Skip to content

chore: refactor quickbuy to use fetchQuotes v2#29165

Merged
joaosantos15 merged 4 commits into
mainfrom
TSA-426-quickbuy-fetchquotes-partial-v2
Apr 22, 2026
Merged

chore: refactor quickbuy to use fetchQuotes v2#29165
joaosantos15 merged 4 commits into
mainfrom
TSA-426-quickbuy-fetchquotes-partial-v2

Conversation

@joaosantos15
Copy link
Copy Markdown
Contributor

@joaosantos15 joaosantos15 commented Apr 22, 2026

Description

  • Replaces QuickBuy's dependency on the Bridge polling hooks (useBridgeQuoteRequest + useBridgeQuoteData) with a one-shot BridgeController.fetchQuotes call managed by a new local hook, useQuickBuyQuotes.
  • Quote state (active quote, loading, error, no-quotes-available) now lives in QuickBuy component state — BridgeController.state.quotes is never populated, so opening QuickBuy no longer pollutes the shared Bridge slice.
  • Adds a quoteOverride parameter to useIsInsufficientBalance so the gas-adjusted native-token balance check still works when the quote lives in local state instead of Redux. All existing callers are unaffected (param is optional).

Out of scope / follow-ups

  • Quote auto-refresh and isExpired UX are not ported; a single fetch per input change.
  • Blockaid validation on Solana source quotes is not ported (was in useBridgeQuoteData). No need because this is already handled by fetchQuotes.
  • Redux slice dispatches (setSourceToken, setDestToken, setSourceAmount, resetBridgeState, setIsSubmittingTx) are kept so useSubmitBridgeTx, useRewards, useInitialSlippage, and useRecipientInitialization still work unchanged. Full slice removal is tracked for a later PR.

Changelog

CHANGELOG entry: no-changelog

Related issues

Fixes:

Manual testing steps

Feature: my feature name

  Scenario: user [verb for user action]
    Given [describe expected initial app state]

    When user [verb for user action]
    Then [describe expected outcome]

Screenshots/Recordings

Before

After

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.

Note

Medium Risk
QuickBuy’s quote lifecycle is refactored from shared Redux/polling hooks to local fetchQuotes calls, which can affect quote timing, error states, and balance gating. Balance checks now accept an optional quote override, so regressions are mostly limited to QuickBuy/bridge UX rather than core transaction signing.

Overview
QuickBuy now manages quotes locally by replacing the polling-based useBridgeQuoteRequest/useBridgeQuoteData flow with a new useQuickBuyQuotes hook that debounces one-shot BridgeController.fetchQuotes requests, tracks loading/error/no-quotes state, and derives the recommended/enriched quote via selectBridgeQuotes without populating shared controller/Redux quote state.

Balance validation is updated: useIsInsufficientBalance adds an optional quoteOverride (including explicit null to ignore Redux quotes) so QuickBuy can still include gas fee context when quotes live outside Redux; tests were updated/added to cover override precedence and QuickBuy wiring.

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

@github-actions
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.

@metamaskbotv2 metamaskbotv2 Bot added the team-social-ai Social & AI team label Apr 22, 2026
@joaosantos15 joaosantos15 marked this pull request as ready for review April 22, 2026 10:25
@joaosantos15 joaosantos15 requested a review from a team as a code owner April 22, 2026 10:25
@github-actions github-actions Bot added the risk:high AI analysis: high risk label Apr 22, 2026
Comment thread app/components/UI/Bridge/hooks/useInsufficientBalance/index.ts Outdated
@github-actions github-actions Bot added risk:medium AI analysis: medium risk and removed risk:high AI analysis: high risk labels Apr 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
12 value mismatches detected (expected — fixture represents an existing user).
View details

@github-actions github-actions Bot added risk:high AI analysis: high risk and removed risk:medium AI analysis: medium risk labels Apr 22, 2026
return () => {
debouncedFetchQuotes.cancel();
};
}, [debouncedFetchQuotes]);
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.

Missing abort on dependency change causes stale quote acceptance

Medium Severity

The effect cleanup cancels the debounce but does not abort the in-flight fetch. When a dependency changes (e.g., user edits the amount), the old API call can resolve and update rawQuotes/isQuoteLoading with stale data before the new debounced fetch starts. In useQuickBuyBottomSheet, the settledSourceTokenAmountRef effect sees isQuoteLoading transition to false and stamps settledSourceTokenAmountRef.current with the current sourceTokenAmount, making isPendingQuoteRefresh false — even though the quote data corresponds to the previous amount. This enables the confirm button with a stale quote for ~300ms, potentially allowing submission of a bridge transaction for the wrong amount.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d00a194. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

AI PR Analysis

🚫 Merge safe: false | 🟠 Risk: high

Merge decision: AI analysis did not complete — manual review required before merging.

AI analysis did not complete. Manual review recommended.

View run

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeTrade, SmokeConfirmations, SmokePredictions, SmokeWalletPlatform, SmokePerps
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 78%
click to see 🤖 AI reasoning details

E2E Test Selection:

The PR introduces changes to three areas:

  1. useInsufficientBalance (Bridge hook): Added an optional quoteOverride parameter that allows callers to bypass the Redux-held selectBridgeQuotes for gas fee calculations. This is backward-compatible but touches the Bridge insufficient balance check logic used in swap/bridge flows → SmokeTrade + SmokeConfirmations (required per SmokeTrade tag description).

  2. useQuickBuyQuotes (new hook): A new hook that fetches bridge quotes independently (directly via BridgeController.fetchQuotes) for the QuickBuy flow in SocialLeaderboard/TraderPositionView. This bypasses the standard Redux bridge quote flow and enriches results using selectBridgeQuotesBase. This is a new quote-fetching path that could affect the QuickBuy transaction flow.

  3. useQuickBuyBottomSheet (refactored): Replaces useBridgeQuoteRequest + useBridgeQuoteData with the new useQuickBuyQuotes hook, and wires quoteOverride to useIsInsufficientBalance. Also removes blockaidError from the error state.

The QuickBuyBottomSheet is used in the SocialLeaderboard/TraderPositionView which is related to:

  • SmokePredictions: The SocialLeaderboard feature is tied to Polymarket prediction market positions (TraderPositionView shows trader positions, QuickBuy allows buying into positions) → SmokePredictions + SmokeWalletPlatform (required per SmokePredictions tag description)
  • SmokePerps: The QuickBuy flow could also be used for Perps positions → SmokePerps + SmokeWalletPlatform (required per SmokePerps tag description)

The changes are primarily refactoring with good unit test coverage. No changes to core controllers, navigation, or shared infrastructure. Risk is medium because the quote fetching path for QuickBuy has been significantly refactored.

Performance Test Selection:
The changes are focused on hook-level refactoring of quote fetching logic for the QuickBuy flow and an optional parameter addition to useInsufficientBalance. These are not UI rendering changes, list rendering changes, or app startup changes. The new useQuickBuyQuotes hook uses debouncing (300ms) which is a performance consideration, but this is a new feature path rather than a regression risk for existing performance benchmarks. No performance test tags are warranted.

View GitHub Actions results

Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

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.

There are 2 total unresolved issues (including 1 from previous review).

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 50226d7. Configure here.

abortControllerRef.current = controller;

setIsQuoteLoading(true);
setQuoteFetchError(null);
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.

Stale isNoQuotesAvailable persists during new fetch

Medium Severity

When a new fetch begins, quoteFetchError is correctly reset to null but isNoQuotesAvailable is not reset to false. If a previous fetch returned zero quotes, the stale isNoQuotesAvailable = true persists throughout the next fetch. Since hasError in useQuickBuyBottomSheet is derived from quoteFetchError || isNoQuotesAvailable, the button incorrectly shows "unavailable" text while a new quote is actively loading. The resetQuotesIdle helper does reset it, but it's only called for invalid inputs — not before a valid fetch starts.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 50226d7. Configure here.

@sonarqubecloud
Copy link
Copy Markdown

@joaosantos15 joaosantos15 added this pull request to the merge queue Apr 22, 2026
Merged via the queue into main with commit 918ea88 Apr 22, 2026
59 of 64 checks passed
@joaosantos15 joaosantos15 deleted the TSA-426-quickbuy-fetchquotes-partial-v2 branch April 22, 2026 18:20
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 22, 2026
@metamaskbotv2 metamaskbotv2 Bot added the release-7.75.0 Issue or pull request that will be included in release 7.75.0 label Apr 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.75.0 Issue or pull request that will be included in release 7.75.0 risk:high AI analysis: high risk size-L team-social-ai Social & AI team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants