fix(wallet): enforce active chain on connect so balances are consistent#158
Merged
Conversation
The Payment Wallet panel reads ETH/ANT/USDC balances on a fixed chain (getActiveChainId — Arbitrum One on mainnet, the manifest chain on devnet), while the Reown AppKit account modal shows the balance on the wallet's actually-connected chain. When a wallet connected on a different chain, the two surfaces disagreed — our panel showed the Arbitrum One balance while AppKit showed ~0 on, say, mainnet/Sepolia (GH #85 / V2-474). The chain was only reconciled at payment time (ensureActiveChain in utils/payment.ts), never at connect. Move that reconciliation to connect time: the AppKit watcher now switches the wallet onto getActiveChainId() before reading balances. If the switch doesn't complete (wallet declines, or the target chain isn't one AppKit knows), it fails soft and raises a "wrong network" banner with a Switch button instead of breaking connect. Devnet-safe: VITE_DEVNET builds skip AppKit entirely (watcher never runs), and the direct-key devnet wallet is skipped via the existing _devnetWalletKeySet guard — it always sits on the manifest chain. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes the inconsistent ETH balance reported in GH #85.
Root cause
The Payment Wallet panel reads balances on a fixed chain (
getActiveChainId()— Arbitrum One on mainnet, the manifest chain on devnet), while the Reown AppKit account modal shows the balance on the wallet's actually-connected chain. When a wallet connected on a different chain, the two disagreed — our panel showed the Arbitrum One balance (e.g.0.1200 ETH) while AppKit showed0.000 ETHon the wallet's real chain. The chain was only reconciled at payment time (ensureActiveChaininutils/payment.ts), never at connect.Fix
Move the reconciliation to connect time. The AppKit watcher (
composables/useWallet.ts::syncFromAppKit) now switches the wallet ontogetActiveChainId()before reading balances. If the switch doesn't complete (wallet declines, or the target chain isn't one AppKit knows), it fails soft and raises a "wrong network" banner with a Switch network button — never breaks connect.Devnet-safe (no impact on manifest testing)
VITE_DEVNET=1local-Anvil builds skip AppKit entirely → the watcher (and this code) never runs._devnetWalletKeySetguard — it always sits on the manifest chain.getActiveChainId()(= the manifest chain, e.g. Sepolia), which is correct.Changes
composables/useWallet.ts— newensureActiveChain()(mirrorspayment.ts), wired into the connect watcher.stores/wallet.ts—wrongNetworkflag, reset on disconnect.pages/wallet.vue— wrong-network banner + Switch button.locales/en.json— two new strings (other locales fall back to EN,fallbackWarn: false).Verification
vitest run— 30/30 pass.nuxi typecheck— clean.Release note
🤖 Generated with Claude Code