Skip to content

Commit 28f70ae

Browse files
authored
refactor(ramps): ramps controller geolocation rename (#7563)
## Explanation ### Current State and Why It Needs to Change The RampsController currently uses "geolocation" terminology (`geolocation` state, `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: 1. **Renamed state and methods**: `geolocation` → `userRegion`, `updateGeolocation()` → `updateUserRegion()` 2. **Added `init()` method**: Encapsulates initialization logic, automatically fetches user region at startup 3. **Added `setUserRegion()` method**: Allows manual region setting without geolocation API, preparing for future UI feature ### Breaking Changes - `geolocation` state property → `userRegion` - `updateGeolocation()` method → `updateUserRegion()` - Removed deprecated `selectGeolocation` and `selectGeolocationRequest` selectors - Removed deprecated `useRampsGeolocation()` hook - Consumers should use `selectUserRegion`, `selectUserRegionRequest`, and `useRampsUserRegion()` instead ### Why Multiple Packages Were Updated This refactor touches both the core controller package and the mobile app because: - Core package contains the controller implementation and public API - Mobile app contains initialization, selectors, hooks, and tests that consume the controller All changes are coordinated to ensure consistent API updates and proper migration from deprecated names. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> Mobile PR that adopts the breaking changes: MetaMask/metamask-mobile#24280 ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs) - [ ] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **BREAKING**: Rename geolocation API > > - State `geolocation` → `userRegion`; method `updateGeolocation()` → `updateUserRegion()` with updated request cache keys and tests > > **New APIs** > > - Add `init()` to fetch initial `userRegion` on startup (graceful failure) > - Add `setUserRegion(region)` to manually set region and fetch eligibility > > **Behavioral updates** > > - Normalize region to lowercase; automatically fetch eligibility after `updateUserRegion` > - Clear stale `eligibility` on failures only if region still matches; prevent race-based overwrites > - `updateEligibility(isoCode)` only updates state when `userRegion` matches the isoCode/undefined > - Handle null/undefined geolocation results > > **Misc** > > - Update `createRequestSelector` examples and tests to reference `updateUserRegion` > - Changelog updated > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit ab80f89. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent b250eeb commit 28f70ae

File tree

7 files changed

+354
-81
lines changed

7 files changed

+354
-81
lines changed

packages/ramps-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12+
- **BREAKING:** Rename `geolocation` to `userRegion` and `updateGeolocation()` to `updateUserRegion()` in RampsController ([#7563](https://github.com/MetaMask/core/pull/7563))
13+
1214
- Bump `@metamask/controller-utils` from `^11.17.0` to `^11.18.0` ([#7583](https://github.com/MetaMask/core/pull/7583))
1315

1416
## [2.1.0]
@@ -21,6 +23,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2123

2224
- Add request caching infrastructure with TTL, deduplication, and abort support ([#7536](https://github.com/MetaMask/core/pull/7536))
2325

26+
- Add `init()` and `setUserRegion()` methods to RampsController ([#7563](https://github.com/MetaMask/core/pull/7563))
27+
2428
### Changed
2529

2630
- Bump `@metamask/controller-utils` from `^11.16.0` to `^11.17.0` ([#7534](https://github.com/MetaMask/core/pull/7534))

0 commit comments

Comments
 (0)