[pull] main from MetaMask:main#328
Merged
Merged
Conversation
…22716) ## **Description** This PR fixes TAT-1564 by moving the cross-margin position validation from the order screen to the market details screen. **Background:** The initial implementation showed the cross-margin warning modal *after* users had already navigated to the order screen and entered their trade details. This created a poor user experience where users would: 1. Tap Long/Short on the market details screen 2. Navigate to the order screen 3. Enter trade amount, leverage, and other details 4. Tap "Place Order" 5. Finally see the cross-margin warning modal **Solution:** This fix moves the validation to occur *before* navigation to the order screen: 1. User taps Long/Short on the market details screen 2. Cross-margin validation runs immediately 3. If cross-margin position detected, modal shows and prevents navigation 4. User sees the warning before entering any trade details The implementation: - Added `handleTradeAction(direction)` shared function in `PerpsMarketDetailsView.tsx` that validates both eligibility and cross-margin before navigation - Removed duplicate cross-margin check from `PerpsOrderView.tsx` - Reuses existing infrastructure: `existingPosition` hook data, modal navigation, error tracking ## **Changelog** CHANGELOG entry: Fixed cross-margin position warning to show before entering trade details instead of after ## **Related issues** Fixes: https://consensyssoftware.atlassian.net/browse/TAT-1564 ## **Manual testing steps** ```gherkin Feature: Cross-margin position warning Scenario: user with cross-margin position attempts to open new trade Given user is on the Perps market details screen And user has an existing cross-margin position for this asset When user taps the "Long" or "Short" button Then cross-margin warning modal should appear immediately And user should remain on the market details screen (navigation blocked) Scenario: user with isolated-margin position opens new trade Given user is on the Perps market details screen And user has an existing isolated-margin position for this asset When user taps the "Long" or "Short" button Then user should navigate to the order screen normally And no warning modal should appear Scenario: user with no existing position opens new trade Given user is on the Perps market details screen And user has no existing position for this asset When user taps the "Long" or "Short" button Then user should navigate to the order screen normally And no warning modal should appear ``` ## **Screenshots/Recordings** ### **Before** Cross-margin warning appeared after user entered trade details in order screen (incorrect timing) ### **After** Cross-margin warning appears immediately when tapping Long/Short button, preventing navigation to order screen (correct timing) https://github.com/user-attachments/assets/c1d9c4ef-5fec-4add-946e-f136dcb3d478 ## **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] > Centralizes long/short handling with pre-navigation cross-margin validation and warning modal in `PerpsMarketDetailsView`. > > - **Perps UI** > - **`PerpsMarketDetailsView.tsx`**: > - Introduces `handleTradeAction(direction)` to unify Long/Short button logic. > - Adds pre-navigation checks: eligibility gate and cross-margin detection using `existingPosition.leverage.type === 'cross'`. > - On cross-margin, navigates to `CROSS_MARGIN_WARNING` modal and tracks a validation error; otherwise calls `navigateToOrder`. > - Updates `handleLongPress`/`handleShortPress` to delegate to `handleTradeAction`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit c3db7e8. 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )