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

fix: MetaMask disconnecting during the connection process. #4347

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading