Skip to content

Commit

Permalink
fix: MetaMask disconnecting during the connection process. (#4347)
Browse files Browse the repository at this point in the history
* fix: disconnection during the connection process.

* fix: disconnection during the connection process.

* chore: tweaks

* chore: changeset

* chore: comment

---------

Co-authored-by: Tom Meagher <tom@meagher.co>
  • Loading branch information
EdouardBougon and tmm authored Oct 17, 2024
1 parent ce4e47f commit 5ae49af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/serious-taxis-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wagmi/connectors": patch
---

Added workaround for MetaMask mobile sometimes disconnecting.
7 changes: 6 additions & 1 deletion packages/connectors/src/metaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,12 @@ export function metaMask(parameters: MetaMaskParameters = {}) {
},
async onAccountsChanged(accounts) {
// Disconnect if there are no accounts
if (accounts.length === 0) this.onDisconnect()
if (accounts.length === 0) {
// ... and using browser extension
if (sdk.isExtensionActive()) this.onDisconnect()
// FIXME(upstream): Mobile app sometimes emits invalid `accountsChanged` event with empty accounts array
else return
}
// Connect if emitter is listening for connect event (e.g. is disconnected and connects through wallet interface)
else if (config.emitter.listenerCount('connect')) {
const chainId = (await this.getChainId()).toString()
Expand Down

0 comments on commit 5ae49af

Please sign in to comment.