feat(trade): generalize quote amount displaying for error case#7011
feat(trade): generalize quote amount displaying for error case#7011
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ✏️ Tip: You can disable in-progress messages and the fortune message in your review settings. WalkthroughNew 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
|
|
||
| import { useIsProviderNetworkUnsupported } from '../hooks/useIsProviderNetworkUnsupported' | ||
|
|
||
| export function ProviderNetworkSupportedUpdater(): null { |
There was a problem hiding this comment.
Just to wire up React state with atom
There was a problem hiding this comment.
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: RenameproviderNetworkSupportedAtomto clarify its actual semantics.The atom stores the result of
useIsProviderNetworkUnsupported()directly, sotruemeans the network is unsupported. The current nameproviderNetworkSupportedAtomsuggests the opposite. Rename toproviderNetworkUnsupportedAtom(orisProviderNetworkUnsupportedAtom) to match its actual value semantics and prevent future misreads.
70addd6 to
46c91bc
Compare
… 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
There was a problem hiding this comment.
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.
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.
To Test
Please also check Limit orders and Swap for sell/buy orders.
Summary by CodeRabbit
New Features
Improvements