Skip to content

Conversation

@kernelwhisperer
Copy link
Contributor

@kernelwhisperer kernelwhisperer commented Dec 3, 2025

Summary

Fixes #6394

To Test

  1. connect to Rabby+safe
  2. specify a buy order with selling eth
  3. change an account in Rabby from Safe to EOA
  4. notice the form getting cleared and order kind being set to sell

Background

Before this change, the output would get disabled, but you were still able to click swap and place an invalid buy order.

Summary by CodeRabbit

  • Bug Fixes

    • Improved ETH flow handling in the swap widget to ensure the swap state resets appropriately when entering the EOA ETH flow.
  • Chores

    • Development server updated to listen on all network interfaces for easier local network testing.

✏️ Tip: You can customize this high-level summary in your review settings.

@kernelwhisperer kernelwhisperer self-assigned this Dec 3, 2025
@vercel
Copy link

vercel bot commented Dec 3, 2025

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

Project Deployment Preview Updated (UTC)
cowfi Ready Ready Preview Dec 4, 2025 10:20am
explorer-dev Ready Ready Preview Dec 4, 2025 10:20am
swap-dev Ready Ready Preview Dec 4, 2025 10:20am
widget-configurator Ready Ready Preview Dec 4, 2025 10:20am
2 Skipped Deployments
Project Deployment Preview Updated (UTC)
cosmos Ignored Ignored Dec 4, 2025 10:20am
sdk-tools Ignored Ignored Preview Dec 4, 2025 10:20am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 3, 2025

Walkthrough

Adds a dev-server host binding and introduces EOA ETH-flow detection in SwapWidget to reset swap state to SELL_ETH_RESET_STATE when an EOA ETH-flow is active and the current order is not a sell order.

Changes

Cohort / File(s) Summary
Dev Server Configuration
apps/cowswap-frontend/project.json
Added "host": true under serve.options so the development server binds to all network interfaces.
EOA ETH Flow Reset Logic
apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx
Imported SELL_ETH_RESET_STATE and useIsEoaEthFlow; added isEoaEthFlow usage and an effect that calls updateSwapState(SELL_ETH_RESET_STATE) when isEoaEthFlow is true and the current order is not a sell order.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify useIsEoaEthFlow correctly and deterministically identifies EOA ETH-flow conditions across account changes.
  • Confirm the effect's dependency list and timing to avoid repeated resets or missed transitions.
  • Ensure SELL_ETH_RESET_STATE reset scope doesn't accidentally clear unrelated user inputs.

Possibly related PRs

  • #6406 — Modifies the same SwapWidget file with Safe and partial-approval ETH-flow adjustments; may overlap with EOA ETH-flow handling.
  • #5530 — Adjusts ETH-swap flow behavior and validation/quoting logic for native ETH; related to ETH-flow handling.

Suggested reviewers

  • elena-zh
  • alfetopito

Poem

🐰 I hopped through code with nimble feet,
Found an ETH-flow that wasn't neat,
A gentle reset, a tiny fix,
Now swap-state flows in tidy ticks,
Hooray — no stray orders on repeat 🥕

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately summarizes the main change: automatically switching to a sell order when wallet context changes from Safe to EOA.
Description check ✅ Passed The PR description includes all required sections: issue reference (#6394), clear testing steps, expected behavior, and background context explaining the fix.
Linked Issues check ✅ Passed The code changes fully address issue #6394 by preventing buy ETH-flow orders through automatic form reset and order type switching when wallet changes from Safe to EOA.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the ETH-flow buy order issue: project.json configuration update and SwapWidget logic to handle wallet context switches.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/disallow-ethflow-buy-order

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a74cee9 and 0ad0b30.

📒 Files selected for processing (2)
  • apps/cowswap-frontend/project.json (1 hunks)
  • apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-12-03T19:23:35.765Z
Learnt from: kernelwhisperer
Repo: cowprotocol/cowswap PR: 6610
File: apps/cowswap-frontend/project.json:38-39
Timestamp: 2025-12-03T19:23:35.765Z
Learning: In the cowswap-frontend project configuration (apps/cowswap-frontend/project.json), the Vite dev server option `"host": true` is set to support Windows + WSL development environments, where binding to all network interfaces is required for the Windows host to access the dev server running in WSL.

Applied to files:

  • apps/cowswap-frontend/project.json
📚 Learning: 2025-09-11T08:25:51.460Z
Learnt from: alfetopito
Repo: cowprotocol/cowswap PR: 6234
File: libs/tokens/src/index.ts:1-4
Timestamp: 2025-09-11T08:25:51.460Z
Learning: In the cowprotocol/cowswap project, there is currently no SSR (Server-Side Rendering) support, so localStorage access at module import time does not cause SSR-related issues.

Applied to files:

  • apps/cowswap-frontend/project.json
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Setup
  • GitHub Check: Cypress
🔇 Additional comments (1)
apps/cowswap-frontend/project.json (1)

38-39: LGTM. The "host": true configuration is appropriate for supporting Windows + WSL development environments where binding to all network interfaces is necessary for the Windows host to access the dev server running in the Linux subsystem. Based on learnings, this is a reasonable inclusion in the PR.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd05bb7 and ba3bb32.

📒 Files selected for processing (2)
  • apps/cowswap-frontend/project.json (1 hunks)
  • apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: shoom3301
Repo: cowprotocol/cowswap PR: 5443
File: apps/cowswap-frontend/src/modules/swap/containers/ConfirmSwapModalSetup/index.tsx:71-71
Timestamp: 2025-02-20T15:59:33.749Z
Learning: The swap module in apps/cowswap-frontend/src/modules/swap/ is marked for deletion in PR #5444 as part of the swap widget unification effort.
📚 Learning: 2025-10-10T20:28:16.565Z
Learnt from: fairlighteth
Repo: cowprotocol/cowswap PR: 6347
File: apps/cowswap-frontend/src/modules/trade/pure/TradeConfirmation/index.tsx:49-49
Timestamp: 2025-10-10T20:28:16.565Z
Learning: In apps/cowswap-frontend/src/modules/trade, TradeConfirmation follows a two-layer architecture: TradeConfirmationView (pure/stateless) in pure/TradeConfirmation/index.tsx renders the UI, while TradeConfirmation (container) in containers/TradeConfirmation/index.tsx wraps it to freeze props during pending trades (via useStableTradeConfirmationProps), wire in signing state (useSigningStep), and inject trade confirmation state (useTradeConfirmState). Consuming modules should import the container TradeConfirmation from 'modules/trade' to preserve this stateful behavior.
<!-- [add_learning]
When reviewing component refactoring in apps/cowswap-frontend/src/modules/trade, recognize the pattern where a pure view component (e.g., TradeConfirmationView) is separated from a stateful container (e.g., TradeConfirmation) that wraps it. The container adds runtime state management (prop stabilization, signing state, etc.) while the view remains testable and composable. Do not flag usages that import th...

Applied to files:

  • apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx
📚 Learning: 2025-02-20T15:59:33.749Z
Learnt from: shoom3301
Repo: cowprotocol/cowswap PR: 5443
File: apps/cowswap-frontend/src/modules/swap/containers/ConfirmSwapModalSetup/index.tsx:71-71
Timestamp: 2025-02-20T15:59:33.749Z
Learning: The swap module in apps/cowswap-frontend/src/modules/swap/ is marked for deletion in PR #5444 as part of the swap widget unification effort.

Applied to files:

  • apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx
📚 Learning: 2025-10-13T19:41:31.440Z
Learnt from: limitofzero
Repo: cowprotocol/cowswap PR: 6351
File: apps/cowswap-frontend/src/modules/erc20Approve/containers/TradeApproveModal/useTradeApproveCallback.ts:87-121
Timestamp: 2025-10-13T19:41:31.440Z
Learning: In apps/cowswap-frontend/src/modules/erc20Approve, useApproveCallback returns Promise<TransactionResponse | undefined> and is distinct from useApproveCurrency, which can return Promise<TransactionReceipt | SafeMultisigTransactionResponse>. When reviewing approval flows, verify which hook is actually being used before flagging Safe wallet concerns.

Applied to files:

  • apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx
📚 Learning: 2025-06-23T07:03:50.760Z
Learnt from: shoom3301
Repo: cowprotocol/cowswap PR: 5859
File: apps/cowswap-frontend/src/modules/tradeQuote/hooks/useTradeQuotePolling.ts:76-82
Timestamp: 2025-06-23T07:03:50.760Z
Learning: In the useTradeQuotePolling hook, there are two useLayoutEffect hooks that work together: one resets the counter to 0 when the confirmation modal closes, and another automatically triggers pollQuote(false, true) whenever the counter reaches 0. This creates an intentional chain reaction for immediate quote updates.

Applied to files:

  • apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx
🧬 Code graph analysis (1)
apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx (1)
apps/cowswap-frontend/src/modules/trade/hooks/useIsEoaEthFlow.ts (1)
  • useIsEoaEthFlow (5-7)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Setup
  • GitHub Check: Cypress
🔇 Additional comments (3)
apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx (3)

15-15: Imports look correct.

The new imports SELL_ETH_RESET_STATE and useIsEoaEthFlow are properly added to support the ETH-flow fix.

Note: Based on learnings, the swap module was previously marked for deletion as part of a swap widget unification effort (PR #5444 from February 2025). If this module is still planned for removal, consider whether this fix should be applied in a different location.

Also applies to: 21-21


102-102: LGTM!

The hook usage is correct and retrieves the EOA ETH flow state as needed.


109-113: Verify scope of isEoaEthFlow to prevent incorrect resetting of non-ETH orders and confirm the fix addresses the wallet switch scenario.

The useEffect correctly resets to a sell order when isEoaEthFlow is active and a buy order is detected. However, before merging, please verify:

  1. isEoaEthFlow scope: Confirm that isEoaEthFlow only becomes true when ETH is involved as the sell or buy currency. If it can be true for non-ETH token pairs, this effect might incorrectly reset unrelated buy orders.

  2. SELL_ETH_RESET_STATE completeness: Verify this constant properly initializes all necessary swap state (currencies, amounts, decimals) for a sell ETH order.

  3. Wallet switch scenario: Test that the fix handles the reported issue where switching from Safe to EOA wallet properly resets a buy order to a sell order without requiring manual action.

Comment on lines +38 to +39
"buildTarget": "cowswap-frontend:build",
"host": true
Copy link
Contributor

@coderabbitai coderabbitai bot Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n apps/cowswap-frontend/project.json | sed -n '30,50p'

Repository: cowprotocol/cowswap

Length of output: 722


🏁 Script executed:

git log --oneline -20 -- apps/cowswap-frontend/project.json

Repository: cowprotocol/cowswap

Length of output: 133


🏁 Script executed:

git show HEAD:apps/cowswap-frontend/project.json | head -50

Repository: cowprotocol/cowswap

Length of output: 1246


🏁 Script executed:

git show HEAD~1:apps/cowswap-frontend/project.json | sed -n '34,50p'

Repository: cowprotocol/cowswap

Length of output: 99


🏁 Script executed:

git log -p --all -S '"host": true' -- apps/cowswap-frontend/project.json | head -100

Repository: cowprotocol/cowswap

Length of output: 45


🏁 Script executed:

rg -A 5 -B 5 "host.*true" apps/cowswap-frontend/

Repository: cowprotocol/cowswap

Length of output: 50377


🏁 Script executed:

git log --all --oneline | head -20

Repository: cowprotocol/cowswap

Length of output: 1312


🏁 Script executed:

rg -B 5 -A 5 "host.*true" --type json

Repository: cowprotocol/cowswap

Length of output: 766


🏁 Script executed:

fd -name "*.md" | xargs rg -l "host" 2>/dev/null | head -5

Repository: cowprotocol/cowswap

Length of output: 474


Clarify the relevance of this dev server configuration change.

This change sets "host": true for the Vite dev server, binding it to all network interfaces instead of localhost. This doesn't appear related to the PR's stated objective of fixing ETH-flow order handling when switching from Safe to EOA wallets.

If this configuration is needed for testing the fix (e.g., in CI/CD or specific development setups), please document that in the PR description. Otherwise, consider moving it to a separate PR.

🤖 Prompt for AI Agents
In apps/cowswap-frontend/project.json around lines 38-39, the dev server "host":
true change binds Vite to all network interfaces but appears unrelated to the
Safe→EOA order-handling fix; either remove/revert this change from this PR (keep
dev server config unchanged) or, if it is required for testing the bugfix
(CI/dev machines, remote device testing, or reproducing the issue), document
that requirement clearly in the PR description (explain why binding to all
interfaces is necessary, where/how tests rely on it, and any security/port
notes); do not leave the unrelated config change in this PR without
justification — move it to a separate config/infra PR if it’s not strictly
needed here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, this was needed for my setup (Windows + Ubuntu running through WSL), otherwise I could not load http://localhost:3000

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kernelwhisperer, thank you for the clarification! That makes perfect sense—WSL setups often require binding to all network interfaces (0.0.0.0) for the Windows host to access services running in the Linux subsystem. The "host": true option is exactly what's needed for this scenario.

This is a reasonable change to include, especially if team members use similar development setups. You might consider adding a brief note in the repository's development documentation (if one exists) mentioning that this configuration supports WSL-based development workflows, which could help other developers in similar environments.

🐰✨


✏️ Learnings added
Learnt from: kernelwhisperer
Repo: cowprotocol/cowswap PR: 6610
File: apps/cowswap-frontend/project.json:38-39
Timestamp: 2025-12-03T19:23:35.765Z
Learning: In the cowswap-frontend project configuration (apps/cowswap-frontend/project.json), the Vite dev server option `"host": true` is set to support Windows + WSL development environments, where binding to all network interfaces is required for the Windows host to access the dev server running in WSL.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@shoom3301
Copy link
Collaborator

Works as expected

test6663.mov

Copy link
Contributor

@elena-zh elena-zh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

@shoom3301 shoom3301 disabled auto-merge December 5, 2025 06:33
@shoom3301 shoom3301 merged commit 66a9013 into develop Dec 5, 2025
15 checks passed
@shoom3301 shoom3301 deleted the fix/disallow-ethflow-buy-order branch December 5, 2025 06:33
@github-actions github-actions bot locked and limited conversation to collaborators Dec 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible to create a buy ETH-flow order

5 participants