fix: clear restored walletconnect connections on disconnect - #2688
Conversation
|
@o-mid is attempting to deploy a commit to the rainbowdotme Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 1236816 The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1236816c4e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // the user closes it, we need to know the wallet isn't connecting anymore. | ||
| // So if it's connecting, we disconnect it. | ||
| if (isConnecting) disconnect(); | ||
| if (isConnecting) void disconnectAll(); |
There was a problem hiding this comment.
Keep cancelling pending wallet connections
When the WalletButton QR flow is still pending and the user closes the connect modal, wagmi has isConnecting set but has not added anything to config.state.connections yet; useDisconnectAll therefore snapshots an empty list and this call becomes a no-op. The previous no-argument disconnect() still forced wagmi's status back to disconnected, which is exactly what the comment above this line says the close handler needs, so this can leave the custom WalletButton stuck in its loading/disabled connecting state until the pending connect promise settles. Preserve the old no-connection fallback when cancelling an in-flight connect.
Useful? React with 👍 / 👎.
Summary
walletConnectconnections.useDisconnectAll).Fixes #2401
Problem
RainbowKit registers multiple WalletConnect connectors that share
id: "walletConnect". After refresh, reconnect can restore more than one. Wagmi's defaultdisconnect()only removes the current connection and switches to the next, so the account UI remains connected.Reproduction
Root cause
Multi-wrapper WalletConnect connectors + wagmi disconnect-current semantics after reconnect.
Fix
Add
useDisconnectAlland use it from Account / Chain / Connect disconnect paths.Tests
disconnect()leaves restored WC connections connecteduseDisconnectAll()clears all in one clickpnpm test:unit run packages/rainbowkit/src/hooks/useDisconnectAll.test.tsxpnpm --filter @rainbow-me/rainbowkit typecheckCompatibility
Test plan