Skip to content

[pull] main from MetaMask:main#328

Merged
pull[bot] merged 1 commit into
Reality2byte:mainfrom
MetaMask:main
Nov 17, 2025
Merged

[pull] main from MetaMask:main#328
pull[bot] merged 1 commit into
Reality2byte:mainfrom
MetaMask:main

Conversation

@pull
Copy link
Copy Markdown

@pull pull Bot commented Nov 17, 2025

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 : )

…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 -->
@pull pull Bot locked and limited conversation to collaborators Nov 17, 2025
@pull pull Bot added the ⤵️ pull label Nov 17, 2025
@pull pull Bot merged commit b01baf8 into Reality2byte:main Nov 17, 2025
4 of 22 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant