Repository navigation
fix(trade-state): preserve URL chainId on first load when wallet is connected - #7692
Conversation
|
@tenderdeve is attempting to deploy a commit to the cow-dev Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughIn ChangesFix: Early return on explicit URL chain switch
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…onnected When the app boots with a connected wallet and an explicit chainId in the URL, the first-load handler called navigateAndSwitchNetwork with the provider chainId right after requesting the wallet to switch, which immediately rewrote the URL to the wallet's chain and dropped the trade state. This is most visible with EOA + WalletConnect: the persisted WC session reports the wallet's own chain on reconnect, so refreshing the page after switching network in the app resets the chain. Returning early after switchNetworkInWallet keeps the URL chain and lets the provider catch up. Fixes cowprotocol#7647
9d69ab5 to
de0891d
Compare
|
Cloudflare Pages preview mirror Preview branch URL: https://github.com/cowprotocol/cowswap/tree/cf-preview/pr-7692 Source fork branch:
|
kernelwhisperer
left a comment
There was a problem hiding this comment.
LGTM, thank you!
fairlighteth
left a comment
There was a problem hiding this comment.
✅ AI Review (Codex GPT-5, worked 5m): no new findings
Review completed. I found no new non-duplicate comments worth posting.
Review scope and related context
Checked:
apps/cowswap-frontend/src/modules/trade/hooks/setupTradeState/useSetupTradeState.ts- First-load connected-wallet path with explicit URL
chainId - Existing accept/reject convergence through
switchNetworkInWallet - Existing PR comments/reviews: no active review threads; CodeRabbit reported no actionable comments
No manual WalletConnect browser run was performed in this review.
Generated using the pr-review skill from the CoW Protocol skills repo.
Summary
Closes #7647.
When the app boots with a connected wallet and an explicit
chainIdin the URL,onProviderNetworkChanges()was:switchNetworkInWallet(urlChainId, providerChainId)), thennavigateAndSwitchNetwork(providerChainId, getDefaultTradeRawState(providerChainId), null)right after.Step 2 immediately rewrote the URL back to the provider's chain (and reset the tokens to the default state for that chain), so the URL chain set by the user was lost.
This is most visible with EOA + WalletConnect: the persisted WC session reports the wallet's own chain on reconnect. Steps from the bug report:
#/<B>/swap).Before the fix: the URL flips back to chain A and the default token pair for chain A.
After the fix: the URL stays on chain B, the app re-issues the network switch to the wallet, and the trade state is preserved.
Changes
apps/cowswap-frontend/src/modules/trade/hooks/setupTradeState/useSetupTradeState.ts: inonProviderNetworkChanges(), when the first-load branch firesswitchNetworkInWallet(urlChainId, providerChainId), return early so we don't overwrite the URL with the provider's chain. Once the wallet completes (or rejects) the switch, the existing handlers take over:noNetworkChangesshort-circuit;switchNetworkInWalletalready navigates back to the provider's chain (existing behavior at lines 68-73).Testing steps
#/<chosen>/swap/....Also verify nothing regressed:
#/100/swap/WETH/COWwith the wallet on a different chain still prompts the wallet to switch./(no chain in URL) with a connected wallet still falls through to the existingnavigateAndSwitchNetwork(providerChainId, ...)path.Checks
pnpm exec nx run cowswap-frontend:lint— passespnpm run typecheck— passespnpm exec nx run cowswap-frontend:test— passes apart from one pre-existing date-dependent flake inAffiliateTraderExpiryBanner.test.tsxthat fails ondeveloptoo (unrelated).Summary by CodeRabbit