Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate polling for wallet account change #2295

Open
roienatan opened this issue Dec 1, 2020 · 5 comments · May be fixed by daostack/alchemy-monorepo#36
Open

Eliminate polling for wallet account change #2295

roienatan opened this issue Dec 1, 2020 · 5 comments · May be fixed by daostack/alchemy-monorepo#36

Comments

@roienatan
Copy link
Contributor

roienatan commented Dec 1, 2020

Currently we poll every 2000ms for account change in MetaMask.
Instead, we can use a listener for account changes, like this:

window.ethereum.on("accountsChanged", (accounts: Array<any>) => {
  //Handle the new accounts.
  //"accounts" will always be an array, but it can be empty.
  //The current account is at accounts[0]
});

See also https://docs.metamask.io/guide/ethereum-provider.html#events.

@dkent600
Copy link
Contributor

dkent600 commented Dec 1, 2020

You should be very careful about relying on any injected provider. Use the provider returned by Web3Modal.

@roienatan
Copy link
Contributor Author

You should be very careful about relying on any injected provider. Use the provider returned by Web3Modal.

mm but where the injected provider come from? It's according the wallet you choose?

@dkent600
Copy link
Contributor

dkent600 commented Dec 1, 2020

You should be very careful about relying on any injected provider. Use the provider returned by Web3Modal.

mm but where the injected provider come from? It's according the wallet you choose?

Yes, from the wallet you choose in the Web3Modal UI

@roienatan
Copy link
Contributor Author

You should be very careful about relying on any injected provider. Use the provider returned by Web3Modal.

mm but where the injected provider come from? It's according the wallet you choose?

Yes, from the wallet you choose in the Web3Modal UI

So, if the injected web3 is set according the Web3ModalUI, what's the issue here?

@dkent600
Copy link
Contributor

dkent600 commented Dec 1, 2020

Sorry I wasn't clear: Web3Modal doesn't inject anything. It returns the provider (you can see this in arc.ts).

Metamask has in the past injected a provider, but is ending that practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants