Skip to content

Commit e36d829

Browse files
chore(runway): cherry-pick fix(perps): geo-restrictions on ui (#25392)
- fix(perps): geo-restrictions on ui cp-7.63.0 (#25379) ## **Description** This PR fixes the missing geo-restriction checks in several perpetuals trading flows as reported in #25374. **PerpsOrderBookView.tsx:** - Added geo-restriction check to `handleLongPress` - shows geo-block modal instead of navigating to long order - Added geo-restriction check to `handleShortPress` - shows geo-block modal instead of navigating to short order - Added geo-restriction check to `handleClosePosition` - shows geo-block modal instead of navigating to close position - Added geo-restriction check to `handleModifyPress` - shows geo-block modal instead of opening modify sheet **PerpsMarketDetailsView.tsx:** - Added geo-restriction check to `handleAutoClosePress` - shows geo-block modal instead of navigating to TP/SL screen - Added geo-restriction check to `handleMarginPress` - shows geo-block modal instead of opening adjust margin sheet - Added geo-restriction check to `handleAddMarginFromBanner` - shows geo-block modal instead of navigating to add margin - Added geo-restriction check to `handleSetStopLossFromBanner` - shows geo-block modal instead of setting stop loss **PerpsTabView.tsx:** - Added geo-restriction check to `handleCloseAllPress` - shows geo-block modal instead of navigating to close all positions modal **PerpsHomeView.tsx:** - Added geo-restriction check to `handleCloseAllPress` - shows geo-block modal instead of opening close all positions sheet **eventNames.ts:** - Added new analytics source values for tracking geo-block notifications from each flow **Note:** Cancel all orders is intentionally NOT geo-blocked - users should be able to cancel their existing orders similar to withdrawals. ## **Changelog** CHANGELOG entry: Fixed geo-restriction enforcement for perpetuals trading flows including order book actions, position management, stop-loss prompts, and close all positions ## **Related issues** Fixes: #25374 ## **Manual testing steps** ```gherkin Feature: Geo-restriction on perps trading flows Scenario: User in geo-blocked region cannot trade via order book Given user is in a geo-blocked region (e.g., US) And user has navigated to the perps order book screen When user taps on Long button Then geo-restriction modal should appear And user should not navigate to long order screen When user taps on Short button Then geo-restriction modal should appear And user should not navigate to short order screen When user taps on Close button (with existing position) Then geo-restriction modal should appear And user should not navigate to close position screen When user taps on Modify button (with existing position) Then geo-restriction modal should appear And modify sheet should not open Scenario: User in geo-blocked region cannot manage positions Given user is in a geo-blocked region (e.g., US) And user has an existing perpetuals position When user taps on Auto-close button on position card Then geo-restriction modal should appear And user should not navigate to TP/SL screen When user taps on Margin button on position card Then geo-restriction modal should appear And adjust margin sheet should not open Scenario: User in geo-blocked region cannot use stop-loss prompt actions Given user is in a geo-blocked region (e.g., US) And user has an existing position with stop-loss prompt visible When user taps on Add Margin from stop-loss prompt banner Then geo-restriction modal should appear And user should not navigate to add margin screen When user taps on Set Stop Loss from stop-loss prompt banner Then geo-restriction modal should appear And stop loss should not be set Scenario: User in geo-blocked region cannot close all positions Given user is in a geo-blocked region (e.g., US) And user has existing perpetuals positions When user taps on Close All button in perps tab Then geo-restriction modal should appear And close all positions modal should not open When user taps on Close All button in perps home Then geo-restriction modal should appear And close all positions sheet should not open Scenario: User in geo-blocked region CAN cancel all orders Given user is in a geo-blocked region (e.g., US) And user has existing perpetuals orders When user taps on Cancel All button Then cancel all orders modal should open (NOT geo-blocked) ``` ## **Screenshots/Recordings** ### **Before** Users in geo-blocked regions could access trading flows without restriction ### **After** Geo-restriction modal appears for all trading flows when user is not eligible ## **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)). 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] > **Medium Risk** > Adds eligibility gating to multiple trading and position-management UI actions; mistakes could wrongly block eligible users or allow restricted actions through. Changes are localized to UI handlers and analytics but touch critical perps flows. > > **Overview** > **Enforces geo-restrictions across key Perps UI actions.** Order book Long/Short/Close/Modify, market details auto-close (TP/SL), adjust margin, stop-loss prompt actions, and bulk close-all entry points now check `selectPerpsEligibility` and show the geo-block tooltip instead of navigating/opening sheets. > > **Adds analytics attribution for blocked actions.** New `PerpsEventValues.SOURCE` constants are introduced to distinguish which UI trigger surfaced the geo-block notification. > > **Updates tests to cover new gating behavior.** Mocks are extended and new cases added to assert geo-block modal display and that navigation/sheets are not triggered when ineligible. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 1698d05. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> [d87e9ea](d87e9ea) Co-authored-by: Alejandro Garcia Anglada <aganglada@gmail.com>
1 parent 87d2dae commit e36d829

8 files changed

Lines changed: 671 additions & 13 deletions

File tree

app/components/UI/Perps/Views/PerpsHomeView/PerpsHomeView.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ jest.mock('../../hooks/usePerpsHomeActions', () => ({
9595
}));
9696

9797
jest.mock('../../hooks/usePerpsEventTracking', () => ({
98-
usePerpsEventTracking: jest.fn(),
98+
usePerpsEventTracking: jest.fn(() => ({
99+
track: jest.fn(),
100+
})),
99101
}));
100102

101103
jest.mock('../../hooks/stream', () => ({

app/components/UI/Perps/Views/PerpsHomeView/PerpsHomeView.tsx

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,18 @@ const PerpsHomeView = () => {
9898
const {
9999
handleAddFunds,
100100
handleWithdraw,
101+
isEligible,
101102
isEligibilityModalVisible,
102103
closeEligibilityModal,
103104
} = usePerpsHomeActions({
104105
buttonLocation: PerpsEventValues.BUTTON_LOCATION.PERPS_HOME,
105106
});
106107

108+
// Separate geo-block modal state for close all / cancel all actions
109+
const [isCloseAllGeoBlockVisible, setIsCloseAllGeoBlockVisible] =
110+
useState(false);
111+
const { track } = usePerpsEventTracking();
112+
107113
// Section scroll tracking for analytics
108114
const { handleSectionLayout, handleScroll, resetTracking } =
109115
usePerpsHomeSectionTracking();
@@ -340,10 +346,21 @@ const PerpsHomeView = () => {
340346
handleGiveFeedback,
341347
]);
342348

343-
// Bottom sheet handlers - open sheets directly
349+
// Bottom sheet handlers - open sheets directly with geo-restriction check
344350
const handleCloseAllPress = useCallback(() => {
351+
// Geo-restriction check for close all positions
352+
if (!isEligible) {
353+
track(MetaMetricsEvents.PERPS_SCREEN_VIEWED, {
354+
[PerpsEventProperties.SCREEN_TYPE]:
355+
PerpsEventValues.SCREEN_TYPE.GEO_BLOCK_NOTIF,
356+
[PerpsEventProperties.SOURCE]:
357+
PerpsEventValues.SOURCE.CLOSE_ALL_POSITIONS_BUTTON,
358+
});
359+
setIsCloseAllGeoBlockVisible(true);
360+
return;
361+
}
345362
setShowCloseAllSheet(true);
346-
}, []);
363+
}, [isEligible, track]);
347364

348365
const handleCancelAllPress = useCallback(() => {
349366
setShowCancelAllSheet(true);
@@ -576,6 +593,20 @@ const PerpsHomeView = () => {
576593
</Modal>
577594
</View>
578595
)}
596+
597+
{/* Close All / Cancel All Geo-Block Modal */}
598+
{isCloseAllGeoBlockVisible && (
599+
<View>
600+
<Modal visible transparent animationType="none" statusBarTranslucent>
601+
<PerpsBottomSheetTooltip
602+
isVisible
603+
onClose={() => setIsCloseAllGeoBlockVisible(false)}
604+
contentKey={'geo_block'}
605+
testID={'perps-home-close-all-geo-block-tooltip'}
606+
/>
607+
</Modal>
608+
</View>
609+
)}
579610
</SafeAreaView>
580611
);
581612
};

0 commit comments

Comments
 (0)