Skip to content

fix(connectors): remove change listener on WalletConnect switchChain failure#5033

Merged
tmm merged 2 commits intowevm:mainfrom
Zelys-DFKH:fix/switch-chain-pending-state
Apr 6, 2026
Merged

fix(connectors): remove change listener on WalletConnect switchChain failure#5033
tmm merged 2 commits intowevm:mainfrom
Zelys-DFKH:fix/switch-chain-pending-state

Conversation

@Zelys-DFKH
Copy link
Copy Markdown

@Zelys-DFKH Zelys-DFKH commented Mar 24, 2026

Fixes #5032

In walletConnect.ts, switchChain registers a change listener on the connector's emitter while waiting for wallet_switchEthereumChain to confirm. When the request fails, Promise.all rejects and control jumps to the catch block, but the listener is never removed. Every failed switch attempt (user rejection, network error, wallet timeout) leaves one orphaned listener permanently attached to the emitter.

Fixed by storing a cleanup reference before registering the listener and calling it at the top of the catch block. Added a test that mocks the provider, fails a switch, and asserts the listener count returns to its pre-call value.

…failure

Co-Authored-By: Zelys <noreply@github.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 24, 2026

@Zelys-DFKH is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 24, 2026

🦋 Changeset detected

Latest commit: 1c966a1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@wagmi/connectors Patch
wagmi Patch
@wagmi/solid Patch
@wagmi/vue Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@tmm tmm force-pushed the fix/switch-chain-pending-state branch from 195885b to 1c966a1 Compare April 6, 2026 19:38
@tmm tmm merged commit f53f3f5 into wevm:main Apr 6, 2026
1 of 3 checks passed
@github-actions github-actions bot mentioned this pull request Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WalletConnect switchChain leaks a change listener on failure

2 participants