Repository navigation
feat(solana): switch between EVM/non-EVM chains - #7848
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds EVM/non-EVM chain-family detection and a coordinated cross-family switching flow with confirmation, wallet disconnection, reconnection modal handling, network-selection integration, Reown switching, translations, and tests. ChangesCross-chain network switching
Estimated code review effort: 4 (Complex) | ~45 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Deploying explorer-dev with
|
| Latest commit: |
cbd9c2e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e11d2cf6.explorer-dev-dxz.pages.dev |
| Branch Preview URL: | https://solana-web-1.explorer-dev-dxz.pages.dev |
Deploying swap-dev with
|
| Latest commit: |
cbd9c2e
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5339ebfb.swap-dev-5u6.pages.dev |
| Branch Preview URL: | https://solana-web-1.swap-dev-5u6.pages.dev |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.test.tsx (1)
1-129: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSolid coverage of the documented contract; consider adding an error-path test.
All five scenarios from the hook's doc comment are covered. One gap: no test exercises
disconnectWallet()rejecting, which is the scenario flagged inuseCrossChainFamilySwitch.tsx(lines 58-67). Once error handling is added there, add a test asserting the rejection is handled gracefully (no unhandled rejection, modal state is sane).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.test.tsx` around lines 1 - 129, Add an error-path test in the useCrossChainFamilySwitch suite that makes disconnectWallet reject, invokes the hook for a connected cross-family switch, and verifies the rejection is handled without an unhandled error while modal state remains correct. Reuse the existing mocks and assertions around disconnectWallet, openWalletConnectionModal, and closeModal; keep the test focused on the behavior implemented in useCrossChainFamilySwitch.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.tsx`:
- Around line 58-67: The cross-chain switch flow must handle disconnect failures
like the existing same-family switch path. In
apps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.tsx lines
58-67, update handleCrossChainFamilySwitch to disconnect within the established
try/catch and provide the existing user-facing snackbar feedback, setting the
URL only after disconnect succeeds;
apps/cowswap-frontend/src/common/hooks/useOnSelectNetwork.tsx lines 18-31
requires no direct change once the hook handles and reports its own errors.
---
Nitpick comments:
In `@apps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.test.tsx`:
- Around line 1-129: Add an error-path test in the useCrossChainFamilySwitch
suite that makes disconnectWallet reject, invokes the hook for a connected
cross-family switch, and verifies the rejection is handled without an unhandled
error while modal state remains correct. Reuse the existing mocks and assertions
around disconnectWallet, openWalletConnectionModal, and closeModal; keep the
test focused on the behavior implemented in useCrossChainFamilySwitch.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 96859830-3888-45ee-9698-00d84edd25b6
📒 Files selected for processing (13)
apps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.test.tsxapps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.tsxapps/cowswap-frontend/src/common/hooks/useOnSelectNetwork.test.tsxapps/cowswap-frontend/src/common/hooks/useOnSelectNetwork.tsxapps/cowswap-frontend/src/locales/en-US.poapps/cowswap-frontend/src/modules/trade/hooks/setupTradeState/useSetupTradeState.tsapps/cowswap-frontend/src/modules/wallet/hooks/useSetWalletConnectionError.tsapps/cowswap-frontend/src/modules/wallet/hooks/useWalletConnectionError.tsapps/cowswap-frontend/src/modules/wallet/state/walletConnectionAtom.tslibs/common-utils/src/index.tslibs/common-utils/src/isSameChainFamily.test.tslibs/common-utils/src/isSameChainFamily.tslibs/wallet/src/wagmi/hooks/useSwitchNetwork.ts
💤 Files with no reviewable changes (3)
- apps/cowswap-frontend/src/modules/wallet/hooks/useWalletConnectionError.ts
- apps/cowswap-frontend/src/modules/wallet/state/walletConnectionAtom.ts
- apps/cowswap-frontend/src/modules/wallet/hooks/useSetWalletConnectionError.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.test.tsx`:
- Around line 117-132: Rename the test case around useCrossChainFamilySwitch to
describe the actual console.error reporting when disconnectWallet fails, rather
than claiming snackbar behavior. Keep the existing URL, modal, and
handled-result assertions unchanged; do not introduce snackbar implementation or
assertions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4ac59fb7-ae1c-45ee-8b2d-975dca4072bf
📒 Files selected for processing (2)
apps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.test.tsxapps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.tsx
There was a problem hiding this comment.
Hey @shoom3301 , very nice!
However, some issues and concerns:
- If I pick Solana in a sell token field, I see that the URL is changed before the modal appears. Is it OK? IMO, it should be changed after I confirm, because if I cancel, I should stay on a selected chain connected to a previous wallet
- I'd remove 'Are you sure' from the text: sounds illogical because I should reply 'yes' or 'no' instead of 'confirm'
- If I change a network in the sell token list to Solana, I see that a swap and bridge order from Solana to EVM chain is specified. Is it OK? Will it be supported? If no, I'd switch to the default token pair on Solana
-
If I'm connected to a wallet that supports 2 chains types (f.e. MM), why it disconnects and does not connect to another chain automatically?
-
I was not able to to this feature in a mobile (and) injected wallets (because it is not possible to open console there). Might it be possible to add this FF into the lauchdarkly?
-
Again, might it be possible to check if an injected wallet supports a non-EVM chain and throw a message like this one (see the screenshot) before switching to solana?
-
(continuation of the p.6): this error message from the screenshot is no longer displayed in the current PR ;(
-
This bug (feature?) is on Prod, but it is directly affects this feature:
- I'm on Solana
- I switch to Base, for example
- I connect to Rabby
- But Rabby is on Avalanche, for example
- and then I appear to be connected to Avalanche, but I wanted to switch to Base.
- Is it OK that it is impossible to switch to solana in the dapp mode of the widget configurator?
-
Widget configurator: it is also impossible to switch to other chains in the wodget standalone mode (known issue, #4870). It makes impossible for me to test this feature three
-
When switching from non-evm to evm chain, it would be nice to indicate it in the modal's text (flip the words)
- Overall, maybe it is better just to tell a user that they need to disconnect a wallet and connect to another one that supports this type of change without adding this additional logic?
E.g. something like this
LMK please which issues can be addressed in this PR , and for which ones I should open separate tasks in Linear to address them later.
Thank you
fairlighteth
left a comment
There was a problem hiding this comment.
⚠️ AI Review (Codex GPT-5, worked 16m): Reown switch failures are treated as success
Finding: [BLOCKING] Propagate Reown switch failures before updating the URL
- Location:
libs/wallet/src/wagmi/hooks/useSwitchNetwork.ts:27 - This one is important:
@reown/appkit@1.8.19’s React hook omitsthrowOnFailure, while its controller catches adapter errors by default. - Therefore, when a user rejects or the wallet fails an EVM network switch, this promise resolves successfully.
useOnSelectNetworkthen updates the URL and closes the selector although the wallet remains on the old chain. - The
!networkbranch likewise logs and resolves, leaving callers unable to distinguish failure from success. This regresses ordinary EVM-to-EVM switching, outside the new cross-family behavior.
Suggested fix
- Use
reownAppKit.switchNetwork(network, { throwOnFailure: true }), or retain wagmi’s rejectingmutateAsyncpath. Throw when no matching network exists. - Add regression coverage showing that wallet rejection propagates and that
useOnSelectNetworkdoes not update the URL or close the selector.
Review scope and related context
- The existing human review already covers cross-family cancellation/URL consistency, reconnection, missing error feedback, and widget behavior; those are not duplicated here.
- I rechecked the resolved disconnect-error thread: current head catches rejection and preserves URL/modal state. The follow-up test-name correction is also applied.
- Test, lint, typecheck, and agent-harness CI pass. Cypress currently fails, but the same four
#do-trade-buttontimeouts occur on the corresponding develop run, so I did not attribute them to this PR.
🤖 Prompt for AI agents
Verify this finding against the current PR head and locked @reown/appkit 1.8.19.
Update useSwitchNetwork so:
- missing target networks reject;
- wallet/adapter switch failures propagate;
- callers update the URL only after a successful switch.
Prefer Reown's throwOnFailure option if Reown state synchronization is required.
Add focused tests for wallet rejection and URL/modal preservation.
Generated using the pr-review skill from the CoW Protocol skills repo.
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/cowswap-frontend/src/common/hooks/useOnSelectNetwork.tsx`:
- Around line 29-33: The network-selection flow around
handleCrossChainFamilySwitch currently returns silently for DISCONNECT_FAILED.
Handle that state explicitly before the generic early return and display the
existing snackbar notification used for regular network-switch failures, then
preserve the current return behavior.
In
`@apps/cowswap-frontend/src/modules/tokensList/hooks/useOpenTokenSelectWidget.ts`:
- Around line 53-86: Update the onSelectToken handler to call
crossChainFamilySwitch only when shouldConfirmNetworkSwitch is true. Treat only
CrossChainFamilySwitchState.NOT_CONFIRMED and
CrossChainFamilySwitchState.DISCONNECT_FAILED as abort conditions that return
early; allow NOT_CROSSING_CHAIN and FINISHED to continue closing the widget and
selecting the token.
In `@libs/common-const/src/featureFlags.ts`:
- Around line 5-14: Update the URL flag handling around IS_SOLANA_ENABLED so
localStorage is changed only when the URL parameter is explicitly present: set
the flag when value is 'true', remove it only when value is 'false', and leave
existing localStorage unchanged when the parameter is absent or has another
value.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: b86a0ae7-3828-4d54-ba8e-11ff9a0af679
📒 Files selected for processing (7)
apps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.test.tsxapps/cowswap-frontend/src/common/hooks/useCrossChainFamilySwitch.tsxapps/cowswap-frontend/src/common/hooks/useOnSelectNetwork.tsxapps/cowswap-frontend/src/locales/en-US.poapps/cowswap-frontend/src/modules/tokensList/hooks/useOpenTokenSelectWidget.tsapps/cowswap-frontend/src/theme/ThemedGlobalStyle.tsxlibs/common-const/src/featureFlags.ts
|
@elena-zh thank you!
|
@fairlighteth Unfortunately, I don't see such an option in Reown |
|
Hey @shoom3301 , changes LGTM (mostly). For the case 8 I've opened #7853 task to address it later (if possible) Same for the 3rd case that is not fully fixed: opened the task on Linear for this There is only one nitpick: you've disabled solana in the source chain selector We don't disable chains from which cross-chain swaps are not supported (f.e., Sepolia or Linea). If a user picks this chain, we reset a buy token and show a default token for that chain in the Buy field. Might it be possible to coly this logic for Solana as well? Thanks |
|
@elena-zh thanks! Fixed. Now Solana works similarly to Sepolia in context of bridging. |




Summary
Fixes: https://linear.app/cowswap/issue/FE-307/support-switching-network-between-evm-and-non-evm
Another step in the Solana integration direction.
This PR adds a new flow (see the video demo) to handle switching networks between EVM and non-EVM chains when the wallet is connected.
We need the flow because wallets do not support switching between EVM and non-EVM chains using
wallet_switchEthereumChain.To Test
switch-network-demo.mov
Enable Solana using
localStorage.setItem('IS_SOLANA_ENABLED', 'true')Summary by CodeRabbit