Commit 609e9a8
authored
fix(ramps): ensure Buy tokens load on token selection screen on fresh install cp-7.68.0 (MetaMask#26952)
## **Description**
**Problem:** When users tap Buy and reach Token Selection (non-V2)
before geolocation and smart routing have run, the screen can show a
blank or incorrect state because `detectedGeolocation` and
`rampRoutingDecision` are not yet set. Previously, these ran only when
the FiatOrders component mounted (e.g. when the user entered a Ramp
flow), which could be too late.
**Solution:** Introduce a **RampsBootstrap** component that runs at app
root as soon as the app mounts:
1. **RampsBootstrap** (`app/components/UI/Ramp/RampsBootstrap.tsx`) –
New component that runs three hooks at app root:
- `useDetectGeolocation()` – detect user region
- `useRampsSmartRouting()` – set ramp routing decision (AGGREGATOR /
DEPOSIT / etc.)
- `useHydrateRampsController()` – when V2 is enabled, ensure controller
init/hydrate runs early
2. **App.tsx** – Mount `<RampsBootstrap />` at the root (direct import
from `Ramp/RampsBootstrap`). Marked with a TODO to remove once V2 flag
is on for all users.
3. **Ramp index (FiatOrders)** – Remove the three hook calls
(`useDetectGeolocation`, `useRampsSmartRouting`,
`useHydrateRampsController`) from `FiatOrders` so they run only once at
app root in RampsBootstrap. `FiatOrders` continues to run
`useFetchRampNetworks()` and order polling.
By the time the user reaches Buy → Token Selection, geolocation and
routing are usually already set, improving non-V2 behavior.
## **Changelog**
CHANGELOG entry: Run Ramps geolocation, smart routing, and controller
hydrate at app root via RampsBootstrap so Token Selection (non-V2) has
region and routing ready sooner.
## **Related issues**
Fixes: MetaMask#26699
## **Manual testing steps**
```gherkin
Feature: Ramps bootstrap at app root
Scenario: User opens app and navigates to Buy Token Selection (non-V2)
Given the app has just started
When the user taps Buy and reaches the Select token screen
Then geolocation and smart routing have already run (bootstrap at app root)
And the token list loads according to region and routing (no blank/empty due to missing geolocation)
Scenario: V2 flow still works
Given Ramps V2 is enabled
When the user goes to Buy and Token Selection
Then tokens load (Engine init plus bootstrap hydrate as before)
```
## **Screenshots/Recordings**
<div>
<a href="https://www.loom.com/share/b7b90cdc4a6645719d2bae04f28c2e3d">
<p>Fix buy token loading issue - 26699 - Watch Video</p>
</a>
<a href="https://www.loom.com/share/b7b90cdc4a6645719d2bae04f28c2e3d">
<img style="max-width:300px;"
src="https://cdn.loom.com/sessions/thumbnails/b7b90cdc4a6645719d2bae04f28c2e3d-c643ea7310eb57da-full-play.gif#t=0.1">
</a>
</div>
## **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
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] 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]
> **Medium Risk**
> Moves ramp bootstrap hooks (geolocation, smart routing, controller
hydration) to run at app startup, which can affect ramp availability
decisions and controller init timing across sessions. Risk is moderate
due to new side effects on app mount and potential extra network calls,
but changes are localized and covered by tests.
>
> **Overview**
> Ensures ramp prerequisites are initialized *as soon as the app mounts*
by introducing `RampsBootstrap`, which runs geolocation detection, smart
routing, and ramps controller hydration and renders `null`.
>
> Mounts `RampsBootstrap` at the `App` root (with a TODO to remove once
V2 is fully rolled out) and removes the same hook calls from
`FiatOrders`, preventing late/duplicate initialization when users reach
non-V2 Buy token selection. Adds unit tests for `RampsBootstrap` and
updates existing app/ramp tests to mock the new root-level component.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
0013f0e. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent e84c09e commit 609e9a8
6 files changed
Lines changed: 78 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| 129 | + | |
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
| |||
1168 | 1169 | | |
1169 | 1170 | | |
1170 | 1171 | | |
| 1172 | + | |
| 1173 | + | |
1171 | 1174 | | |
1172 | 1175 | | |
1173 | 1176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | 17 | | |
23 | 18 | | |
24 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 36 | | |
40 | 37 | | |
41 | 38 | | |
| |||
141 | 138 | | |
142 | 139 | | |
143 | 140 | | |
144 | | - | |
145 | 141 | | |
146 | | - | |
147 | | - | |
148 | 142 | | |
149 | 143 | | |
150 | 144 | | |
| |||
0 commit comments