fix(frontend): debounce swap and market sim quote queries (#346) #855

Merged
PlasticDigits merged 2 commits from local1/346-impl-quote-debounce into main 2026-06-10 05:32:58 +00:00
PlasticDigits commented 2026-06-10 03:39:49 +00:00 (Migrated from gitlab.com)

Fixes #346


Note

Medium Risk
Changes when quotes run and when users can submit trades, which could briefly delay submit or show a prior quote until debounce settles; actual txs still use the typed amount with a stale-quote guard.

Overview
Reduces indexer/LCD quote churn while users type pay amounts by debouncing simulation queries (350ms) on Swap and Trade market panels, instead of firing a sim on every keystroke.

Sim useQuery keys and queryFn now use the debounced raw amount, with keepPreviousData so the UI can keep showing the last quote during refetch. isSimQuoteStaleForSubmit blocks swap/market submit when the live typed amount does not match the debounced sim key or when placeholder data is still shown; Swap shows Calculating... in that window.

Adds reusable useDebouncedValue (with Vitest coverage) and quoteDebounce.ts, and documents the behavior in the swap route display agent notes.

Reviewed by Cursor Bugbot for commit b44758c63c. Bugbot is set up for automated code reviews on this repo. Configure here.

Fixes #346 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes when quotes run and when users can submit trades, which could briefly delay submit or show a prior quote until debounce settles; actual txs still use the typed amount with a stale-quote guard. > > **Overview** > Reduces indexer/LCD quote churn while users type pay amounts by **debouncing simulation queries (350ms)** on **Swap** and **Trade market** panels, instead of firing a sim on every keystroke. > > Sim `useQuery` keys and `queryFn` now use the **debounced raw amount**, with **`keepPreviousData`** so the UI can keep showing the last quote during refetch. **`isSimQuoteStaleForSubmit`** blocks swap/market submit when the live typed amount does not match the debounced sim key or when placeholder data is still shown; Swap shows **Calculating...** in that window. > > Adds reusable **`useDebouncedValue`** (with Vitest coverage) and **`quoteDebounce.ts`**, and documents the behavior in the swap route display agent notes. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b44758c63cf676e99786c15d876957fdbc88aec8. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
ghost1 commented 2026-06-10 03:39:58 +00:00 (Migrated from gitlab.com)

changed the description

changed the description
ghost1 commented 2026-06-10 03:40:05 +00:00 (Migrated from gitlab.com)

changed the description

changed the description
ghost1 commented 2026-06-10 03:40:43 +00:00 (Migrated from gitlab.com)

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue.

Reviewed by Cursor Bugbot for commit b6fb88bce2. Configure here.

<!-- BUGBOT_REVIEW --> Cursor Bugbot has reviewed your changes and found 1 potential issue. <!-- BUGBOT_FIX_ALL --> <a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aToxZmE3MTZmMC1jNDNhLTQ1OGItYWQ3ZS01NDliZWRjN2ZjZTEiLCJlbmNyeXB0aW9uS2V5IjoidmxFVEZJM3FaNDYtcTQ5NkQzWVVBTFBEMC1WaWduX0FvTHJRT3F6Mk1aNCIsImJyYW5jaCI6ImxvY2FsMS8zNDYtaW1wbC1xdW90ZS1kZWJvdW5jZSIsInJlcG9Pd25lciI6IlBsYXN0aWNEaWdpdHMiLCJyZXBvTmFtZSI6ImNsOHktZGV4LXRlcnJhY2xhc3NpYyJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <!-- /BUGBOT_FIX_ALL --> <!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN --> <sup>Bugbot Autofix is [ON](https://www.cursor.com/dashboard/bugbot). A cloud agent has been kicked off to fix the reported issue. <!-- BUGBOT_AUTOFIX_AGENT_LINK --></sup> <!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END --> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b6fb88bce2e7f148c673384a65e07a9baeafcbd1. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
ghost1 commented 2026-06-10 03:40:44 +00:00 (Migrated from gitlab.com)

Stale quote allows swap submit

Medium Severity

Sim quotes now key off debounced amounts with keepPreviousData, but swap submit still uses the live input for pay size, minReceived, and indexer ops. Submit stays enabled while the typed amount differs from the debounced quote or while a refetch runs, so execution can use a quote for another amount.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b6fb88bce2. Configure here.

### Stale quote allows swap submit **Medium Severity** <!-- DESCRIPTION START --> Sim quotes now key off debounced amounts with `keepPreviousData`, but swap submit still uses the live input for pay size, `minReceived`, and indexer ops. Submit stays enabled while the typed amount differs from the debounced quote or while a refetch runs, so execution can use a quote for another amount. <!-- DESCRIPTION END --> <!-- BUGBOT_BUG_ID: 6a73bb8c-4e58-40bb-ac52-95d89d5cfdad --> <!-- LOCATIONS START frontend-dapp/src/pages/SwapPage.tsx#L808-L850 frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx#L437-L448 frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx#L153-L277 LOCATIONS END --> <details> <summary>Additional Locations (2)</summary> - [`frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx#L437-L448`](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-//blob/b6fb88bce2e7f148c673384a65e07a9baeafcbd1/frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx#L437-L448) - [`frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx#L153-L277`](https://gitlab.com/PlasticDigits/cl8y-dex-terraclassic/-//blob/b6fb88bce2e7f148c673384a65e07a9baeafcbd1/frontend-dapp/src/components/trade/TradeMarketOrderPanel.tsx#L153-L277) </details> <div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmZlNzQzNmYzLTE2NzItNGE2NC04YWU1LTJlMDY5OWM5YjNkNyIsImVuY3J5cHRpb25LZXkiOiI0c19KRGVRdndLUlFHVG53UlpEMU5FZmxhV0Q1eldBTkJVRFdmU2VoTmI4IiwiYnJhbmNoIjoibG9jYWwxLzM0Ni1pbXBsLXF1b3RlLWRlYm91bmNlIiwicmVwb093bmVyIjoiUGxhc3RpY0RpZ2l0cyIsInJlcG9OYW1lIjoiY2w4eS1kZXgtdGVycmFjbGFzc2ljIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmZlNzQzNmYzLTE2NzItNGE2NC04YWU1LTJlMDY5OWM5YjNkNyIsImVuY3J5cHRpb25LZXkiOiI0c19KRGVRdndLUlFHVG53UlpEMU5FZmxhV0Q1eldBTkJVRFdmU2VoTmI4IiwiYnJhbmNoIjoibG9jYWwxLzM0Ni1pbXBsLXF1b3RlLWRlYm91bmNlIiwicmVwb093bmVyIjoiUGxhc3RpY0RpZ2l0cyIsInJlcG9OYW1lIjoiY2w4eS1kZXgtdGVycmFjbGFzc2ljIiwicHJOdW1iZXIiOjEzNywiY29tbWl0U2hhIjoiYjZmYjg4YmNlMmU3ZjE0OGM2NzMzODRhNjVlMDdhOWJhZWFmY2JkMSIsInByb3ZpZGVyIjoiZ2l0bGFiIiwiaG9zdG5hbWUiOiJnaXRsYWIuY29tIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b6fb88bce2e7f148c673384a65e07a9baeafcbd1. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
ghost1 commented 2026-06-10 03:42:57 +00:00 (Migrated from gitlab.com)

added 1 commit

  • b44758c6 - fix: block swap submit while debounced quote is stale

Compare with previous version

added 1 commit <ul><li>b44758c6 - fix: block swap submit while debounced quote is stale</li></ul> [Compare with previous version](/PlasticDigits/cl8y-dex-terraclassic/-/merge_requests/137/diffs?diff_id=1843479578&start_sha=b6fb88bce2e7f148c673384a65e07a9baeafcbd1)
ghost1 commented 2026-06-10 03:43:15 +00:00 (Migrated from gitlab.com)

changed the description

changed the description
PlasticDigits commented 2026-06-10 05:32:53 +00:00 (Migrated from gitlab.com)

resolved all threads

resolved all threads
PlasticDigits commented 2026-06-10 05:32:58 +00:00 (Migrated from gitlab.com)

mentioned in commit 338947b1c2

mentioned in commit 338947b1c262a6b36bb0303c766b0fc8b3af4356
PlasticDigits (Migrated from gitlab.com) merged commit 338947b1c2 into main 2026-06-10 05:32:58 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
code/cl8y-dex-terraclassic!855
No description provided.