Skip to content

fix(tradeQuote): clear stale error on params change - #7728

Merged
Danziger merged 7 commits into
cowprotocol:developfrom
tenderdeve:fix/7438-stale-quote-error-on-token-change
Jul 10, 2026
Merged

Danziger merged 7 commits into
cowprotocol:developfrom
tenderdeve:fix/7438-stale-quote-error-on-token-change

Conversation

@tenderdeve

@tenderdeve tenderdeve commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Closes #7438

Problem

After a quote returns an error (e.g. insufficient liquidity), switching to a different token keeps the old error visible until the next quote response arrives. The form briefly shows an error that no longer applies to the current pair.

Repro:

  1. Connect on Ethereum
  2. Get a quote 1 WETH → USDC
  3. Change buy token to 0x583019fF0f430721aDa9cfb4fac8F06cA104d0B4 → "insufficient liquidity"
  4. Change buy token back to USDC → "insufficient liquidity" persists until next refresh

Cause

useTradeQuoteManager.setLoading flips isLoading and hasParamsChanged but leaves the previous error in state. The form keeps rendering the stale error while the new quote is fetched.

Fix

When hasParamsChanged is true, clear error in setLoading. Same-param polling refreshes are untouched, so transient error flicker during a normal refresh is not affected.

Testing

  1. Repro the steps from the issue
  2. After step 4, no "insufficient liquidity" error is shown — form enters loading state, then displays the fresh quote

Summary by CodeRabbit

  • Bug Fixes
    • Fixed trade-quote loading so stale error messages are cleared only when the core trade details change (e.g., tokens, amount, or order type).
    • Prevents incorrect dismissal of errors when only quote settings are adjusted, avoiding misleading “error flicker” during quote refreshes.
    • Ensures the displayed quote/loading state stays consistent with the latest user input.

When the user changes a quote parameter (e.g. swaps the buy token) after
a previous quote returned an error such as 'insufficient liquidity', the
old error remained displayed until the next quote response. The form
showed a stale error for an unrelated token pair while loading.

Clear `error` in `setLoading` whenever `hasParamsChanged` is true so
the form transitions cleanly into loading state for the new params.

Fixes cowprotocol#7438
@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

@tenderdeve is attempting to deploy a commit to the cow-dev Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7e041b51-f491-4b8a-b702-d7e5747fa3e3

📥 Commits

Reviewing files that changed from the base of the PR and between a51ef4c and 0f5bfa9.

📒 Files selected for processing (1)
  • apps/cowswap-frontend/src/modules/tradeQuote/hooks/useTradeQuoteManager.test.ts

Walkthrough

useTradeQuoteManager now clears quote errors only when the trade subject changes. The hook also adds a helper to detect those changes and tests covering slippage-only, token-change, and amount-change cases.

Changes

Trade Quote Error Reset

Layer / File(s) Summary
Conditional error reset in setLoading
apps/cowswap-frontend/src/modules/tradeQuote/hooks/useTradeQuoteManager.ts
setLoading now records the previous quote params and clears error only when the trade subject changed, while still setting the quote to loading.
Trade subject comparison helper
apps/cowswap-frontend/src/modules/tradeQuote/hooks/useTradeQuoteManager.ts
A new internal helper compares quote kind, amount, token addresses, and chain IDs, and treats missing previous params as no subject change.
Stale error clearing tests
apps/cowswap-frontend/src/modules/tradeQuote/hooks/useTradeQuoteManager.test.ts
The hook test file seeds quote state, mocks unsupported-token processing, and verifies stale errors stay on slippage-only changes but clear on buy-token and amount changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • shoom3301
  • fairlighteth
  • elena-zh

Poem

🐇 I hopped through quotes both old and new,
And left stale errors out of view.
When tokens change, the slate turns light,
Fresh quotes appear in morning bright.
No lingering gloom upon the trail—
Just loading hops and rabbit zeal!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: clearing stale trade-quote errors when quote parameters change.
Description check ✅ Passed The description includes the issue link, problem/cause/fix, and testing steps, so it is mostly complete despite not using the exact template headings.
Linked Issues check ✅ Passed The code and tests address #7438 by clearing stale errors on token-pair changes and reloading the quote instead of leaving the old error visible.
Out of Scope Changes check ✅ Passed The change set stays focused on stale error clearing and regression coverage, with no obvious unrelated code paths added.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@elena-zh elena-zh added the trigger-preview Add to a fork PR to trigger CF-pages preview. See https://github.com/cowprotocol/cowswap/pull/7615 label Jun 24, 2026
@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Cloudflare Pages preview mirror

Preview branch URL: https://github.com/cowprotocol/cowswap/tree/cf-preview/pr-7728
Mirror PR: #7732
Cloudflare Pages preview links will be posted on the mirror PR by the Cloudflare Pages GitHub integration once builds complete.

Source fork branch: tenderdeve/cowswap:fix/7438-stale-quote-error-on-token-change
Approval target SHA: b2b48813e327
Last mirrored SHA: 3950f009dcea
Last comment update: @Danziger at 2026-07-10T10:15:16.520Z

  • Sync Cloudflare preview to approval target commit

@github-actions github-actions Bot removed the trigger-preview Add to a fork PR to trigger CF-pages preview. See https://github.com/cowprotocol/cowswap/pull/7615 label Jun 24, 2026
@vercel
vercel Bot temporarily deployed to Preview – storybook June 24, 2026 10:40 Inactive
@vercel
vercel Bot temporarily deployed to Preview – widget-configurator June 24, 2026 10:41 Inactive
@vercel
vercel Bot temporarily deployed to Preview – cowfi June 24, 2026 10:42 Inactive

@elena-zh elena-zh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The app is blinking now as an insane one if a error happens

Image Image

Clearing the error on every params change made smart slippage recompute
(it returns null while an error is shown), which flipped the quote params
back and re-triggered the loading branch — flickering the form between the
error and loading states.

Restrict the error clear to genuine trade-subject changes (token pair,
amount or order kind) and ignore slippage-only param changes, so the stale
error is still dropped on token switch without the flicker.

Addresses @elena-zh's review feedback.
@tenderdeve

Copy link
Copy Markdown
Contributor Author

@elena-zh updated in a51ef4c — fixed the flicker. The blink came from clearing the error on every params change: while an error is shown smart slippage returns null, so clearing the error let it recompute, which changed the quote params and re-triggered the loading branch in a loop. The error clear is now restricted to genuine trade-subject changes (token pair / amount / order kind) and ignores slippage-only param changes, so switching tokens still drops the stale error but the form no longer blinks.

tenderdeve and others added 2 commits June 24, 2026 19:39
Guards the flicker regression: a slippage-only params change must keep the
existing error (clearing it would let smart slippage recompute and loop),
while a token-pair or amount change clears the stale error.
@vercel
vercel Bot temporarily deployed to Preview – storybook June 25, 2026 13:26 Inactive
@vercel
vercel Bot temporarily deployed to Preview – widget-configurator June 25, 2026 13:27 Inactive
@vercel
vercel Bot temporarily deployed to Preview – sdk-tools June 25, 2026 13:27 Inactive
@vercel
vercel Bot temporarily deployed to Preview – cowfi June 25, 2026 13:28 Inactive

@elena-zh elena-zh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM now, thank you

@Danziger
Danziger requested review from shoom3301 and removed request for shoom3301 July 10, 2026 09:58
@Danziger
Danziger enabled auto-merge (squash) July 10, 2026 10:22
@Danziger
Danziger merged commit a2e8a45 into cowprotocol:develop Jul 10, 2026
11 of 19 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 10, 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.

Error from a previous quote may be displayed for another token pair

3 participants