Skip to content

fix: add fallbacks for swap quote sorting#25928

Merged
micaelae merged 8 commits intomainfrom
swap-sorting-fallbacks
Feb 12, 2026
Merged

fix: add fallbacks for swap quote sorting#25928
micaelae merged 8 commits intomainfrom
swap-sorting-fallbacks

Conversation

@micaelae
Copy link
Copy Markdown
Member

@micaelae micaelae commented Feb 10, 2026

Description

Uses the priceImpact or destTokenAmount to sort bridge quotes if fiat cost is not available

Changelog

CHANGELOG entry: fix: fall back to priceImpact or destTokenAmount for swap quote sorting

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

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
Changes quote ordering logic and timing of exchange-rate fetching, which can affect which quote is recommended and potentially alter user-facing swap/bridge outcomes when data is missing.

Overview
Improves selectSortedBridgeQuotes sorting behavior in the patched @metamask/bridge-controller so the default sort no longer treats missing fiat cost as 0; it now sorts by fiat cost when available for all quotes, otherwise falls back to priceImpact, and finally destTokenAmount.

Moves fetchAssetExchangeRates from the quote-request update path to the fetchBridgeQuotes path (fire-and-forget with logging), aligning rate fetching with quote retrieval.

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

@metamaskbot metamaskbot added the team-swaps-and-bridge Swaps and Bridge team label Feb 10, 2026
@micaelae micaelae marked this pull request as ready for review February 11, 2026 22:27
@micaelae micaelae requested a review from a team as a code owner February 11, 2026 22:27
@micaelae micaelae enabled auto-merge February 11, 2026 22:27
Copy link
Copy Markdown

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

+ return (0, lodash_1.orderBy)(quotesWithMetadata, ({ cost }) => Number(cost.valueInCurrency), 'asc');
+ }
+ if (quotesWithMetadata.every((quote) => quote.quote.priceData?.priceImpact)) {
+ return (0, lodash_1.orderBy)(quotesWithMetadata, ({ quote }) => Number(quote.priceData?.priceImpact), 'asc');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Price impact ascending sort recommends worst quote first

High Severity

The priceImpact fallback sorts ascending ('asc'), but mock data shows priceImpact values are negative (e.g., "-0.001991570073761955"), where less negative means a better quote. Ascending sort places the most negative (worst) value first, so selectRecommendedQuote (which picks quotes[0]) would recommend the quote with the worst price impact. The sort direction likely needs to be 'desc' to match the destTokenAmount fallback pattern, which correctly uses descending to put the best quote first.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A negative priceImpact indicates a better quote so ascending is the correct order. For example: a quote with -.5 priceImpact is better than one with .1 priceImpact

ghgoodreau
ghgoodreau previously approved these changes Feb 12, 2026
SteP-n-s
SteP-n-s previously approved these changes Feb 12, 2026
infiniteflower
infiniteflower previously approved these changes Feb 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeAccounts, SmokeConfirmations, SmokeIdentity, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeTrade, SmokeWalletPlatform, SmokeCard, SmokePerps, SmokeRamps, SmokeMultiChainAPI, SmokePredictions, FlaskBuildTests
  • Selected Performance tags: @PerformanceAccountList, @PerformanceOnboarding, @PerformanceLogin, @PerformanceSwaps, @PerformanceLaunch, @PerformanceAssetLoading, @PerformancePredict, @PerformancePreps
  • Risk Level: high
  • AI Confidence: 100%
click to see 🤖 AI reasoning details

E2E Test Selection:
Hard rule (controller-version-update): @MetaMask controller package version updated in package.json: @metamask/assets-controllers@npm:^99.2.0, @metamask/bridge-controller@npm:^65.3.0, @metamask/bridge-controller@npm:^65.2.0, @metamask/bridge-controller@npm:^65.1.0, @metamask/bridge-controller. Running all tests.

Performance Test Selection:
Hard rule (controller-version-update): @MetaMask controller package version updated in package.json: @metamask/assets-controllers@npm:^99.2.0, @metamask/bridge-controller@npm:^65.3.0, @metamask/bridge-controller@npm:^65.2.0, @metamask/bridge-controller@npm:^65.1.0, @metamask/bridge-controller. Running all tests.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

LGTM

@micaelae micaelae added this pull request to the merge queue Feb 12, 2026
Merged via the queue into main with commit 6994d93 Feb 12, 2026
267 of 272 checks passed
@micaelae micaelae deleted the swap-sorting-fallbacks branch February 12, 2026 23:50
@github-actions github-actions bot locked and limited conversation to collaborators Feb 12, 2026
@metamaskbot metamaskbot added the release-7.67.0 Issue or pull request that will be included in release 7.67.0 label Feb 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.67.0 Issue or pull request that will be included in release 7.67.0 size-S team-swaps-and-bridge Swaps and Bridge team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants