Skip to content

fix(keychain): external wallet network-switch prompts (Ready)#2606

Draft
broody wants to merge 3 commits into
mainfrom
fix-external-wallet-network-switch
Draft

fix(keychain): external wallet network-switch prompts (Ready)#2606
broody wants to merge 3 commits into
mainfrom
fix-external-wallet-network-switch

Conversation

@broody
Copy link
Copy Markdown
Contributor

@broody broody commented May 21, 2026

Problem

Selecting an external Starknet wallet (e.g. Ready) in the purchase flow prompts a network switch even when the wallet is already on the controller's network — and the requested target is the wrong network (Sepolia while the controller is on Mainnet), sometimes prompting Sepolia then Mainnet back-to-back.

Diagnosis so far

Two contributing issues:

  1. onExternalConnect switched unconditionally — it called wallet_switchStarknetChain on every connect without checking the wallet's current chain.
  2. isMainnet could go stale — it was derived from controller.chainId() with a [controller] dependency, so it only recomputed when the controller object identity changed. After an in-place network switch (or if chainId() wasn't ready at first set) it stayed at its initial false, making the flow resolve the wrong target chain.

Changes

  • external-wallet.ts: only request a switch when the wallet's current chain differs from the target (normalized compare).
  • connection.ts: derive isMainnet from the RPC-derived chainId state (which tracks rpcUrl/network changes), falling back to controller.chainId().

⚠️ Draft / WIP

  • A previous local test showed the prompt persisting, so this is not yet confirmed.
  • Includes temporary [chain-debug] console logging (connection isMainnet effect, chainId resolution in the wallet picker/drawer, and the switch decision) to capture runtime values on the preview. These logs must be removed before merge.

Verification plan

  • Reproduce Ready connect on Mainnet, capture [chain-debug] console output
  • Confirm no spurious switch prompt when already on the controller's network
  • Remove [chain-debug] logging
  • Mark ready for review

🤖 Generated with Claude Code

broody and others added 3 commits May 21, 2026 08:42
onExternalConnect always requested a wallet_switchStarknetChain even when
the wallet was already on the target chain, causing wallets like Ready to
prompt a network switch on every connect (and to default the switch dialog
to the opposite network). Only switch when the wallet's current chain
differs from the controller's target chain.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…er ref

isMainnet was computed from controller.chainId() with a [controller]
dependency, so it only recomputed when the controller object identity
changed. After an in-place network switch (or when chainId() wasn't ready
at first set) it went stale, leaving isMainnet wrong regardless of the
actual connected network. This made the external-wallet flow resolve the
wrong target chain (e.g. Sepolia while the controller is on Mainnet) and
prompt a needless network switch. Derive isMainnet from the RPC-derived
chainId state, which tracks rpcUrl/network changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Temporary console logging to diagnose the Ready wallet network-switch
prompts (isMainnet resolution, resolved target chainId, and the switch
decision in onExternalConnect). To be removed once diagnosed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 21, 2026

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

Project Deployment Actions Updated (UTC)
controller-example-next Ready Ready Preview May 22, 2026 7:19pm
controller-ui Ready Ready Preview May 22, 2026 7:19pm
keychain Ready Ready Preview May 22, 2026 7:19pm
keychain-storybook Ready Ready Preview May 22, 2026 7:19pm

Request Review

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.

1 participant