Skip to content

fix(ramps): Set the region state from geolocation's response initially only#8354

Draft
imyugioh wants to merge 3 commits intomainfrom
fix/ramps-geolocaiton-call-init-once
Draft

fix(ramps): Set the region state from geolocation's response initially only#8354
imyugioh wants to merge 3 commits intomainfrom
fix/ramps-geolocaiton-call-init-once

Conversation

@imyugioh
Copy link
Copy Markdown
Member

@imyugioh imyugioh commented Mar 31, 2026

Explanation

Payment methods (getPaymentMethods) were being fetched redundantly from two paths: the controller's fireAndForget calls inside setSelectedToken and setSelectedProvider, 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:

  1. setSelectedToken — Removed fireAndForget(getPaymentMethods(...)). Token selection now only updates tokens.selected and resets payment methods state. It no longer triggers a payment methods fetch; React Query on the mobile side is the single fetch owner.

  2. setSelectedProvider — Removed fireAndForget(getPaymentMethods(...)) and the tokenSupportedByProvider gate that only existed to guard that call. Provider selection now only updates providers.selected and resets payment methods state. React Query on the mobile side handles fetching.

  3. #runInit (geolocation fix)forceRefresh no longer overrides a persisted userRegion with the geolocation endpoint response. Geolocation is only used to seed the initial region when userRegion is 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) from setSelectedToken and setSelectedProvider; React Query is now the single fetch owner. Fixed init to not override persisted user region with geolocation on forceRefresh.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@imyugioh imyugioh self-assigned this Mar 31, 2026
@imyugioh imyugioh force-pushed the fix/ramps-geolocaiton-call-init-once branch from 2e9d637 to e38a582 Compare April 1, 2026 00:50
@imyugioh imyugioh changed the title fix: coinbase order crypto currency lookup by network-aware ID mapping fix(ramps): Set the region state from geolocation's response initially only Apr 1, 2026
@imyugioh imyugioh force-pushed the fix/ramps-geolocaiton-call-init-once branch from e38a582 to e7946ce Compare April 1, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant