fix(ramps): Set the region state from geolocation's response initially only#8354
Draft
fix(ramps): Set the region state from geolocation's response initially only#8354
Conversation
2e9d637 to
e38a582
Compare
e38a582 to
e7946ce
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.
Explanation
Payment methods (
getPaymentMethods) were being fetched redundantly from two paths: the controller'sfireAndForgetcalls insidesetSelectedTokenandsetSelectedProvider, and React Query independently in the mobile hook. This caused 2–3 duplicate API calls on every token selection, blocking the user with a ~10s spinner.Changes:
setSelectedToken— RemovedfireAndForget(getPaymentMethods(...)). Token selection now only updatestokens.selectedand resets payment methods state. It no longer triggers a payment methods fetch; React Query on the mobile side is the single fetch owner.setSelectedProvider— RemovedfireAndForget(getPaymentMethods(...))and thetokenSupportedByProvidergate that only existed to guard that call. Provider selection now only updatesproviders.selectedand resets payment methods state. React Query on the mobile side handles fetching.#runInit(geolocation fix) —forceRefreshno longer overrides a persisteduserRegionwith the geolocation endpoint response. Geolocation is only used to seed the initial region whenuserRegionis null, matching the agreed behavior: "once set, always respect the user's choice."Link to metamask-mobile
TBD — mobile PR removes the duplicate React Query fetch trigger and scopes the query key to
[regionCode, providerId]only.References
TRAM-3398
Changelog
CHANGELOG entry: @metamask/ramps-controller — Removed redundant
fireAndForget(getPaymentMethods)fromsetSelectedTokenandsetSelectedProvider; React Query is now the single fetch owner. Fixedinitto not override persisted user region with geolocation onforceRefresh.Checklist