Skip to content

feat(perps): add deferEligibilityCheck option to PerpsController#27483

Merged
abretonc7s merged 13 commits into
mainfrom
feat/defer-eligibility-check
Mar 19, 2026
Merged

feat(perps): add deferEligibilityCheck option to PerpsController#27483
abretonc7s merged 13 commits into
mainfrom
feat/defer-eligibility-check

Conversation

@abretonc7s

@abretonc7s abretonc7s commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

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

Manual testing steps

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

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.

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.

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

Port from Core PR #8197. Adds a constructor option to prevent the eager
geolocation fetch during wallet onboarding (privacy compliance) and a
startEligibilityMonitoring() method to resume checks post-onboarding.
@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.

@abretonc7s abretonc7s marked this pull request as ready for review March 16, 2026 13:15
@abretonc7s abretonc7s requested a review from a team as a code owner March 16, 2026 13:15
Comment thread app/controllers/perps/PerpsController.ts
@github-actions github-actions Bot added size-M and removed size-S labels Mar 16, 2026
Comment thread app/controllers/perps/PerpsController.test.ts

@cursor cursor Bot left a comment

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.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

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.

Comment thread app/controllers/perps/PerpsController.ts Outdated
Comment thread app/controllers/perps/PerpsController.test.ts Outdated

@gambinish gambinish left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It seems like we are including a few changes that are outside of the scope of the deferEligibilityCheck feature

Can we create a separate PR that scopes the diff to only that change? The breadcrumb and sentry fixes seem out of scope to me, and should likely be introduced as a separate PR.

@abretonc7s

Copy link
Copy Markdown
Contributor Author

It seems like we are including a few changes that are outside of the scope of the deferEligibilityCheck feature

Can we create a separate PR that scopes the diff to only that change? The breadcrumb and sentry fixes seem out of scope to me, and should likely be introduced as a separate PR.

Those were necessary to unblock the sync and were included to force the sync but yes otherwise they need to be separate. Fixing it now since we dont need have urgency anymore.

…igibilityCheck

Moved breadcrumb abstraction, external dependency removal, and linting
fixes to a separate PR (fix/perps-core-sync-improvements).
@github-actions github-actions Bot added the risk-high Extensive testing required · High bug introduction risk label Mar 18, 2026
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Mar 18, 2026
Comment thread app/controllers/perps/PerpsController.ts
@abretonc7s abretonc7s enabled auto-merge March 18, 2026 14:03
@github-actions github-actions Bot added risk-high Extensive testing required · High bug introduction risk and removed risk-high Extensive testing required · High bug introduction risk labels Mar 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: @PerformancePreps
  • Risk Level: high
  • AI Confidence: 70%
click to see 🤖 AI reasoning details

E2E Test Selection:
Changes are in PerpsController and its associated method action types and unit tests. PerpsController is a core controller under app/controllers and directly powers the Perps (perpetuals trading) feature, including Add Funds deposits, balance updates, and market interactions. Controller-level changes can affect on-chain deposit flows, state management, and UI data binding for Perps screens.

SmokePerps must be selected to validate add funds, balance updates, and trading account behavior. Per the tag requirements, SmokePerps also requires SmokeWalletPlatform (Perps section is embedded in Trending and affects wallet activity/history) and SmokeConfirmations (Add Funds deposits are on-chain transactions that go through the confirmation UI).

No evidence of changes to other controllers (Accounts, Network, Identity, MultiChain, Snaps, etc.), so broader tags are not required.

Given this is a controller change in a financial feature with on-chain effects, risk is high within the Perps domain.

Performance Test Selection:
Controller changes may affect perps market loading, balance updates, and Add Funds execution performance. Since PerpsController orchestrates data fetching and state updates for the perps feature, performance characteristics (market load time, deposit flow responsiveness) could be impacted. Running @PerformancePreps ensures no regressions in perps trading performance.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@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

@abretonc7s abretonc7s added this pull request to the merge queue Mar 19, 2026
Merged via the queue into main with commit bb507cc Mar 19, 2026
109 of 110 checks passed
@abretonc7s abretonc7s deleted the feat/defer-eligibility-check branch March 19, 2026 16:27
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 19, 2026
@metamaskbot metamaskbot added the release-7.71.0 Issue or pull request that will be included in release 7.71.0 label Mar 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.71.0 Issue or pull request that will be included in release 7.71.0 risk-high Extensive testing required · High bug introduction risk size-M team-perps Perps team type-feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants