fix(ramps-controller): refresh countries catalog on app startup#9261
Conversation
Stop persisting the countries catalog and force-refetch via init() so preset amounts stay in sync after app restarts. TRAM-3682 Co-authored-by: Cursor <cursoragent@cursor.com>
TRAM-3682 Co-authored-by: Cursor <cursoragent@cursor.com>
dae992f to
82c35e8
Compare
saustrie-consensys
left a comment
There was a problem hiding this comment.
I left an important question before I can approve
| if (forceRefresh || !hasCountries) { | ||
| await this.getCountries(options); | ||
| } | ||
| await this.getCountries({ ...options, forceRefresh: true }); |
There was a problem hiding this comment.
@amitabh94 @wenfix Why not simply use forceRefresh? We created that option for a reason
There was a problem hiding this comment.
I believe this PR uses forceRefresh only.
There was a problem hiding this comment.
@saustrie-consensys just to make sure I follow: do you mean keep reading options.forceRefresh instead of hardcoding it (the old forceRefresh || !hasCountries shape), or that the caller should drive the refresh via init({ forceRefresh }) and #runInit shouldn't force it at all? Happy to go either way, with persist: false the cold start already refetches regardless, so the hardcoded forceRefresh: true was redundant either way.
There was a problem hiding this comment.
This is a small endpoint and not doing any major work so I am even okay to always refresh it on controller init i.e. everytime the app starts or user closes and reopens the app.
| }, | ||
| countries: { | ||
| persist: true, | ||
| persist: false, |
There was a problem hiding this comment.
I think this should be true as we want to honor the users selection of region from settings.
There was a problem hiding this comment.
I believe we can keep this change to remove the persistence on the countries endpoint as before because it is just to get the country catalog.My bad as I got confused between countries data and user region which are separate.
|
@metamaskbot publish-preview |
a1f454c to
1132ac3
Compare
|
@metamaskbot publish-preview |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
|
@metamaskbot publish-preview |
|
@metamaskbot publish-preview |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
## Explanation This release branch publishes `@metamask/ramps-controller` `15.1.0`. The release includes the scope-aware in-app provider widening work from MetaMask#9353, plus the existing unreleased `init()` / countries catalog refresh entries from MetaMask#9261. The release tool also bumped the root monorepo version to `1095.0.0` and updated `@metamask/transaction-pay-controller`'s workspace dependency on `@metamask/ramps-controller` to `^15.1.0`. This branch was generated by `yarn create-release-branch`. ## References - Related to MetaMask#9353 - Related to MetaMask#9261 - Related to MetaMask/metamask-mobile#32682 ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them Validation: `yarn changelog:validate` Made with [Cursor](https://cursor.com) --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…n app start (MetaMask#32776) ## **Description** Bumps `@metamask/ramps-controller` so `init()` no longer skips `getCountries()` when cached data is already present. Previously the countries catalog was persisted and reused across cold starts, so users kept seeing stale preset amounts (e.g. `100` for CRC) even after the API started returning the correct value (`25000`). The controller now stops persisting the catalog and re-fetches + re-syncs `userRegion` on every app start. Currently pinned to a preview build of the package (`@metamask-previews/ramps-controller@15.0.0-preview-1bd5239bf`) while the official release is pending in `MetaMask/core`; this will be swapped to the released `npm` version once it ships. ## **Changelog** CHANGELOG entry: Fixed an issue where some regions showed an incorrect default buy amount after a cold app start. ## **Related issues** Fixes: TRAM-3682 Core PR: MetaMask/core#9261 ## **Manual testing steps** ```gherkin Feature: Ramps region default amounts Scenario: user opens the app after a cold start Given the on-ramp API returns a CRC default amount of 25000 for Costa Rica When user cold-starts the app and opens the Buy flow with a Costa Rica region Then the preset default amount shown is 25000, not the stale cached 100 ``` ## **Screenshots/Recordings** ### **After** https://github.com/user-attachments/assets/6175bfd7-7071-469e-8f04-9003cac4cff8 ## **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 - [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. #### Performance checks (if applicable) - [ ] I've tested on Android - Ideally on a mid-range device; emulator is acceptable - [ ] I've tested with a power user scenario - Use these [power-user SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93) to import wallets with many accounts and tokens - [ ] I've instrumented key operations with Sentry traces for production performance metrics - See [`trace()`](/app/util/trace.ts) for usage and [`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274) for an example ## **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** > Touches on-ramp region defaults and adds a countries fetch on every cold start; behavior is confined to the ramps controller dependency with no local code edits. > > **Overview** > Upgrades **`@metamask/ramps-controller`** from `15.0.0` to **`15.1.0`** (lockfile only; no app source changes). That release changes startup behavior so the **countries catalog is fetched on every cold start** instead of reusing a persisted cache, which fixes **stale regional default buy amounts** in the Buy flow (e.g. Costa Rica showing `100` instead of API `25000`). > > The resolved package also moves **`@metamask/messenger`** to `^2.0.0` as a transitive dependency of the controller. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ce54dd9. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
Explanation
Stale persisted countries catalog data caused preset amounts (e.g. $100 / $250 / $500) to stay wrong after app restarts until the user changed region, even when the API had updated values.
This change is controller-only in
@metamask/ramps-controller— no MetaMask Mobile or portfolio changes.persist: false) so restarts do not reuse stale catalog data.init(), always refetch countries viagetCountries()(including whenuserRegionis already set).getCountries(), re-syncuserRegionpreset amounts from the fresh catalog via#syncUserRegionFromCountriesCatalog.Consumers need a new
@metamask/ramps-controllerrelease; mobile can pick it up via the usual Core dependency bump.References
Recording (mobile client)
country-default-amounts-after.mov
Checklist
Made with Cursor