feat(ramps): adds controller methods for region eligibility #7539
+790
−27
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
Current state:
The RampsController currently supports fetching and storing the user's geolocation, but has no mechanism to determine whether a user's region is eligible for ramps (on/off-ramp services). This eligibility information is available via the regions/countries API endpoint, but wasn't being consumed by the controller.
Solution:
This PR adds region eligibility checking to the RampsController by:
New
Countrytype - Defines the shape of country data returned from the regions API, includingisoCode,supportedflag, andunsupportedStatesarray (for countries like the US where specific states may be blocked).New
getCountriesservice method - Calls the cached regions API (https://on-ramp-cache.api.cx.metamask.io/regions/countries) to fetch the list of countries with their eligibility information.New
getCountriescontroller method - Wraps the service call with the existing request caching infrastructure for deduplication and cache management.New
getRegionEligibilitycontroller method - The main entry point that:unsupportedStatesarray (e.g., NY is blocked)Notable implementation details:
on-ramp-cache.api.cx.metamask.io) than the main API, so a separategetCacheBaseUrlfunction was addedCOUNTRY-STATE(e.g.,US-TX), and state codes are compared case-insensitively against theunsupportedStatesarraygetRegionEligibilityautomatically callsupdateGeolocationbefore checking eligibilityReferences
Checklist