Skip to content

Conversation

@georgeweiler
Copy link
Contributor

@georgeweiler georgeweiler commented Dec 19, 2025

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:

  1. New Country type - Defines the shape of country data returned from the regions API, including isoCode, supported flag, and unsupportedStates array (for countries like the US where specific states may be blocked).

  2. New getCountries service 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.

  3. New getCountries controller method - Wraps the service call with the existing request caching infrastructure for deduplication and cache management.

  4. New getRegionEligibility controller method - The main entry point that:

    • Automatically fetches geolocation if not already available in state
    • Fetches the countries list
    • Checks if the user's country is in the supported list
    • For the US, additionally checks if the user's state is in the unsupportedStates array (e.g., NY is blocked)
    • Returns a boolean indicating eligibility

Notable implementation details:

  • The cache API uses a different base URL (on-ramp-cache.api.cx.metamask.io) than the main API, so a separate getCacheBaseUrl function was added
  • Geolocation format is COUNTRY-STATE (e.g., US-TX), and state codes are compared case-insensitively against the unsupportedStates array
  • When geolocation is null, getRegionEligibility automatically calls updateGeolocation before checking eligibility

References

  • TRAM-2923

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

@georgeweiler georgeweiler changed the title feat(ramps-controller): adds ramps controller methods for region elig… feat(ramps): adds controller methods for region eligibility Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants