fix(perps): pass position in TP/SL onConfirm to avoid No position found errors#27409
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. |
gambinish
left a comment
There was a problem hiding this comment.
Approving, but if you have time, could we increase test coverage here?
Automated Review — PR #27409
SummaryThe PR fixes an intermittent "No position found" error when confirming TP/SL on an existing position. The root cause was that the The fix passes the position from The fix achieves its stated goal. Live validation on device confirmed TP/SL can be set from the market details flow with no "No position found" errors. Full review detailsAcceptance Criteria Validation
Code Quality
Live Validation
Correctness
Static Analysis
Architecture & DomainThe approach (pass position via nav params rather than relying on a ref) is the correct pattern for React Navigation flows. Refs are for in-component state across re-renders; cross-screen data should flow via navigation params. This PR aligns the pattern with React Navigation best practices. The signature Risk Assessment
Recommended ActionAPPROVE The fix is correct, minimal, and well-tested. The one suggestion worth raising is the silent-dismissal edge case (anti-pattern finding #1) — consider showing an error toast when Line comments (2 comments: 1 suggestion, 1 nitpick)
const result = await onConfirm(position, parseTakeProfitPrice, parseStopLossPrice, trackingData);
if (result && !result.success) {
// show error toast here instead of navigating back
return;
}
navigation.goBack();This makes failures explicit to the user rather than silently closing the sheet.
Recipe (15 steps defined){
"title": "PR #27409 — TP/SL onConfirm receives position from route params (no stale-ref error)",
"pre_conditions": [
"User has at least one open Perps position (BTC)",
"Metro is running on PR branch fix/perps/tpsl-update-v2",
"App is authenticated and on Wallet screen"
],
"validate": {
"runtime": {
"steps": [
{
"id": "check-positions",
"action": "recipe_ref",
"ref": "positions",
"assert": {
"operator": "not_null",
"field": "0"
}
},
{
"id": "nav-market-details",
"action": "navigate",
"target": "PerpsMarketDetails",
"params": {
"market": {
"symbol": "BTC",
"name": "BTC",
"price": "0",
"change24h": "0",
"change24hPercent": "0",
"volume": "0",
"maxLeverage": "100"
},
"initialTab": "position"
}
},
{
"id": "wait-market-details-load",
"action": "wait",
"ms": 2000
},
{
"id": "screenshot-market-details",
"action": "screenshot",
"filename": "evidence/01-market-details.png"
},
{
"id": "press-auto-close-toggle",
"action": "press",
"test_id": "position-card-auto-close-toggle"
},
{
"id": "wait-tpsl-view-load",
"action": "wait",
"ms": 2000
},
{
"id": "screenshot-tpsl-view",
"action": "screenshot",
"filename": "evidence/02-tpsl-view.png"
},
{
"id": "press-tp-10pct",
"action": "press",
"test_id": "perps-tpsl-take-profit-percentage-button-10"
},
{
"id": "wait-tp-calculated",
"action": "wait",
"ms": 1000
},
{
"id": "screenshot-tpsl-with-tp",
"action": "screenshot",
"filename": "evidence/03-tpsl-tp-set.png"
},
{
"id": "watch-logs-before-confirm",
"action": "log_watch",
"window_seconds": 5,
"must_not_appear": ["No position found", "no position found"]
},
{
"id": "press-set-button",
"action": "press",
"test_id": "perps-tpsl-bottomsheet"
},
{
"id": "wait-confirm",
"action": "wait",
"ms": 3000
},
{
"id": "watch-logs-after-confirm",
"action": "log_watch",
"window_seconds": 5,
"must_not_appear": ["No position found", "no position found"]
},
{
"id": "screenshot-final",
"action": "screenshot",
"filename": "evidence/04-after-confirm.png"
}
]
}
}
} |
abretonc7s
left a comment
There was a problem hiding this comment.
Review: PR #27409 — fix(perps): pass position in TP/SL onConfirm
Tier: standard | Tests: all pass | TSC: clean | Device: validated on iOS sim
Sound, minimal fix for the stale-ref race. All three PerpsTPSL callers updated correctly. 2 suggestions (test the primary fix path, check onConfirm result before goBack), 1 nitpick.
…ute test Add missing _trackingData param to PerpsOrderView's onConfirm callback to match the full TPSLTrackingData type signature used elsewhere. Fix PerpsMarketDetailsView test mock (updateTPSL → handleUpdateTPSL) and add dedicated mock for the direct usePerpsTPSLUpdate import path. Add test verifying handleUpdateTPSL is called with positionFromRoute when currentPositionRef is stale.
…onFromRoute test" This reverts commit 85eee9c.
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Tag selection rationale:
The risk is medium because while the changes are contained to Perps, the callback signature change touches multiple components and fixes a race condition that could affect position management reliability. Performance Test Selection: |
|
✅ E2E Fixture Validation — Schema is up to date |
|



Description
When editing Take Profit / Stop Loss (TP/SL) for an existing Perps position, the
onConfirmcallback relied on a ref (currentPositionRef.current) to get the position at execution time. If the position was updated during navigation (e.g. via WebSocket), the ref could be stale, causing "No position found" errors when the user confirmed TP/SL.This change extends the TP/SL
onConfirmsignature to accept an optional first argumentposition. The TPSL view now passes the position from route params intoonConfirm, and the market-details flow uses that passed position when present, falling back to the ref. Order flow and market-tabs callbacks were updated to match the new signature (they ignore the position argument). This ensures the callback always receives the correct position and avoids the stale-ref error.Changelog
CHANGELOG entry: null
Related issues
Fixes: https://consensyssoftware.atlassian.net/browse/TAT-2369
Manual testing steps
Screenshots/Recordings
N/A (behavioral fix; no UI change).
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Changes the
PerpsTPSLrouteonConfirmcallback signature/return type and updates multiple callers, so mismatches could break TP/SL confirmation flows if any usage is missed.Overview
Fixes a TP/SL confirmation race by passing the
positionfromPerpsTPSLViewinto the routeonConfirmcallback, and havingPerpsMarketDetailsViewprefer that position (falling back tocurrentPositionRef) before callinghandleUpdateTPSL.Updates the
PerpsTPSLnavigation type and all known callers (PerpsOrderView,PerpsMarketTabs) to match the new(position?, tp?, sl?, trackingData?)signature, adjusts TPSL view tests accordingly, and adds a market-details test asserting{ success: false }when confirm runs after the position is cleared.Written by Cursor Bugbot for commit ee47f9c. This will update automatically on new commits. Configure here.