Skip to content

fix(perps): enforce geo-block and compliance gate on Market Insights Long/Short actions cp-7.72.1#28678

Merged
aganglada merged 7 commits into
mainfrom
fix/perps-market-insights-geo-block
Apr 10, 2026
Merged

fix(perps): enforce geo-block and compliance gate on Market Insights Long/Short actions cp-7.72.1#28678
aganglada merged 7 commits into
mainfrom
fix/perps-market-insights-geo-block

Conversation

@michalconsensys

@michalconsensys michalconsensys commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Description

The MarketInsightsView (AI summaries page) Long/Short buttons navigated directly to PerpsOrderRedirect without checking geo-eligibility or running the compliance gate. This allowed users in restricted regions to bypass restrictions and open perps positions from the Market Insights entry point, even though every other entry point (Market Details, Order Book, Token Details) correctly blocked them.

Changes:

  • Wrapped handlePerpsDirectionPress in the compliance gate() and added the isEligible geo-check before navigation, matching the pattern in PerpsMarketDetailsView and AssetOverviewContent
  • Renders the PerpsBottomSheetTooltip geo-block modal ("Perps unavailable in your region") when the user is ineligible
  • Added MARKET_INSIGHTS to PERPS_EVENT_VALUE.SOURCE for proper geo-block analytics attribution
  • Updated existing tests and added a new test case for the ineligible scenario

Changelog

CHANGELOG entry: Fixed a bug where users in restricted regions could open perps positions from the Market Insights page

Related issues

Fixes:

Manual testing steps

Feature: Perps geo-block enforcement on Market Insights

  Scenario: Restricted user taps Long on Market Insights
    Given the user is in a geo-restricted region
    And the user navigates to Market Insights for a perps asset (e.g. ETH)

    When the user taps the "Long" button
    Then the "Perps unavailable in your region" modal is shown
    And the user is NOT navigated to the order screen

  Scenario: Restricted user taps Short on Market Insights
    Given the user is in a geo-restricted region
    And the user navigates to Market Insights for a perps asset

    When the user taps the "Short" button
    Then the "Perps unavailable in your region" modal is shown
    And the user is NOT navigated to the order screen

  Scenario: Eligible user taps Long on Market Insights
    Given the user is NOT in a geo-restricted region
    And the user navigates to Market Insights for a perps asset

    When the user taps the "Long" button
    Then the user is navigated to the order screen as expected

Screenshots/Recordings

N/A — behavior matches existing geo-block modal shown on other Perps entry points.

Before

Tapping Long/Short on Market Insights in a restricted region navigated to the order screen (bypassing restrictions).

After

Simulator Screenshot - iPhone 17 Pro Max - 2026-04-10 at 17 46 41

Tapping Long/Short on Market Insights in a restricted region shows the geo-block modal and blocks navigation.

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 Perps eligibility/compliance gating and navigation from MarketInsightsView, so mistakes could reintroduce a restriction bypass or block eligible users; changes are localized and covered by updated tests.

Overview
Prevents the Market Insights Perps Long/Short CTAs from navigating directly to order flow without restrictions by wrapping the action in the compliance gate() and checking selectPerpsEligibility first.

When ineligible, it now tracks a geo-block screen view with source PERPS_EVENT_VALUE.SOURCE.MARKET_INSIGHTS and shows the PerpsBottomSheetTooltip in a modal instead of navigating. Tests were updated to handle async gated presses and a new test asserts the ineligible geo-block behavior; the Perps view test renderer also ensures extra routes get the same Perps providers.

Reviewed by Cursor Bugbot for commit 8ed8908. Bugbot is set up for automated code reviews on this repo. Configure here.

…erps actions

The MarketInsightsView Long/Short buttons navigated directly to
PerpsOrderRedirect without checking geo-eligibility or running
the compliance gate, allowing restricted users to open positions.
Adds the same guards used by PerpsMarketDetailsView and
AssetOverviewContent so the geo-block modal is shown for
ineligible users.
@michalconsensys michalconsensys self-assigned this Apr 10, 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-perps Perps team label Apr 10, 2026
@michalconsensys michalconsensys marked this pull request as ready for review April 10, 2026 15:51
@michalconsensys michalconsensys requested a review from a team as a code owner April 10, 2026 15:51
contentKey="geo_block"
testID="market-insights-geo-block-tooltip"
/>
</Modal>

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.

Extra Modal wrapper inconsistent with reference pattern

Medium Severity

The PerpsBottomSheetTooltip is wrapped in a React Native Modal here, but the reference implementation in PerpsMarketDetailsView (line ~1574) renders PerpsBottomSheetTooltip directly without a Modal wrapper. Since PerpsBottomSheetTooltip likely already provides its own modal/bottom-sheet overlay internally, the extra Modal wrapper can cause double backdrops, z-index conflicts, or touch-event interception issues that break the dismiss behavior.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f9a9f99. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Some seem to be using modal and some not, this is likely just due to the animation

@michalconsensys michalconsensys changed the title fix(perps): enforce geo-block and compliance gate on Market Insights Long/Short actions fix(perps): enforce geo-block and compliance gate on Market Insights Long/Short actions cp-7.72.1 Apr 10, 2026
@michalconsensys

Copy link
Copy Markdown
Contributor Author

@metamaskbot update-mobile-fixture

@github-actions github-actions Bot added the risk-medium Moderate testing recommended · Possible bug introduction risk label Apr 10, 2026
javiergarciavera and others added 2 commits April 10, 2026 18:43
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
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?
-->

## **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:

## **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]
> **Low Risk**
> Low risk test-only change that adjusts component-view rendering
behavior; main risk is breaking navigation assertions if provider
wrapping alters route props or stack behavior.
> 
> **Overview**
> Updates `renderPerpsView` test renderer so **all `extraRoutes`
screens** (both root stack and `Routes.PERPS.ROOT` nested stack) are
wrapped with the same Perps providers (`AccessRestrictedProvider`,
`PerpsConnectionContext`, `PerpsStreamProvider`) as the primary view.
This ensures extra routes can render real Perps views (not just probes)
without missing-context errors during component-view tests.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
b3dae39. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
joaosantos15
joaosantos15 previously approved these changes Apr 10, 2026
aganglada
aganglada previously approved these changes Apr 10, 2026
@aganglada aganglada enabled auto-merge April 10, 2026 16:50
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 10, 2026
isVisible
onClose={closeEligibilityModal}
contentKey="geo_block"
testID="market-insights-geo-block-tooltip"

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.

Geo-block testID missing from selectors enum, uses raw string

Low Severity

The new testID="market-insights-geo-block-tooltip" is hardcoded as a raw string in the component and queried with raw strings in the test (queryByTestId('market-insights-geo-block-tooltip'), getByTestId('market-insights-geo-block-tooltip')). Every other testID in this component references the MarketInsightsSelectorsIDs enum from MarketInsights.testIds.ts. This new testID needs to be added to that enum and referenced via the constant, consistent with the rest of the file. Violates the unit testing guideline to prefer testID constants over hardcoded strings.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: Unit Testing Guidelines

Reviewed by Cursor Bugbot for commit 40d8e04. Configure here.

@aganglada aganglada dismissed stale reviews from joaosantos15 and themself via fac7ff6 April 10, 2026 17:10
aganglada
aganglada previously approved these changes Apr 10, 2026
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 10, 2026

@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 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

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.

Reviewed by Cursor Bugbot for commit fac7ff6. Configure here.

Comment thread app/components/UI/MarketInsights/Views/MarketInsightsView/MarketInsightsView.tsx Outdated
geositta
geositta previously approved these changes Apr 10, 2026
@aganglada aganglada disabled auto-merge April 10, 2026 17:23
…Mask/metamask-mobile into fix/perps-market-insights-geo-block
@gambinish gambinish dismissed stale reviews from geositta and aganglada via 8ed8908 April 10, 2026 17:35
@github-actions github-actions Bot added risk-medium Moderate testing recommended · Possible bug introduction risk and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Apr 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokePerps, SmokeWalletPlatform, SmokeConfirmations
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 85%
click to see 🤖 AI reasoning details

E2E Test Selection:
The PR introduces a geo-block/eligibility check in MarketInsightsView for Perps direction buttons (Long/Short). Key changes:

  1. MarketInsightsView.tsx: Adds compliance gate (useComplianceGate) and perps eligibility check (selectPerpsEligibility). When a user is not eligible (geo-blocked), a PerpsBottomSheetTooltip modal is shown instead of navigating to the Perps order screen. This directly affects the Perps flow from MarketInsights.

  2. perpsViewRenderer.tsx: Test infrastructure improvement - wraps extra routes with Perps providers (AccessRestrictedProvider, PerpsConnectionContext, PerpsStreamProvider) to ensure provider parity. This affects all Perps view tests that use renderPerpsView with extraRoutes.

  3. eventNames.ts: Adds MARKET_INSIGHTS source constant for analytics tracking in geo-block scenarios.

Tag Selection Rationale:

  • SmokePerps: Primary tag - changes directly affect Perps functionality (geo-block modal, eligibility check, navigation from MarketInsights to Perps order screen). The perpsViewRenderer change also affects Perps test infrastructure.
  • SmokeWalletPlatform: Required per SmokePerps description - Perps is a section inside the Trending tab, and changes to Perps views affect Trending.
  • SmokeConfirmations: Required per SmokePerps description - Add Funds deposits are on-chain transactions requiring confirmations.

The changes are scoped to Perps/MarketInsights interaction with no impact on accounts, networks, swaps, or other unrelated areas.

Performance Test Selection:
The changes add a geo-block modal and eligibility check to MarketInsightsView, and improve test provider wrapping in perpsViewRenderer. These are logic/UI changes (modal display, compliance gate) that don't impact rendering performance, list loading, data fetching performance, or app startup. No performance-sensitive code paths are modified.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

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

@aganglada aganglada enabled auto-merge April 10, 2026 17:59
@aganglada aganglada added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit 90f34c6 Apr 10, 2026
103 checks passed
@aganglada aganglada deleted the fix/perps-market-insights-geo-block branch April 10, 2026 18:22
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 10, 2026
@metamaskbot metamaskbot added the release-7.74.0 Issue or pull request that will be included in release 7.74.0 label Apr 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.74.0 Issue or pull request that will be included in release 7.74.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-M team-perps Perps team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants