Commit fbdd300
authored
feat(ramps): uses api endpoint to determine ramp eligibility (#22279)
## **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**
```gherkin
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**
<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->
### **Before**
<!-- [screenshots/recordings] -->
### **After**
<!-- [screenshots/recordings] -->
## **Pre-merge author checklist**
- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
## **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.
<!-- CURSOR_SUMMARY -->
---
> [!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.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
77d4425. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 7e3f4ce commit fbdd300
File tree
3 files changed
+178
-6
lines changed- app/components/UI/Ramp/hooks
3 files changed
+178
-6
lines changedLines changed: 145 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
| |||
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| 65 | + | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| |||
68 | 71 | | |
69 | 72 | | |
70 | 73 | | |
71 | | - | |
| 74 | + | |
| 75 | + | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
| |||
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
90 | 98 | | |
91 | 99 | | |
92 | 100 | | |
| |||
126 | 134 | | |
127 | 135 | | |
128 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
129 | 237 | | |
130 | 238 | | |
131 | 239 | | |
| |||
258 | 366 | | |
259 | 367 | | |
260 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
261 | 405 | | |
262 | 406 | | |
263 | 407 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
16 | 34 | | |
17 | 35 | | |
18 | 36 | | |
| |||
44 | 62 | | |
45 | 63 | | |
46 | 64 | | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
52 | 78 | | |
53 | 79 | | |
54 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
0 commit comments