-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chore(runway): cherry-pick fix(perps): correct Stop Loss banner ROE threshold to -10% and skip debounce for old orders cp-7.61.0 #23713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(runway): cherry-pick fix(perps): correct Stop Loss banner ROE threshold to -10% and skip debounce for old orders cp-7.61.0 #23713
Conversation
…hreshold to -10% and skip debounce for old orders cp-7.61.0 (#23427) ## **Description** This PR fixes a bug where the Stop Loss banner was not displaying at the correct Return on Equity (ROE) threshold, and adds an enhancement to bypass the debounce delay for established positions. ## **Changelog** CHANGELOG entry: Fixed Stop Loss banner to display at -10% ROE instead of -20% ROE and skip debounce for old orders ## **Related issues** Jira issue: https://consensyssoftware.atlassian.net/browse/TAT-2163 Fixes #23473 ## **Manual testing steps** ```gherkin Feature: Stop Loss Banner Display Scenario: user has position with -10% ROE Given user has an open Perps position And position ROE is between -10% and -20% And liquidation distance is greater than 3% And position has no existing stop loss set And ROE has been below -10% for at least 60 seconds When user views the position details Then Stop Loss prompt banner should be displayed And banner should suggest setting a stop loss ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** N/A <!-- [screenshots/recordings] --> ### **After** N/A <!-- [screenshots/recordings] --> ## **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] > Stop-loss prompt now triggers at -10% ROE and skips debounce for positions >2 minutes old using order fills; integrated into market details view with updated tests. > > - **Perps Stop-Loss Prompt Logic**: > - Update `STOP_LOSS_PROMPT_CONFIG.ROE_THRESHOLD` to `-10` in `constants/perpsConfig.ts`. > - Enhance `useStopLossPrompt`: > - Add `positionOpenedTimestamp` param and bypass 60s debounce when ROE below threshold and position age ≥ 2 minutes. > - Add `finishDebounce` helper and `hasBeenShownRef` to show once per position lifecycle; reset appropriately. > - **View Integration**: > - In `PerpsMarketDetailsView.tsx`, fetch fills via `usePerpsOrderFills`, compute `positionOpenedTimestamp` from latest matching "Open" fill, and pass to `useStopLossPrompt`. > - **Tests**: > - Extend `useStopLossPrompt.test.ts` for new threshold and debounce-bypass behavior, including edge cases and priority rules. > - In `PerpsMarketDetailsView.test.tsx`, mock `usePerpsOrderFills` and add test verifying position opened timestamp computation. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit cf3a2a9. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
|
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. |
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsAll changes are isolated to the Perps (Perpetuals trading) feature area:
Why Medium Risk: While isolated, this changes user-facing behavior around financial risk management (stop-loss prompts). The threshold change (from -20% to -10% ROE) means users will see warnings earlier, and the debounce bypass means existing positions show warnings faster. This warrants testing the actual perps flow. Why only SmokePerps: The changes don't touch accounts, core wallet, network switching, swaps, or any other feature areas. All modifications are within app/components/UI/Perps/ directory. The SmokePerps tag should cover all perpetuals trading flows including position management and UI interactions. |
|
|
||
| useEffect(() => { | ||
| hasBeenShownRef.current = false; | ||
| }, [position?.coin]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Missing state reset on market change causes premature banner
When switching between markets (position?.coin changes), only hasBeenShownRef is reset while roeDebounceComplete and roeBelowThresholdSinceRef are not. If a user was viewing a market where the debounce completed and the banner was showing, then switches to a different market that also has a position with ROE below threshold, the banner will immediately appear without respecting the debounce logic for the new market. The roeDebounceComplete state from the previous market persists and triggers the banner prematurely.
|
|
No release label on PR. Adding release label release-7.61.0 on PR, as PR was cherry-picked in branch 7.61.0. |



Description
This PR fixes a bug where the Stop Loss banner was not displaying at the
correct Return on Equity (ROE) threshold, and adds an enhancement to
bypass the debounce delay for established positions.
Changelog
CHANGELOG entry: Fixed Stop Loss banner to display at -10% ROE instead
of -20% ROE and skip debounce for old orders
Related issues
Jira issue: https://consensyssoftware.atlassian.net/browse/TAT-2163
Fixes #23473
Manual testing steps
Screenshots/Recordings
Before
N/A
After
N/A
Pre-merge author checklist
Docs and MetaMask Mobile
Coding
Standards.
if applicable
guidelines).
Not required for external contributors.
Pre-merge reviewer checklist
app, test code being changed).
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
Note
Updates stop-loss prompt to trigger at -10% ROE and skip debounce for positions >2 minutes old using order fills; wires view to provide timestamp and adds tests.
STOP_LOSS_PROMPT_CONFIG.ROE_THRESHOLDto-10inconstants/perpsConfig.ts.useStopLossPromptto acceptpositionOpenedTimestamp, bypassing ROE debounce when position age ≥2 minutes and below threshold; minor refactor withfinishDebounceand show-once guard.usePerpsOrderFillsand computepositionOpenedTimestamp(most recent matchingOpenfill) inPerpsMarketDetailsView.tsx.positionOpenedTimestampintouseStopLossPrompt.PerpsMarketDetailsView.test.tsx.useStopLossPrompt.test.tsfor-10%ROE threshold and debounce-bypass scenarios.Written by Cursor Bugbot for commit 9cdf4b7. This will update automatically on new commits. Configure here.
3a558e8