Skip to content

Fix: Base connector interactions - #303

Open
brunomenezes wants to merge 6 commits into
mainfrom
fix/coinbase-interaction-mobile
Open

brunomenezes wants to merge 6 commits into
mainfrom
fix/coinbase-interaction-mobile

Conversation

@brunomenezes

Copy link
Copy Markdown
Member

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 baseAccount connector, 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() sends wallet_connect with the requested chain first and takes the connection chain from the first entry of the reply, never from eth_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, useWalletClient fails with ConnectorChainMismatchError, the app treats the wallet as inactive, and RainbowKit, seeing a connection, no longer opens its modal, therefore we have a dead Connect button. withVerifiedChainId wraps RainbowKit's base wallet and reads the wallet's chain after connecting.

Order: page load → reconnectOnMount → baseAccount.connect() says chain 1 → eth_chainId says 8453 → requested chain differs → wallet_switchEthereumChain to Mainnet → connection and connector agree → active

On 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 — useWalletClient was 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. useWagmiWallet now requests the client for the wallet's own chain and disables the query on unsupported chains, so a switch refetches it. The hook also exposes walletClientError through the wallet context and warns about it once.

Diagnostics overlay — src/components/wallet/debug/, enabled with ?walletDebug=1 on 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 and window.ethereum report, 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 in localStorage → Web3Container lazy-loads the panel → snapshot on mount, on wagmi state change and on Refresh → Copy JSON

The mount is a build-time condition on NODE_ENV, so production bundles carry none of its code (verified by searching the next build output for the overlay's markers). next.config.js documents the allowedDevOrigins allow-list needed to open the dev server from a phone.

Tests — baseAccountChainMismatch.test.ts reproduces the bug against real wagmi with a fake in-app provider (isCoinbaseBrowser, wallet_connect echoing the requested chains, eth_chainId on Base) and covers the wrapper: switch to the requested chain, refuse, reconnect, matching chain. @base-org/account is 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/connectors 6.2.0 has it, wagmi's main still 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.

@brunomenezes
brunomenezes requested a review from tuler November 2, 2026 21:24
@brunomenezes brunomenezes self-assigned this Nov 2, 2026
@brunomenezes brunomenezes added type:bug Something isn't working and requires a fix staking Changes targeted to the Staking platform labels Nov 2, 2026
@vercel

vercel Bot commented Nov 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
staking Ready Ready Preview Nov 2, 2026 9:24pm UTC

Request Review

@brunomenezes brunomenezes moved this to 👁 In Review in Rollups Tooling Nov 2, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 41528003568

Coverage increased (+0.7%) to 69.308%

Details

  • Coverage increased (+0.7%) from the base build.
  • Patch coverage: 15 uncovered changes across 5 files (141 of 156 lines covered, 90.38%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
src/components/wallet/debug/WalletDebugPanel.tsx 61 55 90.16%
src/components/wallet/config.ts 4 0 0.0%
src/components/Web3Container.tsx 3 0 0.0%
src/components/wallet/debug/walletDebugLog.ts 36 35 97.22%
src/components/wallet/withVerifiedChainId.ts 19 18 94.74%
Total (8 files) 156 141 90.38%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3880
Covered Lines: 2816
Line Coverage: 72.58%
Relevant Branches: 2027
Covered Branches: 1278
Branch Coverage: 63.05%
Branches in Coverage %: Yes
Coverage Strength: 29.15 hits per line

💛 - Coveralls

This branch was successfully deployed

1 active deployment
Preview — 23c66d3f Deployed Nov 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

staking Changes targeted to the Staking platform type:bug Something isn't working and requires a fix

Projects

Status: 👁 In Review

Development

Successfully merging this pull request may close these issues.

2 participants