-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(perps): new TPSL view design #21396
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
base: main
Are you sure you want to change the base?
Conversation
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. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## fix/perps/modalbottomsheetrefactor #21396 +/- ##
=====================================================================
Coverage ? 77.10%
=====================================================================
Files ? 3615
Lines ? 89150
Branches ? 16868
=====================================================================
Hits ? 68741
Misses ? 15719
Partials ? 4690 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
https://github.com/MetaMask/metamask-mobile/pull/21344/files/f8316a369689a965e0d489a0ee07d52290cc0603#r2446141415 Ideally could be addressed in this PR if there will be some changes @abretonc7s |
Thansk @nickewansmith adding it with the design tweaks |
|
Description
This PR implements TAT-1729, adding expected profit/loss calculation display to the Auto Close (TP/SL) configuration screen. It also includes several UX improvements based on design refinements.
What is the reason for the change?
Users need to see the expected net profit or loss when setting TP/SL values, accounting for trading fees. This helps them make informed decisions about their risk management strategy. Additionally, several UX improvements were needed to match the final design specifications.
What is the improvement/solution?
Expected P&L Display: Shows real-time expected profit/loss below TP and SL input fields
formatPerpsFiat
with PRICE_RANGES_MINIMAL_VIEWTerminology Update: Renamed "TP/SL" to "Auto close" throughout the UI
UX Improvements:
Implementation Approach (DRY):
calculatePnL()
utility frompnlCalculations.ts
usePerpsOrderFees()
hook for accurate fee calculationcalculatePositionSize()
for new orderscalculateExpectedPnL()
wrapper that combines P&L with fee deductionusePerpsTPSLForm
hook return values (no new hooks created)formatPerpsFiat
)Changelog
CHANGELOG entry: Added expected profit/loss display to Auto Close (TP/SL) configuration showing net profit after fees, improved UI layout and terminology
Related issues
Manual testing steps
Screenshots/Recordings
Before
After
Screen.Recording.2025-10-18.at.7.43.52.PM.mov
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Adds expected net PnL (after fees) to the Auto close screen, revamps its UI/strings, plumbs amount/decimals, and extends TPSL logic, utils, and tests.
PerpsTPSLView.tsx
,.styles.ts
): centered header with absolute back button; right-aligned "Clear" actions; "$" label on left of inputs; condensed price info; auto-scroll on input focus; footer shows "Cancel/Set" (keypad off) or "Done" (keypad on); removes explainer text; percentage buttons no longer stay selected.perps.tpsl.expected_profit|expected_loss
under TP/SL, formatted withPRICE_RANGES_MINIMAL_VIEW
, with fallbacks fromPERPS_CONSTANTS
.PerpsOrderView.tsx
): passesamount
andszDecimals
to TPSL route; minor label/state refactors.usePerpsTPSLForm
: acceptsamount
/szDecimals
; computesexpectedTakeProfitPnL
/expectedStopLossPnL
using size fromcalculatePositionSize
and fees fromusePerpsOrderFees
; refines direction/entry-price logic; returns new display fields.usePerpsTPSLUpdate
: simplifies error callback message.PerpsNavigationParamList['PerpsTPSL']
withamount
andszDecimals
.pnlCalculations.ts
: addscalculateExpectedPnL
.tpslValidation.ts
: guards whendirection
missing; minor regex/sign handling.en.json
):cancel
,set
,clear
, and expected PnL strings; updates USD label to$
.PerpsTPSLView.test.tsx
andusePerpsTPSLForm.test.ts
for new UI, formatting, Redux wrapper, keypad/labels, and expected behaviors.Written by Cursor Bugbot for commit c9678b8. This will update automatically on new commits. Configure here.