Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

can addProvider be called over time, to offer a "logged in" mode? #220

Closed
gre opened this issue Feb 12, 2018 · 2 comments
Closed

can addProvider be called over time, to offer a "logged in" mode? #220

gre opened this issue Feb 12, 2018 · 2 comments

Comments

@gre
Copy link

gre commented Feb 12, 2018

Hi everyone, i'm currently writing a starter kit at Ledger to have a minimal dapp bootstrap, where i'm trying to cover some basic dapp feature usecase (like, getting a value, setting a value, listening to a value change on a contract).

as shown in this GIF, i've currently made that the dapp is only "opened" after you actually log-in with the ledger or the MetaMask extension.

One of the "feature" i'm trying to reach now, is to have the app showing things even if you are not logged in, basically having a read-only mode – pushing the "log in" at the very end, when you actually want to do a set value (or whatever contract call).
I've successfully reached that by just doing:

export const getReadOnlyWeb3 = async () => {
  const engine = new ProviderEngine();
  engine.addProvider(new FetchSubprovider({ rpcUrl }));
  engine.start();
  return new Web3(engine);
};

however, what should happen when user logs in? a simple implementation is just to trash & replace the web3 instance by the new one, but that kinda means having to "reset" the UI (and wait the same data to come again).
Ideally, I was thinking, what about you can engine.addProvider(aMoreExtendedSubproviderThatAddSupportForMoreThings) ? so we keep using the FetchSubprovider but just adding the missing pieces (the part about getAccounts and signTransaction, ..)
Moreover, I've notice the MetaMask don't support the watch() mode, there is no event going through, but I believe that's a known bug (can't find again the issue). I'm not finding a way to combine FetchSubprovider with metamask however (only thing I know is you can new Web3(web3.currentProvider), is there a way to use web3.currentProvider as a subprovider in combination of Fetch?)

sorry for the multi-questions thread thing. I would be happy to discuss it somewhere else if more appropriate.

If there is no solution for this, I'm probably going to try the simple "trash & replace" approach for now.

Thanks

@danfinlay
Copy link
Contributor

Trash & replace is one simple solution.

Currently there is no providerSubprovider like what would allow you to chain subproviders together and fall back to a normal provider, but this would be a practical way to compose your own subproviders with a fallback to MetaMask.

We have had some issues with events/logs/watch, (see here), but you may be able to work around by reloading, or waiting for our next release.

We're hoping to add our own Ledger integration soon, so that will also help here.

If you don't want to wait for that, and don't want to trash providers, a third architecture would be to add your own hooked-wallet-subprovider in such a way that it lists whatever account is currently "logged in" and conditionally signs with whichever strategy has been chosen.

@gre
Copy link
Author

gre commented Feb 14, 2018

That makes sense! thanks :)

@gre gre closed this as completed Feb 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants