-
-
Notifications
You must be signed in to change notification settings - Fork 268
refactor(ramps): ramps controller geolocation rename #7563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+354
−81
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…controller-get-eligibility
…controller-get-eligibility
… into TRAM-2923-ramps-controller-get-eligibility
…controller-get-eligibility
…-geolocation-rename
…-geolocation-rename
7 tasks
wachunei
reviewed
Jan 9, 2026
Comment on lines
509
to
515
| if (state.userRegion === null) { | ||
| state.eligibility = eligibility; | ||
| } else { | ||
| const currentUserRegion = state.userRegion.toLowerCase().trim(); | ||
| if (currentUserRegion === normalizedIsoCode) { | ||
| state.eligibility = eligibility; | ||
| } |
Member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small suggestion for readability: extract state.geolocation as a variable to avoid the null check and string manipulation on separate lines:
this.update((state) => {
const userRegion = state.geolocation?.toLowerCase().trim();
if (userRegion === null || userRegion === normalizedIsoCode) {
state.eligibility = eligibility;
}
});
wachunei
approved these changes
Jan 12, 2026
github-merge-queue bot
pushed a commit
to MetaMask/metamask-mobile
that referenced
this pull request
Jan 15, 2026
<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->
## **Description**
This PR adopts the breaking changes from `@metamask/ramps-controller`
v3.1.0, which refactors the controller to use "userRegion" terminology
instead of "geolocation" and introduces proper initialization patterns.
### **Reason for Change**
The ramps-controller package was refactored to:
1. **Improve naming clarity**: "geolocation" implies a read-only,
automatically-detected value, but we plan to allow users to manually
change their region. The new "userRegion" terminology better reflects
that it's a user-selectable region.
2. **Add proper initialization**: Previously, consumers had to manually
call `updateGeolocation()` after creating the controller, which was
error-prone. The new `init()` method encapsulates initialization logic
and automatically fetches the user region at startup.
3. **Enable manual region setting**: The new `setUserRegion()` method
allows users to manually set their region without calling the
geolocation API, preparing for future UI features.
### **Changes in This PR**
#### **Selectors** (`app/selectors/rampsController/index.ts`)
- ✅ Removed deprecated `selectGeolocation` selector
- ✅ Removed deprecated `selectGeolocationRequest` selector
- ✅ Added `selectUserRegion` selector (replaces `selectGeolocation`)
- ✅ Added `selectUserRegionRequest` selector (replaces
`selectGeolocationRequest`)
#### **Hooks** (`app/components/UI/Ramp/hooks/`)
- ✅ Renamed `useRampsGeolocation.ts` → `useRampsUserRegion.ts`
- ✅ Updated hook to use new `updateUserRegion()` and `setUserRegion()`
methods
- ✅ Updated hook to use new `selectUserRegion` and
`selectUserRegionRequest` selectors
- ✅ Updated all references and imports throughout the codebase
#### **Controller Initialization**
(`app/core/Engine/controllers/ramps-controller/ramps-controller-init.ts`)
- ✅ Updated to call `controller.init()` at startup (non-blocking)
- ✅ Initialization automatically fetches user region via geolocation API
- ✅ Errors are handled gracefully and available via selectors
#### **Tests**
- ✅ Updated `ramps-controller-init.test.ts` to test new `init()` method
- ✅ Updated `useRampsUserRegion.test.ts` to use new API and cache keys
- ✅ Updated selector tests to use `userRegion` state property
- ✅ All tests updated to use `'updateUserRegion'` cache key instead of
`'updateGeolocation'`
#### **Yarn Patch**
- ✅ Updated ramps-controller patch to include all local changes
(userRegion state, updateUserRegion, setUserRegion, init methods)
### **Migration Guide**
**Before:**
```ts
import { selectGeolocation, selectGeolocationRequest } from './selectors/rampsController';
import { useRampsGeolocation } from './hooks/useRampsGeolocation';
// Manual initialization required
Engine.context.RampsController.updateGeolocation();
```
**After:**
```ts
import { selectUserRegion, selectUserRegionRequest } from './selectors/rampsController';
import { useRampsUserRegion } from './hooks/useRampsUserRegion';
// Automatic initialization via controller.init() in ramps-controller-init.ts
```
### **Breaking Changes Adopted**
- ❌ `geolocation` state property → ✅ `userRegion`
- ❌ `updateGeolocation()` method → ✅ `updateUserRegion()`
- ❌ `selectGeolocation` selector → ✅ `selectUserRegion`
- ❌ `selectGeolocationRequest` selector → ✅ `selectUserRegionRequest`
- ❌ `useRampsGeolocation()` hook → ✅ `useRampsUserRegion()`
### **Related PRs**
- Core package PR:
[MetaMask/core#7563](MetaMask/core#7563) -
Refactors ramps-controller to use userRegion terminology and adds init()
method
## **Changelog**
<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`
If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`
(This helps the Release Engineer do their job more quickly and
accurately)
-->
CHANGELOG entry: Adopted new ramp controller variable names
## **Related issues**
Fixes:
## **Manual testing steps**
```gherkin
Feature: my feature name
Scenario: user [verb for user action]
Given [describe expected initial app state]
When user [verb for user action]
Then [describe expected outcome]
```
## **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**
- [ ] 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).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] 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]
> Adopts the new `@metamask/ramps-controller` v3 APIs and init model.
>
> - Migrate from `geolocation` to `userRegion`: new `useRampsUserRegion`
hook (with `fetchUserRegion` and `setUserRegion`), selectors
`selectUserRegion`/`selectUserRegionRequest` (retain `selectGeolocation`
aliases); update `useRampsGeolocation` to call `updateUserRegion`
> - Initialize controller via `controller.init()` at startup
(`ramps-controller-init`), replacing `updateGeolocation` side-effect
> - Refactor ramps service init: derive environment via
`getRampsEnvironment` and platform context via `getRampsContext` (uses
`Platform.OS`)
> - Update fixtures, snapshots, and tests accordingly (new request keys
`updateUserRegion:[]`, added `eligibility`/`tokens` fields)
> - Bump dependency to `@metamask/ramps-controller@^3.0.0`
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
c99674b. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation
Current State and Why It Needs to Change
The RampsController currently uses "geolocation" terminology (
geolocationstate,updateGeolocation()method), which implies a read-only, automatically-detected value. However, we plan to allow users to manually change their region in the future, so the naming should reflect that it's a user-selectable region rather than just a detected geolocation.Additionally, consumers must manually call
updateGeolocation()after creating the controller, which is error-prone and lacks a clear initialization pattern.Solution and How It Works
This PR refactors the controller to use "userRegion" terminology and introduces proper initialization:
geolocation→userRegion,updateGeolocation()→updateUserRegion()init()method: Encapsulates initialization logic, automatically fetches user region at startupsetUserRegion()method: Allows manual region setting without geolocation API, preparing for future UI featureBreaking Changes
geolocationstate property →userRegionupdateGeolocation()method →updateUserRegion()selectGeolocationandselectGeolocationRequestselectorsuseRampsGeolocation()hookselectUserRegion,selectUserRegionRequest, anduseRampsUserRegion()insteadWhy Multiple Packages Were Updated
This refactor touches both the core controller package and the mobile app because:
All changes are coordinated to ensure consistent API updates and proper migration from deprecated names.
References
Mobile PR that adopts the breaking changes: MetaMask/metamask-mobile#24280
Checklist
Note
BREAKING: Rename geolocation API
geolocation→userRegion; methodupdateGeolocation()→updateUserRegion()with updated request cache keys and testsNew APIs
init()to fetch initialuserRegionon startup (graceful failure)setUserRegion(region)to manually set region and fetch eligibilityBehavioral updates
updateUserRegioneligibilityon failures only if region still matches; prevent race-based overwritesupdateEligibility(isoCode)only updates state whenuserRegionmatches the isoCode/undefinedMisc
createRequestSelectorexamples and tests to referenceupdateUserRegionWritten by Cursor Bugbot for commit ab80f89. This will update automatically on new commits. Configure here.