fix(keychain): external wallet network-switch prompts (Ready)#2606
Draft
broody wants to merge 3 commits into
Draft
fix(keychain): external wallet network-switch prompts (Ready)#2606broody wants to merge 3 commits into
broody wants to merge 3 commits into
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
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:
onExternalConnectswitched unconditionally — it calledwallet_switchStarknetChainon every connect without checking the wallet's current chain.isMainnetcould go stale — it was derived fromcontroller.chainId()with a[controller]dependency, so it only recomputed when the controller object identity changed. After an in-place network switch (or ifchainId()wasn't ready at first set) it stayed at its initialfalse, 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: deriveisMainnetfrom the RPC-derivedchainIdstate (which tracksrpcUrl/network changes), falling back tocontroller.chainId().[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
[chain-debug]console output[chain-debug]logging🤖 Generated with Claude Code