Skip to content

Conversation

@georgeweiler
Copy link
Contributor

@georgeweiler georgeweiler commented Nov 6, 2025

Description

This PR updates the Ramps Smart Routing hook to use the actual API endpoints now that they are available in production and staging environments.

What is the reason for the change?
The smart routing feature was previously using a placeholder endpoint (/endpoint-coming-soon) while waiting for the backend API to be deployed. The API endpoints are now available and ready to be integrated.

What is the improvement/solution?

  • Integrated production and staging API endpoints for ramp eligibility checks
  • Production URL: https://on-ramp-content.api.cx.metamask.io/regions/countries/{region-code}
  • Staging URL: https://on-ramp-content.uat-api.cx.metamask.io/regions/countries/{region-code}
  • Environment detection uses process.env.METAMASK_ENVIRONMENT directly to determine which endpoint to use
  • Production environments: production, beta, rc
  • Staging environments: dev, exp, test, e2e, and all others default to staging

Changelog

CHANGELOG entry: null

Related issues

Fixes: https://consensyssoftware.atlassian.net/browse/TRAM-2807

Manual testing steps

Feature: Ramp Smart Routing API Integration

  Scenario: User in supported region sees appropriate ramp option
    Given the app is running in a production environment
    And the user's detected geolocation is "us-ca"
    When the ramp smart routing hook initializes
    Then the app fetches eligibility from "https://on-ramp-content.api.cx.metamask.io/regions/countries/us-ca"
    And the routing decision is set based on the API response

  Scenario: User in supported region in staging environment
    Given the app is running in a dev/staging environment
    And the user's detected geolocation is "us-ca"
    When the ramp smart routing hook initializes
    Then the app fetches eligibility from "https://on-ramp-content.uat-api.cx.metamask.io/regions/countries/us-ca"
    And the routing decision is set based on the API response

  Scenario: User in unsupported region
    Given the app is running in any environment
    And the user's detected geolocation returns global: false from API
    When the ramp smart routing hook initializes
    Then the routing decision is set to UNSUPPORTED
    And the user cannot access ramp features

  Scenario: API fetch fails
    Given the app is running in any environment
    And the API request fails or times out
    When the ramp smart routing hook initializes
    Then the routing decision is set to ERROR
    And appropriate error logging occurs

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Hook now fetches ramp eligibility from environment-specific endpoints with error handling; tests expanded and Babel config updated to preserve env vars.

  • Ramps Smart Routing (app/components/UI/Ramp/hooks/useRampsSmartRouting.ts)
    • Use real eligibility API with env-based base URLs via process.env.METAMASK_ENVIRONMENT (PRODUCTION vs STAGING).
    • Build fetch URL '/regions/countries/{region}'; validate response.ok and throw on errors; log and route to ERROR on failure.
  • Tests (useRampsSmartRouting.test.ts)
    • Add cases verifying production/staging URLs across envs (production, beta, rc, dev, exp, test, e2e).
    • Add error-path tests for failed fetch and non-OK responses (404, 500); persist/restore env; update geolocation to us-ca.
  • Build/Config (babel.config.tests.js)
    • Exclude useRampsSmartRouting.ts and its tests from inline env var transform to allow runtime env-based behavior.

Written by Cursor Bugbot for commit 77d4425. This will update automatically on new commits. Configure here.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-ramp issues related to Ramp features label Nov 6, 2025
@github-actions github-actions bot added the size-M label Nov 6, 2025
@georgeweiler georgeweiler marked this pull request as ready for review November 7, 2025 03:40
@georgeweiler georgeweiler requested a review from a team as a code owner November 7, 2025 03:40
const baseUrl = getBaseUrl();
const response = await fetch(
`/endpoint-coming-soon?region=${rampGeodetectedRegion}`,
`${baseUrl}/regions/countries/${rampGeodetectedRegion}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use URL object to construct URLs, as it handles bass URLs trailing slashes, encoding, etc...

const url = new URL(`/regions/countries/${rampGeodetectedRegion}`, baseUrl).toString();
await fetch(url);

@sonarqubecloud
Copy link

@georgeweiler georgeweiler added this pull request to the merge queue Nov 11, 2025
Merged via the queue into main with commit fbdd300 Nov 11, 2025
86 checks passed
@georgeweiler georgeweiler deleted the TRAM-2834-ramp-eligibility-api-fetch branch November 11, 2025 01:00
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 2025
@metamaskbot metamaskbot added the release-7.60.0 Issue or pull request that will be included in release 7.60.0 label Nov 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.60.0 Issue or pull request that will be included in release 7.60.0 size-M team-ramp issues related to Ramp features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants