Metamask-extension: Add a `ethereum.on('disconnect, callback)`

Created on 25 Apr 2020  路  2Comments  路  Source: MetaMask/metamask-extension

Metamask has a button disconnect, that if pushed by the user, will requrie the app to re-enable the provider.

DApp should be able to react to that the same way they are able to react to network changed or wallet changed.

L00-provider T08-featureRequest question

Most helpful comment

Hi @Amxx, hope you are well! My answer will probably be more thorough than you require it to be, for the benefit of anyone stumbling across this issue.

MetaMask already emits an event in the case you described: accountsChanged. It emits with an array that is either empty or has at least one account in it (today only ever one, but soon also multiple). If the user revokes access to their account(s), the accountsChanged event will be emitted with [].

accountsChanged is also emitted with [] if MetaMask becomes locked. This particular case can be identified by calling the non-standard asynchronous method ethereum._metamask.isUnlocked(), perhaps in the accountsChanged listener callback.

In light of recent updates to the provider API via EIP 1193, there's one more thing I want to clear up. In our UI, connected/disconnected refers to whether a dapp has access to one or more of the user's accounts. In the provider specification, connected/disconnected refers to whether the Provider can send RPC requests to its chain(s) or not. MetaMask's provider therefore will emit the event disconnect in our next release, but it will not have anything to do with the user's accounts.

I'll close this issue for now, but please feel free to reach out with any further questions or comments.

All 2 comments

@rekmarks can you give the ERC standard perspective on this

Hi @Amxx, hope you are well! My answer will probably be more thorough than you require it to be, for the benefit of anyone stumbling across this issue.

MetaMask already emits an event in the case you described: accountsChanged. It emits with an array that is either empty or has at least one account in it (today only ever one, but soon also multiple). If the user revokes access to their account(s), the accountsChanged event will be emitted with [].

accountsChanged is also emitted with [] if MetaMask becomes locked. This particular case can be identified by calling the non-standard asynchronous method ethereum._metamask.isUnlocked(), perhaps in the accountsChanged listener callback.

In light of recent updates to the provider API via EIP 1193, there's one more thing I want to clear up. In our UI, connected/disconnected refers to whether a dapp has access to one or more of the user's accounts. In the provider specification, connected/disconnected refers to whether the Provider can send RPC requests to its chain(s) or not. MetaMask's provider therefore will emit the event disconnect in our next release, but it will not have anything to do with the user's accounts.

I'll close this issue for now, but please feel free to reach out with any further questions or comments.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danfinlay picture danfinlay  路  3Comments

DISC30 picture DISC30  路  3Comments

BassBauman picture BassBauman  路  3Comments

rossbulat picture rossbulat  路  3Comments

BMillman19 picture BMillman19  路  3Comments