Repository navigation
Fix: Base connector interactions - #303
Open
brunomenezes wants to merge 6 commits into
Open
brunomenezes wants to merge 6 commits into
brunomenezes wants to merge 6 commits into
Conversation
…se in-app browser.
…witch when it differs.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Coverage Report for CI Build 41528003568Coverage increased (+0.7%) to 69.308%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats💛 - Coveralls |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In the Coinbase Wallet in-app browser the explorer auto-connects through the Base Account connector, but the header shows a "Connect To Wallet" button that does nothing, and only a reload with the wallet already on Mainnet gets the address to appear. The cause is in wagmi's
baseAccountconnector, which records the chain it asked for instead of the chain the wallet is on. This fixes the connection, makes a network switch in the wallet take effect without a reload, and adds a development-only diagnostics overlay for browsers that have no devtools, which is how the cause was found.User-facing change: connecting from the Coinbase Wallet app works, on Mainnet and on Sepolia. No dependency changes.
Changes:
Base Account chain —
baseAccount.connect()sendswallet_connectwith the requested chain first and takes the connection chain from the first entry of the reply, never frometh_chainId. Inside the Coinbase in-app browser the wallet defaults to Base (8453), so wagmi reports a connection on Mainnet while the connector answers 8453,useWalletClientfails withConnectorChainMismatchError, the app treats the wallet as inactive, and RainbowKit, seeing a connection, no longer opens its modal, therefore we have a dead Connect button.withVerifiedChainIdwraps RainbowKit'sbasewallet and reads the wallet's chain after connecting.Order: page load →
reconnectOnMount→baseAccount.connect()says chain 1 →eth_chainIdsays 8453 → requested chain differs →wallet_switchEthereumChainto Mainnet → connection and connector agree →activeOn reconnect no chain is requested, so the wrapper reports the real chain and an unsupported one shows "Unsupported Network" like any other wallet. The existing Mainnet auto-switch applies outside development. A wallet that refuses the switch fails the connection, as with the other connectors.
Wallet client on the wallet's chain —
useWalletClientwas keyed by wagmi's config chain, which only follows configured chains, and refetched only when the address changed. A cached error survived a network switch in the wallet until a reload.useWagmiWalletnow requests the client for the wallet's own chain and disables the query on unsupported chains, so a switch refetches it. The hook also exposeswalletClientErrorthrough the wallet context and warns about it once.Diagnostics overlay —
src/components/wallet/debug/, enabled with?walletDebug=1on development builds. Wallet in-app browsers have no devtools. Safari's Web Inspector attaches to an iOS webview only when the host app opts in, which Coinbase Wallet's store build does not, and Android's remote debugging has the same opt-in. In-page devtools such as Eruda or vConsole cover console, network and storage but know nothing about wagmi, and the decisive readout here is wagmi-specific: the chain wagmi recorded against the chain the connector andwindow.ethereumreport, the wallet client error, whether RainbowKit would open its modal. The overlay shows that as a frozen, copyable JSON snapshot, keeps the last console errors (also those thrown during reconnect), offers "Switch to Sepolia / Mainnet" buttons, and minimizes to a corner pill out of the way of the modals. It diagnosed this bug in two snapshots from the phone.Usage:
?walletDebug=1→ flag remembered inlocalStorage→Web3Containerlazy-loads the panel → snapshot on mount, on wagmi state change and on Refresh → Copy JSONThe mount is a build-time condition on
NODE_ENV, so production bundles carry none of its code (verified by searching thenext buildoutput for the overlay's markers).next.config.jsdocuments theallowedDevOriginsallow-list needed to open the dev server from a phone.Tests —
baseAccountChainMismatch.test.tsreproduces the bug against real wagmi with a fake in-app provider (isCoinbaseBrowser,wallet_connectechoing the requested chains,eth_chainIdon Base) and covers the wrapper: switch to the requested chain, refuse, reconnect, matching chain.@base-org/accountis mapped to a stub under Jest, since the real SDK fetches on creation and is not resolvable from the project root. The overlay's flag, log capture and panel have their own suites.Other findings
The flaw is upstream:
@wagmi/connectors6.2.0 has it, wagmi'smainstill has it, and the only partial fix (reconnect, 7.0.1) requires wagmi 3, which RainbowKit 2 does not support. CoW Swap patched the same connector code for the desktop popup case in cowprotocol/cowswap#8366 and reports it still present in connectors 8.2.0. The app-level wrapper is preferred over a pnpm patch: typed, unit-tested, unaffected by dependency bumps, and a one-line removal once upstream fixes it.