fix(ramps): payment methods not loading after provider change when token unsupported#8102
Closed
amitabh94 wants to merge 1 commit intoMetaMask:mainfrom
Closed
Conversation
…nge when token unsupported - setSelectedProvider: use assetId the new provider supports (selected token or first supported) so payment-methods API succeeds - getPaymentMethods: apply response when provider matches; set selected payment method to first when fallback assetId was used Fixes TRAM-3314. Related TRAM-3315. Made-with: Cursor
6cd4483 to
4556fdf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem: After changing provider in the Buy flow (e.g. from "Change provider" in the Token Not Available modal), payment methods sometimes never load and the user can see an internal error. This happens when the selected token is not supported by the new provider: the controller still requested payment methods using the current (unsupported) token’s
assetId, so the API failed or returned empty and payment methods stayed cleared.Root cause:
setSelectedProvider(providerId)calledgetPaymentMethods(regionCode, { provider: provider.id })without passingassetId.getPaymentMethodsthen usedassetIdfrom state (state.tokens.selected?.assetId). So the request was (newProvider + old selected token). If that token isn’t supported by the new provider, the payment-methods API can fail or return empty → payment methods never load.getPaymentMethodsonly applied the response when bothtokenSelectionUnchangedandproviderSelectionUnchangedwere true. When we later fix (1) by requesting with a fallback assetId (a token the new provider supports), the response would havetokenSelectionUnchanged === false, so we never applied the result and the UI stayed in loading/error.Solution:
setSelectedProvider: When fetching payment methods for the new provider, use anassetIdthe new provider supports: the selected token if it’s inprovider.supportedCryptoCurrencies, otherwise the first supported asset. Pass that explicitly togetPaymentMethodsso the API succeeds.getPaymentMethods(update block): Apply the returned payment methods wheneverproviderSelectionUnchangedis true (not only when token also matches). When we used a fallback assetId, reset the selected payment method to the first in the list so the UI has a valid selection.Files changed:
packages/ramps-controller/src/RampsController.ts–setSelectedProvider: compute and pass supportedassetIdfor payment methods;getPaymentMethods: apply payment methods when provider matches, and set selected to first when token didn’t match or selection invalid.packages/ramps-controller/CHANGELOG.md– Fixed entry for payment methods not loading after provider change.Changelog
CHANGELOG entry added under Fixed: Fix payment methods not loading after changing provider when the selected token is not supported by the new provider; controller now uses a supported asset for the request and still applies the response when provider matches.
Related issues
Manual testing steps
Provider change when token not supported
Provider change when token is supported
SOL / non-EVM (TRAM-3315)
Pre-merge author checklist
Pre-merge reviewer checklist