Skip to content

feat(trade): generalize quote amount displaying for error case#7011

Merged
shoom3301 merged 7 commits intodevelopfrom
fix/trade-quote-error-handling
Feb 18, 2026
Merged

feat(trade): generalize quote amount displaying for error case#7011
shoom3301 merged 7 commits intodevelopfrom
fix/trade-quote-error-handling

Conversation

@shoom3301
Copy link
Copy Markdown
Collaborator

@shoom3301 shoom3301 commented Feb 13, 2026

Summary

In #6771 we changed the quote state logic, now we don't reset the previous quote when another one contains an error.
This responsibility has shifted to UI. But the shift was applied only to Swap widget, this is a problem, it must be applied to Twap as well. An exception is Limit orders widget.

image

To Test

  1. connect to a wallet on Polygon (reproducible on any chain)
  2. go to twap orders
  3. pick 1000 WPOL to USDC to sell --> quote is loaded
  4. change an amount to sell 0.01 wpol --> when quote gets 404 error
  • AR: the output amount displays an amount from previous quote
  • ER: the output amount displays zero

Please also check Limit orders and Swap for sell/buy orders.

Summary by CodeRabbit

  • New Features

    • Background tracking of provider network support added.
    • Exposed a central control to determine when quote amounts should be hidden.
  • Improvements

    • Quote amounts automatically hide during loading or error states.
    • More consistent and simplified quote/rate presentation across Swap, Trade, TWAP widgets.
    • UI updates ensure wrap/unwrap and sell/buy flows display amounts consistently.

@shoom3301 shoom3301 self-assigned this Feb 13, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 13, 2026

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

Project Deployment Actions Updated (UTC)
cowfi Building Building Preview Feb 18, 2026 1:29pm
explorer-dev Building Building Preview Feb 18, 2026 1:29pm
swap-dev Building Building Preview Feb 18, 2026 1:29pm
widget-configurator Building Building Preview Feb 18, 2026 1:29pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
cosmos Ignored Ignored Feb 18, 2026 1:29pm
sdk-tools Ignored Ignored Preview Feb 18, 2026 1:29pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 13, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

 _______________________________________________________
< Coding ain't done 'til all the Tests run. 'Nuff said. >
 -------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

✏️ Tip: You can disable in-progress messages and the fortune message in your review settings.

Walkthrough

New atoms, hooks, and an updater centralize hiding of quote amounts and provider-network unsupported state; UI components and updaters are refactored to consume these atoms (shouldHideQuoteAmountsAtom, isProviderNetworkUnsupportedAtom, currentTradeQuoteAtom) via new hooks and utilities.

Changes

Cohort / File(s) Summary
New Atoms
apps/cowswap-frontend/src/modules/trade/state/shouldHideQuoteAmounts.atom.ts, apps/cowswap-frontend/src/entities/common/isProviderNetworkUnsupported.atom.ts, apps/cowswap-frontend/src/modules/tradeQuote/state/tradeQuoteAtom.ts
Adds shouldHideQuoteAmountsAtom (derived from current quote loading/error), isProviderNetworkUnsupportedAtom (boolean
Updater Integration
apps/cowswap-frontend/src/common/updaters/ProviderNetworkSupportedUpdater.ts, apps/cowswap-frontend/src/modules/application/containers/App/Updaters.tsx
New ProviderNetworkSupportedUpdater writes provider unsupported status into atom and is registered in the app Updaters tree.
Hooks / API
apps/cowswap-frontend/src/modules/trade/hooks/useShouldHideQuoteAmounts.ts, apps/cowswap-frontend/src/modules/trade/index.ts, apps/cowswap-frontend/src/modules/trade/hooks/useUpdateCurrencyAmount.ts
Adds useShouldHideQuoteAmounts hook and re-exports it; adds explicit return type to useUpdateCurrencyAmount.
Trade quote hook simplification
apps/cowswap-frontend/src/modules/tradeQuote/hooks/useTradeQuote.ts
Simplifies useTradeQuote to read currentTradeQuoteAtom directly (removes previous memo/derivation logic).
Currency info masking utility & form changes
apps/cowswap-frontend/src/modules/trade/containers/TradeWidget/TradeWidgetForm.utils.tsx, apps/cowswap-frontend/src/modules/trade/containers/TradeWidget/TradeWidgetForm.tsx
Adds mapCurrencyInfo to mask amounts/receive info based on hide flag; refactors TradeWidgetForm to use mapCurrencyInfo with sell/trade-derived logic.
Consumers updated to use centralized hide flag
apps/cowswap-frontend/src/modules/swap/containers/SwapWidget/index.tsx, apps/cowswap-frontend/src/modules/twap/containers/TwapFormWidget/index.tsx, apps/cowswap-frontend/src/modules/twap/updaters/QuoteObserverUpdater.tsx
Components now use useShouldHideQuoteAmounts and adjust rendering/side-effects accordingly (remove local gating, add hide guard, convert memo side-effects to useEffect).

Sequence Diagram

sequenceDiagram
    participant Provider as Provider Network
    participant Updater as ProviderNetworkSupportedUpdater
    participant Atoms as Jotai Atoms
    participant TradeQuote as currentTradeQuoteAtom
    participant UI as UI Components

    Provider->>Updater: provide network supported/unsupported status
    Updater->>Atoms: set `isProviderNetworkUnsupportedAtom`
    UI->>Atoms: read `shouldHideQuoteAmountsAtom` (via hook)
    TradeQuote->>Atoms: derive `currentTradeQuoteAtom` (reads provider atom & tradeQuotes)
    Atoms-->>UI: boolean to hide/show quote amounts
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • elena-zh
  • alfetopito
  • limitofzero

Poem

🐰 In a burrow of atoms I hop and hide,
Quotes peek out then tuck inside.
Networks whisper, updaters write,
Numbers blink in morning light—
Hooray, state hops on this joyful ride! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: generalizing quote amount displaying to handle error cases across multiple widgets.
Description check ✅ Passed The description includes all required sections: summary with issue reference, testing steps with checkboxes, and background context explaining the change rationale.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/trade-quote-error-handling

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.


import { useIsProviderNetworkUnsupported } from '../hooks/useIsProviderNetworkUnsupported'

export function ProviderNetworkSupportedUpdater(): null {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Just to wire up React state with atom

Copy link
Copy Markdown
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

🤖 Fix all issues with AI agents
In `@apps/cowswap-frontend/src/entities/common/providerNetworkSupported.atom.ts`:
- Around line 1-3: The atom's name is inverted relative to its semantics:
providerNetworkSupportedAtom actually stores the "unsupported" state; rename the
atom to providerNetworkUnsupportedAtom (keep its type boolean | null and initial
value null) and update all references accordingly—specifically replace uses in
ProviderNetworkSupportedUpdater.ts (where useIsProviderNetworkUnsupported()
sets/reads it) and in tradeQuoteAtom.ts (where the variable
isProviderNetworkUnsupported is used) so the atom name and its usages
consistently reflect that true means "unsupported".
🧹 Nitpick comments (2)
apps/cowswap-frontend/src/modules/tradeQuote/hooks/useTradeQuote.ts (1)

3-4: Nit: consolidate the two imports from the same module.

Lines 3 and 4 both import from '../state/tradeQuoteAtom'. These can be merged.

Proposed fix
-import { currentTradeQuoteAtom } from '../state/tradeQuoteAtom'
-import { TradeQuoteState } from '../state/tradeQuoteAtom'
+import { currentTradeQuoteAtom, TradeQuoteState } from '../state/tradeQuoteAtom'
apps/cowswap-frontend/src/modules/tradeQuote/state/tradeQuoteAtom.ts (1)

74-76: Rename providerNetworkSupportedAtom to clarify its actual semantics.

The atom stores the result of useIsProviderNetworkUnsupported() directly, so true means the network is unsupported. The current name providerNetworkSupportedAtom suggests the opposite. Rename to providerNetworkUnsupportedAtom (or isProviderNetworkUnsupportedAtom) to match its actual value semantics and prevent future misreads.

Comment thread apps/cowswap-frontend/src/entities/common/providerNetworkSupported.atom.ts Outdated
@elena-zh elena-zh requested review from a team February 13, 2026 13:15
Copy link
Copy Markdown
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!

… fix/trade-quote-error-handling

# Conflicts:
#	apps/cowswap-frontend/src/modules/trade/containers/TradeWidget/TradeWidgetForm.tsx
#	apps/cowswap-frontend/src/modules/tradeQuote/hooks/useTradeQuote.ts
Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/cowswap-frontend/src/modules/tradeQuote/state/tradeQuoteAtom.ts`:
- Around line 74-87: Add unit tests for currentTradeQuoteAtom covering the three
branches: (1) when derivedTradeStateAtom has missing input or output currencies
assert the atom returns DEFAULT_TRADE_QUOTE_STATE, (2) when
isProviderNetworkUnsupportedAtom is true assert it returns
DEFAULT_TRADE_QUOTE_STATE, and (3) when both currencies exist and
tradeQuotesAtom contains an entry keyed by
getCurrencyAddress(inputCurrency).toLowerCase() assert the stored quote is
returned; in each test, initialize/mock the relevant atoms
(isProviderNetworkUnsupportedAtom, derivedTradeStateAtom, tradeQuotesAtom) to
deterministic values and verify currentTradeQuoteAtom’s output matches
expectations, reusing the same key formation logic as updateTradeQuoteAtom to
build the tradeQuotes entry.

Comment thread apps/cowswap-frontend/src/modules/tradeQuote/state/tradeQuoteAtom.ts Outdated
Copy link
Copy Markdown
Contributor

@limitofzero limitofzero left a comment

Choose a reason for hiding this comment

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

put a small comment

@shoom3301 shoom3301 merged commit e4908c5 into develop Feb 18, 2026
7 of 12 checks passed
@shoom3301 shoom3301 deleted the fix/trade-quote-error-handling branch February 18, 2026 13:29
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 18, 2026
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.

3 participants