Skip to content

fix(quick-buy): enable Buy CTA in lockstep with quote loader#31218

Merged
xavier-brochard merged 2 commits into
mainfrom
fix/quick-buy-cta-enable-lag
Jun 8, 2026
Merged

fix(quick-buy): enable Buy CTA in lockstep with quote loader#31218
xavier-brochard merged 2 commits into
mainfrom
fix/quick-buy-cta-enable-lag

Conversation

@xavier-brochard

@xavier-brochard xavier-brochard commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Description

In the QuickBuy bottom sheet, the Buy button sometimes took longer to become enabled than the amount-section quote loader took to disappear. The user expects the CTA to become tappable as soon as the quote completes.

Reason for the change: the loader and the Buy button were gated by two conditions that drifted out of sync for one render. The loader is driven by isBlockingQuoteLoad (gated by isQuoteLoading), which clears the instant the fetch resolves. The button is gated by isConfirmDisabled, which includes isPendingQuoteRefresh — and that value was derived from settledSourceTokenAmountRef, a ref updated only inside a post-commit useEffect. On the render where the quote arrived, the loader hid but the ref had not caught up, and ref writes do not schedule a re-render, so the CTA only re-enabled on the next unrelated render (a redux tick, gas-estimate update, quote countdown, etc.) — producing the variable lag.

Solution: replace the timing/effect-based "settled amount" tracking with a synchronous derivation. A displayed quote is for the current amount when the quote's own srcTokenAmount equals the requested amount (the request is built with calcTokenValue(sourceTokenAmount, decimals).toFixed(0) and the bridge echoes that exact value back). isPendingQuoteRefresh now derives from this synchronous check, so isBlockingQuoteLoad and isConfirmDisabled settle on the same render the matching quote lands. Background refreshes of the same amount keep srcTokenAmount unchanged, so the CTA stays enabled as before.

Changelog

CHANGELOG entry: Fixed the QuickBuy Buy button sometimes staying disabled briefly after the quote finished loading.

Related issues

Fixes: An issue where he QuickBuy Buy button sometimes staying disabled briefly after the quote finished loading.

Manual testing steps

Feature: QuickBuy Buy button enablement

  Scenario: Buy button enables as soon as the quote loads
    Given I open the QuickBuy bottom sheet for a token
    When I enter or select an amount and the quote loader spins
    Then the loader disappears when the quote completes
    And the Buy button becomes enabled on the same frame (no lag)

  Scenario: Buy button stays disabled while a new amount is being quoted
    Given a quote is already displayed for an amount
    When I change the amount so a new quote is fetched
    Then the Buy button is disabled until the quote for the new amount arrives

Screenshots/Recordings

Before

N/A

After

N/A

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Made with Cursor


Note

Low Risk
Localized QuickBuy confirm/disable logic with added unit tests; no auth, submission, or bridge API changes beyond when the button enables.

Overview
Fixes QuickBuy Buy staying disabled briefly after the quote loader finishes by replacing post-commit ref tracking of the “settled” amount with a synchronous isActiveQuoteForCurrentAmount check.

isPendingQuoteRefresh now derives from whether the on-screen quote matches the committed amount: atomic units from calcTokenValue on the requested sourceTokenAmount are compared to activeQuote.sentAmount (full wallet deduction), not quote.srcTokenAmount, so gas-included/sponsored quotes still enable the CTA when the displayed quote is valid.

Tests add default sentAmount on quote fixtures plus cases for same-render loader/CTA sync and post-fee srcTokenAmount with matching sentAmount.

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

The Buy button could stay disabled for a beat after the quote loader
disappeared. isPendingQuoteRefresh was derived from a ref updated inside a
post-commit useEffect, so on the render where the quote arrived the loader
hid (gated by isQuoteLoading) but the ref had not caught up yet, and ref
writes do not schedule a re-render. The CTA only re-enabled on the next
unrelated render.

Derive isActiveQuoteForCurrentAmount synchronously by comparing the quote's
own srcTokenAmount to the requested amount, and base isPendingQuoteRefresh on
it. The loader and CTA now settle on the same render the matching quote lands.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@mm-token-exchange-service mm-token-exchange-service Bot added team-social-ai Social & AI team INVALID-PR-TEMPLATE PR's body doesn't match template labels Jun 8, 2026
@xavier-brochard xavier-brochard marked this pull request as ready for review June 8, 2026 17:35
@github-actions github-actions Bot added size-S risk:medium AI analysis: medium risk labels Jun 8, 2026

@cursor cursor Bot 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.

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

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1ca32d8. Configure here.

This update improves the handling of gas-included quotes in the QuickBuy flow. It introduces a new `sentAmount` property to accurately reflect the total wallet deduction, including fees, allowing for better comparison against the requested amount. Additionally, the `isActiveQuoteForCurrentAmount` logic has been updated to ensure the Buy CTA is enabled correctly when the active quote matches the expected amount after accounting for fees.

Unit tests have been added to verify the new behavior, ensuring that the CTA is enabled for valid gas-included quotes and remains disabled when conditions are not met.
@github-actions github-actions Bot added size-M and removed size-S labels Jun 8, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: None (no tests recommended)
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 90%
click to see 🤖 AI reasoning details

E2E Test Selection:
The two changed files are:

  1. useQuickBuyController.ts - A refactor of the isPendingQuoteRefresh logic within the QuickBuy component of the SocialLeaderboard/TraderPositionView. The change replaces a useRef/useEffect pattern with a useMemo that compares sentAmount against the requested amount in atomic units. This fixes a bug where the Buy CTA was stuck disabled for gas-included/gas-sponsored quotes.

  2. useQuickBuyController.test.ts - Unit tests covering the new behavior.

Why no E2E tags are needed:

  • No E2E tests reference QuickBuy, TraderPosition, or SocialLeaderboard components (confirmed via grep)
  • The only related E2E tests are in tests/smoke/perps/ but they are all describe.skipped
  • The changes are purely internal to a React hook's state management logic (no API surface changes, no navigation changes, no shared component changes)
  • The fix is well-covered by the accompanying unit tests
  • No shared infrastructure (Engine, controllers, navigation, modals) is touched
  • The change is self-contained within the QuickBuy component hierarchy

Performance Test Selection:
The changes are a refactor of a React hook's internal state management logic (replacing useRef/useEffect with useMemo). While this is a minor optimization, it doesn't affect rendering performance in a measurable way for performance tests. The QuickBuy component is not covered by any performance test suite, and the change doesn't affect app startup, account list rendering, login, swaps, or other performance-tested flows.

View GitHub Actions results

@mm-token-exchange-service mm-token-exchange-service Bot removed the INVALID-PR-TEMPLATE PR's body doesn't match template label Jun 8, 2026
@xavier-brochard xavier-brochard enabled auto-merge June 8, 2026 17:59
@xavier-brochard xavier-brochard added this pull request to the merge queue Jun 8, 2026
Merged via the queue into main with commit c09f43c Jun 8, 2026
111 of 115 checks passed
@xavier-brochard xavier-brochard deleted the fix/quick-buy-cta-enable-lag branch June 8, 2026 20:38
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 8, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.82.0 Issue or pull request that will be included in release 7.82.0 label Jun 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.82.0 Issue or pull request that will be included in release 7.82.0 risk:medium AI analysis: medium risk size-M team-social-ai Social & AI team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants