feat: defer eligibility to allow for onboarding to proceed without le…#8197
Merged
Conversation
…aking private url
…OnFeatureFlagChange to refreshEligibility()
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Member
Author
|
@metamaskbot publish-previews |
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
7 tasks
abretonc7s
requested changes
Mar 16, 2026
abretonc7s
left a comment
Contributor
There was a problem hiding this comment.
We cant modify core directly, it should come from mobile than sync to core or we loose mobile as source of truth
This was referenced Mar 16, 2026
Merged
abretonc7s
previously approved these changes
Mar 16, 2026
abretonc7s
left a comment
Contributor
There was a problem hiding this comment.
Approving before the resync
abretonc7s
reviewed
Mar 16, 2026
abretonc7s
approved these changes
Mar 16, 2026
github-merge-queue Bot
pushed a commit
to MetaMask/metamask-mobile
that referenced
this pull request
Mar 19, 2026
) ## **Description** Adds `deferEligibilityCheck` constructor option to `PerpsController` that prevents the eager geolocation fetch during wallet onboarding (privacy compliance). Also adds `startEligibilityMonitoring()` method to resume checks post-onboarding. Follow-up fixes included in this PR: - **Remove mobile-only imports from perps controller code** — `@sentry/react-native` (PerpsController, TradingService) and `AppConstants` (MYXClientService) were breaking core sync. Routed `addBreadcrumb` through `PerpsTracer` infrastructure injection, replaced `AppConstants.ZERO_ADDRESS` with existing perps constant. - **Fix core sync script** — `--ext .ts` no longer works with core's flat eslint config; replaced with glob patterns. - **Fix `@metamask/geolocation-controller` missing from core tsconfig/package.json** — added as devDependency and project reference so perps-controller builds in core. ## **Changelog** CHANGELOG entry: null ## **Related issues** Fixes: Core PR [#8197](MetaMask/core#8197) ## **Manual testing steps** ```gherkin Feature: Deferred eligibility check Scenario: PerpsController defers geolocation during onboarding Given PerpsController is instantiated with deferEligibilityCheck: true When refreshEligibility is called Then it returns immediately without fetching geolocation Scenario: Eligibility monitoring resumes post-onboarding Given PerpsController was instantiated with deferEligibilityCheck: true When startEligibilityMonitoring() is called Then eligibility checks resume using current remote feature flag state ``` ## **Screenshots/Recordings** N/A — internal controller changes, no UI impact. ## **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)). ## **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 eligibility/geo-blocking flow by optionally skipping geolocation and adding a new entry point to re-enable checks, which could affect region-gating if misused. Default behavior is unchanged when the new option is not set, and coverage is added via unit tests. > > **Overview** > Adds an optional `deferEligibilityCheck` constructor flag to `PerpsController` that **prevents the initial geolocation-based eligibility check** from running until explicitly resumed. > > Introduces `startEligibilityMonitoring()` (also exposed via messenger action types) to clear the deferral, read current remote feature flags, and immediately trigger an eligibility refresh, with error logging if feature-flag state lookup fails. > > Extends `PerpsController` tests to cover the deferred/ resumed behavior and error logging, plus a small typing cleanup in preload cache key assertions. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit cf17d6b. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
4 tasks
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Mar 25, 2026
## Explanation Mobile (`feat/perps/core-resolver`, PR MetaMask/metamask-mobile#27899) is the source of truth for perps code. The last sync to core was Feb 26 — 27 days stale. Since then, 4 commits went directly to core (#7941, #8197, #8214, #8234), all of which have been backported into the mobile branch. This PR syncs the latest mobile perps code to core using `validate-core-sync.sh`. Key changes: - **Geolocation dependency**: Added `@metamask/geolocation-controller` as a devDependency + tsconfig reference — `messenger.ts` now imports `GeolocationControllerGetGeolocationAction` for eligibility geolocation checks. - **New files**: `MYXWalletService.ts` (MYX wallet integration) and `PerpsController-method-action-types.ts` (typed action map). - **Package exclusion**: Added `!dist/services/MYXWalletService*` to `files` in `package.json` to keep MYX code out of published package. - **MYX provider**: Enhanced error handling (tightened to `error.code` check), wallet service integration, expanded config constants. - **HyperLiquid provider**: Subscription reliability improvements, order book processing, expanded event names. - **Eligibility service**: Refactored for geolocation-based region blocking via GeolocationController messenger action. - **ESLint**: 3 suppressions (1 `no-restricted-globals` for `require()` in MYX dynamic load, 2 `@typescript-eslint/no-base-to-string` in myxAdapter). Supersedes stale PR #8207 (`feat/perps/newsync`, 139 commits behind main). ## References - Supersedes #8207 - Related to MetaMask/metamask-mobile#27899 - Backported core PRs: #7941, #8197, #8214, #8234 ## Checklist - [ ] 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 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Touches core Perps controller/provider logic (provider init, caching, eligibility geo-checks) and adds MYX wallet/authenticated reads, which could affect data freshness and provider availability across networks. > > **Overview** > Syncs Perps code from mobile into core, including **new MYX wallet/auth plumbing** and broader provider/config updates. > > `PerpsController` now (a) defers messenger handler registration until `init()`, (b) resolves MYX enablement via credentials/flags and dynamically imports/registers MYX with explicit auth config resolution, and (c) replaces single cached preload fields with **per-provider/per-network market+user caches** (with reinit guards and preload retriggering). > > Adds geolocation-based eligibility checking via `GeolocationController:getGeolocation`, expands analytics/event constants, and refactors exports to explicit named exports. HyperLiquid reliability is improved with better multi-DEX failure handling, asset-id repair/backfill, stale market-data fallback, configurable builder addresses, and a new `fetchHistoricalCandles`; MYX config/endpoints are updated and `MYXProvider` gains authenticated read support (positions/orders/fills/funding/history) plus candle subscription (REST + WS updates). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit d8a453d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
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
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
Add
deferEligibilityCheckconstructor option that prevents the eager geolocation fetch toon-ramp.api.cx.metamask.io/geolocationfrom firing during wallet onboarding, fixing a privacy compliance violation in the extension's maximum-privacy onboarding E2E testAdd
startEligibilityMonitoring()public method that the consumer calls post-onboarding to read the current feature flag state, perform the initial eligibility check, and unblock the already-registeredRemoteFeatureFlagController:stateChangesubscriptionImplementation uses a single guard in
refreshEligibilityOnFeatureFlagChangeNote: This does not update the perps-controller to use the new geolocation service. This would require removing the existing
EligibilityServicein order to keep the change as minimal as possible to unblock extension development. We can revisit to migrate to this new service soon after the blocked extension PRs have been merged.References
Checklist
Note
Medium Risk
Changes geo-blocking eligibility timing by gating
refreshEligibility()behind a new deferral flag and adding a new public start hook; mistakes could leave users incorrectly marked ineligible/eligible until monitoring starts.Overview
Adds an opt-in
deferEligibilityCheckconstructor option to prevent geo-blocking eligibility checks (and the associated geolocation fetch) from running duringPerpsControllerconstruction.Introduces
startEligibilityMonitoring()(exposed via messenger) to re-enable eligibility processing post-onboarding by reading currentRemoteFeatureFlagControllerstate and triggering the initial eligibility evaluation;refreshEligibility()now no-ops while deferred.Adds unit tests covering the deferral behavior, the new start method, and the default non-deferred path.
Written by Cursor Bugbot for commit 3304a44. This will update automatically on new commits. Configure here.