Skip to content

fix(rewards): use GeolocationController for mUSD card geo check#27746

Merged
VGR-GIT merged 3 commits into
mainfrom
rwds-1107-show-musd
Mar 23, 2026
Merged

fix(rewards): use GeolocationController for mUSD card geo check#27746
VGR-GIT merged 3 commits into
mainfrom
rwds-1107-show-musd

Conversation

@VGR-GIT
Copy link
Copy Markdown
Contributor

@VGR-GIT VGR-GIT commented Mar 20, 2026

Description

Use the actual GeolocationController state instead of rewards Redux state to determine mUSD card visibility on the Rewards dashboard. This prevents a flash of the mUSD card for UK users when the card slice loads before the geo check completes.

Problem:
Previously, showMusdCard was derived as optinAllowedForGeo !== false, treating null (initial/undetermined) the same as true (allowed). The rewards Redux initial state has optinAllowedForGeoLoading: false and optinAllowedForGeo: null. When the card slice had already loaded but the rewards geo check hadn't started yet, isAnyGeoLoading evaluated to false while showMusdCard was true, causing the mUSD card to render briefly for UK users.

Solution:

  • Use selectGeolocationLocation and selectGeolocationStatus from GeolocationController
  • Require positive geo confirmation: location must be defined, not 'UNKNOWN', and not 'GB'
  • Handle all geo status states: 'idle', 'loading', 'complete', 'error'
  • Add UK_COUNTRY_CODE and UNKNOWN_LOCATION constants for clarity

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

Feature: mUSD card geo restriction

  Scenario: UK user should not see mUSD card flash
    Given the user is in the UK (geoLocation is 'GB')
    And the card geo check has completed before the GeolocationController

    When user navigates to Rewards dashboard
    Then the mUSD calculator card should NOT flash briefly
    And the mUSD calculator card should remain hidden

  Scenario: Non-UK user sees mUSD card after geo check completes
    Given the user is in the US (geoLocation is 'US')

    When user navigates to Rewards dashboard
    And the GeolocationController status becomes 'complete'
    Then the mUSD calculator card should be visible

Screenshots/Recordings

Before

N/A

After

N/A

Pre-merge author checklist

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.

Made with Cursor


Note

Low Risk
Low risk UI gating change that only affects when the mUSD rewards card renders; main risk is inadvertently hiding/showing the card for some geolocation edge cases (e.g., undefined/UNKNOWN/status handling).

Overview
Updates the Rewards dashboard EarnRewardsPreview to derive mUSD card visibility from GeolocationController (selectGeolocationLocation/selectGeolocationStatus) instead of the rewards reducer’s optinAllowedForGeo flags.

The mUSD card now renders only after a confirmed, known location and is explicitly hidden for GB and UNKNOWN/undefined locations, treating idle/loading as a loading state to prevent a brief “flash” for UK users. Tests are updated to cover the new idle/loading skeleton behavior and the undefined/UNKNOWN/GB hiding cases.

Written by Cursor Bugbot for commit b466bbf. This will update automatically on new commits. Configure here.

Use the actual GeolocationController state instead of rewards Redux
state to determine mUSD card visibility. This prevents a flash of the
mUSD card for UK users when the card slice loads before the geo check.

Changes:
- Use selectGeolocationLocation and selectGeolocationStatus from
  GeolocationController instead of rewards selectors
- Require positive geo confirmation (location must be defined, not
  'UNKNOWN', and not 'GB') to show mUSD card
- Handle all geo status states: 'idle', 'loading', 'complete', 'error'
- Add UK_COUNTRY_CODE and UNKNOWN_LOCATION constants for clarity

Made-with: Cursor
@VGR-GIT VGR-GIT self-assigned this Mar 20, 2026
@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-rewards Rewards team label Mar 20, 2026
@VGR-GIT VGR-GIT marked this pull request as ready for review March 20, 2026 15:00
@VGR-GIT VGR-GIT requested a review from a team as a code owner March 20, 2026 15:00
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.


const AVATAR_SIZE = 78;
const UK_COUNTRY_CODE = 'GB';
const UNKNOWN_LOCATION = 'UNKNOWN';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded UNKNOWN_LOCATION duplicates package-exported constant

Low Severity

The local UNKNOWN_LOCATION = 'UNKNOWN' constant duplicates the same constant already exported by @metamask/geolocation-controller, which is imported and used in app/core/Engine/controllers/geolocation-controller/index.ts. If the package ever changes its sentinel value, this hardcoded copy would silently diverge, causing the geo check to miss the unknown-location case and potentially flashing the mUSD card for users whose location lookup failed.

Fix in Cursor Fix in Web

@github-actions github-actions Bot added the risk-low Low testing needed · Low bug introduction risk label Mar 23, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-low Low testing needed · Low bug introduction risk labels Mar 23, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeCard
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 72%
click to see 🤖 AI reasoning details

E2E Test Selection:
The changes are in EarnRewardsPreview.tsx and its test file. The component is part of the Rewards Dashboard and shows earn reward cards (mUSD calculator card and MetaMask Card card). The key change is a refactor of the geolocation check: instead of using selectOptinAllowedForGeo/selectOptinAllowedForGeoLoading from the rewards reducers, it now uses selectGeolocationLocation/selectGeolocationStatus from the geolocationController selectors. The behavioral change is that the mUSD card is now hidden when geoLocation is undefined or 'UNKNOWN' (to prevent flash), and explicitly hidden for UK ('GB') users. This is a medium-risk change because it modifies geo-blocking logic that determines what users see in the Rewards section. The SmokeCard tag is the most relevant as it covers Card home screen display, Add Funds, and card-related analytics. The Rewards Dashboard is the entry point for the MetaMask Card feature. No other E2E tags directly test the EarnRewardsPreview component or Rewards Dashboard. The change does not affect core navigation, confirmations, or other shared components that would warrant broader test coverage.

Performance Test Selection:
The changes are a simple selector swap in a UI component - replacing one Redux selector with another. There is no new rendering logic, no list rendering changes, no data fetching changes, and no animation changes. The performance impact is negligible and does not warrant running performance tests.

View GitHub Actions results

@github-actions
Copy link
Copy Markdown
Contributor

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

@sonarqubecloud
Copy link
Copy Markdown

@VGR-GIT VGR-GIT enabled auto-merge March 23, 2026 14:15
@VGR-GIT VGR-GIT added this pull request to the merge queue Mar 23, 2026
Merged via the queue into main with commit 173222b Mar 23, 2026
198 of 200 checks passed
@VGR-GIT VGR-GIT deleted the rwds-1107-show-musd branch March 23, 2026 15:59
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 23, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-M team-rewards Rewards team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants