Skip to content

fix(ramps): normalize provider IDs in BuildQuote quote matching [TRAM-3331]#28337

Merged
saustrie-consensys merged 7 commits into
mainfrom
saustrie-consensys/fix-token-error-flash
Apr 13, 2026
Merged

fix(ramps): normalize provider IDs in BuildQuote quote matching [TRAM-3331]#28337
saustrie-consensys merged 7 commits into
mainfrom
saustrie-consensys/fix-token-error-flash

Conversation

@saustrie-consensys
Copy link
Copy Markdown
Contributor

@saustrie-consensys saustrie-consensys commented Apr 2, 2026

Description

When selecting a token in the UB2 Buy flow, a quick error ("We've encountered an error") flashes on the amount input screen before the correct "Powered by [provider]" text appears.

The root cause is a provider ID mismatch: the quotes API can return provider IDs in a prefixed format (/providers/transak) while the controller state stores them without the prefix (transak). This caused selectedQuote to resolve to null, briefly rendering the error banner.

The fix normalizes provider IDs on both sides of the comparison using normalizeProviderCode() and switches from array destructuring to .find() so all returned quotes are searched.

Changelog

CHANGELOG entry: Fixed Buy amount screen sometimes showing a generic error when quotes returned for the selected provider but provider id strings differed in format.

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TRAM-3331
Based on draft PR #27779

Manual testing steps

Feature: Token selection in Buy flow

  Scenario: user selects a token and navigates to amount input
    Given user is on the token selection screen in the Buy flow

    When user selects a token (e.g. ETH)
    Then the amount input screen shows "Powered by [provider]" without any error flash

Screenshots/Recordings

Before

N/A. Reason: This is an extremely rare race condition. It doesn't happen often, and after several changes on main, it's even less common. Nevertheless, we still want to solve this logical condition via this PR.

After

N/A. Reason: This is an extremely rare race condition. It doesn't happen often, and after several changes on main, it's even less common. Nevertheless, we still want to solve this logical condition via this PR.

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
Touches Buy flow quote-selection and payment-method loading state; small logic changes but in a user-critical conversion path and could affect when errors/continue button appear.

Overview
Prevents the Buy amount input screen from briefly showing the generic no quotes error by updating BuildQuote to normalize provider IDs (handling /providers/... vs short codes) and to search all returned quotes via .find() when deriving selectedQuote.

Tightens useRampsPaymentMethods loading behavior so isLoading stays true while auto-selecting a payment method when the previously selected method is no longer present, avoiding UI flashes of stale selection. Adds targeted tests covering provider-ID matching scenarios, empty/mismatched quote responses, continue-button disabled state, and the stale-selection loading fallback.

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

The UB2 BuildQuote screen compared quote.provider with
selectedProvider.id using strict equality. When the API returned
prefixed IDs (e.g. /providers/transak) the match failed, causing a
brief error flash. Use normalizeProviderCode on both sides and .find()
instead of array destructuring so all returned quotes are searched.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

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.

@saustrie-consensys saustrie-consensys self-assigned this Apr 2, 2026
@saustrie-consensys saustrie-consensys added team-money-movement issues related to Money Movement features team-ramps labels Apr 2, 2026
@github-actions github-actions Bot added the size-M label Apr 2, 2026
@saustrie-consensys saustrie-consensys changed the title fix(ramps): normalize provider IDs in BuildQuote quote matching fix(ramps): normalize provider IDs in BuildQuote quote matching [TRAM-3331] Apr 2, 2026
@saustrie-consensys saustrie-consensys marked this pull request as ready for review April 6, 2026 14:52
@saustrie-consensys saustrie-consensys requested a review from a team as a code owner April 6, 2026 14:52
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.

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 25ca6bb. Configure here.

Comment thread app/components/UI/Ramp/Views/BuildQuote/BuildQuote.test.tsx Outdated
wachunei
wachunei previously approved these changes Apr 6, 2026
saustrie-consensys and others added 2 commits April 7, 2026 23:57
isAutoSelecting only checked !selectedPaymentMethod (null), missing the
case where the selected method is stale (no longer in the refreshed list).
This allowed the stale name to flash before the useEffect corrected it.

Now also checks that the current selection exists in the fetched list,
keeping isLoading true until the fallback completes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the risk-medium Moderate testing recommended · Possible bug introduction risk label Apr 7, 2026
Replace toBeTruthy/toBeNull with toBeOnTheScreen/not.toBeOnTheScreen
per unit testing guidelines.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 8, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 13, 2026
Comment on lines +124 to +125
!paymentMethodsQuery.data.some(
(m) => m.id === selectedPaymentMethod.id,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: for clarity

Suggested change
!paymentMethodsQuery.data.some(
(m) => m.id === selectedPaymentMethod.id,
paymentMethodsQuery.data.every(
(m) => m.id !== selectedPaymentMethod.id,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll add it now

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
The changes are focused entirely within the Ramp (on-ramp/off-ramp) feature:

  1. useRampsPaymentMethods.ts: Bug fix for isAutoSelecting logic - now correctly handles the case where a previously selected payment method is no longer in the available list (stale selection). This prevents UI flash during payment method refresh.

  2. BuildQuote.tsx: Bug fix for selectedQuote matching - now uses normalizeProviderCode() for provider ID comparison and find() instead of only checking the first quote. This fixes provider ID prefix mismatches (e.g., /providers/moonpay vs moonpay) and cases where the matching quote isn't first in the array.

  3. Test files: Unit tests validating the new behaviors.

These are targeted bug fixes in the Ramps feature's BuildQuote flow and payment method selection. The changes are self-contained within app/components/UI/Ramp/ with no impact on shared infrastructure, controllers, navigation, or other wallet features. SmokeRamps is the appropriate and sufficient tag to validate these changes.

Performance Test Selection:
These changes are bug fixes in the Ramps BuildQuote flow and payment method selection logic. They involve minor conditional logic changes (isAutoSelecting check and quote matching via find()) with no impact on rendering performance, data loading patterns, or any performance-sensitive paths. No performance tests are warranted.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

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

@saustrie-consensys saustrie-consensys added this pull request to the merge queue Apr 13, 2026
Merged via the queue into main with commit 16484d7 Apr 13, 2026
93 checks passed
@saustrie-consensys saustrie-consensys deleted the saustrie-consensys/fix-token-error-flash branch April 13, 2026 15:00
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 13, 2026
@metamaskbot metamaskbot added the release-7.74.0 Issue or pull request that will be included in release 7.74.0 label Apr 13, 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-M team-money-movement issues related to Money Movement features team-ramps

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants