Skip to content

fix: prevent infinite quote request loop caused by token warning in unified swaps context cp-7.73.0#28361

Merged
infiniteflower merged 2 commits into
mainfrom
fix/swaps-infinite-loop-token-warnings
Apr 2, 2026
Merged

fix: prevent infinite quote request loop caused by token warning in unified swaps context cp-7.73.0#28361
infiniteflower merged 2 commits into
mainfrom
fix/swaps-infinite-loop-token-warnings

Conversation

@infiniteflower

@infiniteflower infiniteflower commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Description

When a destination token has a security warning (e.g. a Blockaid malicious/suspicious flag), the unified swaps bridge view was entering an infinite quote request loop.

Root cause: tokenWarning was included as a dependency of the useMemo that builds the analytics context object in useUnifiedSwapBridgeContext. tokenWarning is itself derived from quote results (blockaid data returned by the bridge controller). This created a feedback cycle:

Quote fetched → tokenWarning updates → context object recreates
→ updateQuoteParams identity changes → useEffect fires
→ new quote request → repeat ∞

Fix: Remove tokenWarning from the useMemo dependency array and clear security_warnings to [] for now. The security_warnings field will be populated properly in the bridge controller instead, removing the React dependency cycle entirely.

Changelog

CHANGELOG entry: Fixed a bug that caused repeated quote requests when swapping to a token with a security warning.

Related issues

Fixes: #28367

Manual testing steps

Feature: Unified Swaps/Bridge quote fetching with token warnings

  Scenario: user swaps to a token with a Blockaid security warning
    Given the user has opened the Swap/Bridge screen
    And the user has selected a source token with sufficient balance

    When the user selects a destination token that has a Blockaid security warning
    And the user enters a valid source amount
    Then the app fetches a quote once
    And does not repeatedly fire additional quote requests
    And the security warning banner is displayed on screen

  Scenario: user swaps to a normal token (no warning)
    Given the user has opened the Swap/Bridge screen
    And the user has selected a source token with sufficient balance

    When the user selects a destination token with no security warning
    And the user enters a valid source amount
    Then the app fetches a quote once
    And quote results are displayed normally

Screenshots/Recordings

Before

N/A

After

Uploading Screen Recording 2026-04-02 at 4.24.51 PM.mov…

Pre-merge author checklist

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

Low Risk
Low risk: small change limited to analytics context memoization, but it temporarily drops security_warnings data which could affect warning-related telemetry until re-populated elsewhere.

Overview
Prevents an infinite bridge quote re-fetch loop by removing destination token warning state from useUnifiedSwapBridgeContext’s memoized context object.

security_warnings is now always an empty array (TODO) and the useMemo dependency list no longer includes the warning selector, stabilizing the context identity passed into BridgeController.updateBridgeQuoteRequestParams.

Written by Cursor Bugbot for commit 21dec81. This will update automatically on new commits. Configure here.

@github-actions

github-actions Bot commented Apr 2, 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.

@metamaskbot metamaskbot added the team-swaps-and-bridge Swaps and Bridge team label Apr 2, 2026
@infiniteflower infiniteflower changed the title fix: prevent infinite quote request loop caused by token warning in unified swaps context fix: prevent infinite quote request loop caused by token warning in unified swaps context cp-7.73.0 Apr 2, 2026
@infiniteflower infiniteflower marked this pull request as ready for review April 2, 2026 20:25
@infiniteflower infiniteflower requested a review from a team as a code owner April 2, 2026 20:25

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

Comment thread app/components/UI/Bridge/hooks/useUnifiedSwapBridgeContext/index.ts
SteP-n-s
SteP-n-s previously approved these changes Apr 2, 2026
@infiniteflower infiniteflower enabled auto-merge April 2, 2026 20:43
@github-actions github-actions Bot added size-S risk-medium Moderate testing recommended · Possible bug introduction risk and removed size-XS labels Apr 2, 2026
@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeTrade, SmokeConfirmations
  • Selected Performance tags: @PerformanceSwaps
  • Risk Level: medium
  • AI Confidence: 88%
click to see 🤖 AI reasoning details

E2E Test Selection:
The change modifies useUnifiedSwapBridgeContext, a hook used in the Bridge/Swap flow. Specifically:

  1. What changed: Removed selectDestTokenWarning selector import and usage. The security_warnings field in the analytics context is now hardcoded to [] (with a TODO comment), instead of being populated from the destination token warning selector.

  2. Impact: This affects the swap/bridge analytics context passed via useBridgeQuoteRequest. The core swap/bridge functionality is not broken - only the security_warnings analytics field is temporarily emptied. However, this change touches the unified swap/bridge context that feeds into quote requests, so the swap and bridge flows need validation.

  3. Tags selected:

    • SmokeTrade: Directly covers swap and bridge flows that use this hook. Need to verify swaps and bridges still work correctly after removing the token warning dependency.
    • SmokeConfirmations: Required per SmokeTrade tag description - "When selecting SmokeTrade for swap/bridge flows, also select SmokeConfirmations."
  4. Tags NOT selected: No account, network, identity, or other feature areas are affected by this change. The change is isolated to the Bridge/Swap context hook.

Performance Test Selection:
The change modifies useUnifiedSwapBridgeContext which is used in useBridgeQuoteRequest - a core part of the swap flow. While the change is minor (removing a selector from the dependency array), it could theoretically affect memoization behavior in the swap context. Running @PerformanceSwaps provides a safety net to ensure swap flow performance hasn't regressed.

View GitHub Actions results

@sonarqubecloud

sonarqubecloud Bot commented Apr 2, 2026

Copy link
Copy Markdown

@github-actions

github-actions Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

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

@infiniteflower infiniteflower added this pull request to the merge queue Apr 2, 2026
Merged via the queue into main with commit b155157 Apr 2, 2026
97 checks passed
@infiniteflower infiniteflower deleted the fix/swaps-infinite-loop-token-warnings branch April 2, 2026 21:46
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 2, 2026
@weitingsun weitingsun added release-7.74.0 Issue or pull request that will be included in release 7.74.0 and removed release-99999.1.0 labels Apr 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.74.0 Issue or pull request that will be included in release 7.74.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-S team-swaps-and-bridge Swaps and Bridge team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Fetching a swaps quote for a token that is suspicious results in an infinite loading state.

6 participants