-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(perps): validate TP/SL prices, clear stale config, and block invalid orders cp-7.71.0 #27791
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
Changes from 4 commits
8e4e9c9
cb8dade
1bbea67
4778add
28df8a7
bd12aad
c85cf59
c71774d
9131943
7c10dc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| } from '../../../../../component-library/components/Texts/Text'; | ||
| import useTooltipModal from '../../../../../components/hooks/useTooltipModal'; | ||
| import Routes from '../../../../../constants/navigation/Routes'; | ||
| import Engine from '../../../../../core/Engine'; | ||
| import DevLogger from '../../../../../core/SDKConnect/utils/DevLogger'; | ||
| import { useTheme } from '../../../../../util/theme'; | ||
| import { TraceName } from '../../../../../util/trace'; | ||
|
|
@@ -139,6 +140,8 @@ | |
| import { | ||
| calculateRoEForPrice, | ||
| isStopLossSafeFromLiquidation, | ||
| isValidStopLossPrice, | ||
| isValidTakeProfitPrice, | ||
| } from '../../utils/tpslValidation'; | ||
| import createStyles from './PerpsOrderView.styles'; | ||
| import { PerpsPayRow } from './PerpsPayRow'; | ||
|
|
@@ -672,7 +675,11 @@ | |
| ); | ||
| const absRoE = Math.abs(parseFloat(tpRoE || '0')); | ||
| tpDisplay = | ||
| absRoE > 0 ? `${absRoE.toFixed(0)}%` : strings('perps.order.off'); | ||
| absRoE > 0 | ||
| ? `${absRoE.toFixed(0)}%` | ||
| : formatPerpsFiat(orderForm.takeProfitPrice, { | ||
| ranges: PRICE_RANGES_UNIVERSAL, | ||
| }); | ||
| } | ||
|
|
||
| if (orderForm.stopLossPrice && price > 0 && orderForm.leverage) { | ||
|
|
@@ -689,7 +696,11 @@ | |
| ); | ||
| const absRoE = Math.abs(parseFloat(slRoE || '0')); | ||
| slDisplay = | ||
| absRoE > 0 ? `${absRoE.toFixed(0)}%` : strings('perps.order.off'); | ||
| absRoE > 0 | ||
| ? `${absRoE.toFixed(0)}%` | ||
| : formatPerpsFiat(orderForm.stopLossPrice, { | ||
| ranges: PRICE_RANGES_UNIVERSAL, | ||
| }); | ||
| } | ||
|
|
||
| return `${strings('perps.order.tp')} ${tpDisplay}, ${strings( | ||
|
|
@@ -1079,6 +1090,12 @@ | |
| } else { | ||
| await executeOrder(orderParams); | ||
| } | ||
|
|
||
| // Clear pending trade config after successful submission to prevent | ||
| // stale TP/SL values from being restored on the next order form visit | ||
| Engine.context.PerpsController?.clearPendingTradeConfiguration( | ||
| orderForm.asset, | ||
| ); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pending config cleared even when order execution failsMedium Severity
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is intended |
||
| } finally { | ||
| // Always reset submission flag | ||
| isSubmittingRef.current = false; | ||
|
|
@@ -1204,6 +1221,26 @@ | |
| ), | ||
| ); | ||
|
|
||
| const isTakeProfitPriceInvalid = Boolean( | ||
| orderForm.takeProfitPrice?.trim() && | ||
| assetData.price > 0 && | ||
| !isValidTakeProfitPrice(orderForm.takeProfitPrice, { | ||
| currentPrice: assetData.price, | ||
|
michalconsensys marked this conversation as resolved.
Outdated
|
||
| direction: orderForm.direction, | ||
| }), | ||
| ); | ||
|
|
||
| const isStopLossPriceInvalid = Boolean( | ||
| orderForm.stopLossPrice?.trim() && | ||
| assetData.price > 0 && | ||
| !isValidStopLossPrice(orderForm.stopLossPrice, { | ||
| currentPrice: assetData.price, | ||
| direction: orderForm.direction, | ||
| }), | ||
| ); | ||
|
|
||
| const hasInvalidTPSL = isTakeProfitPriceInvalid || isStopLossPriceInvalid; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| let rewardAnimationState = RewardAnimationState.Idle; | ||
| if (rewardsState.isLoading) { | ||
| rewardAnimationState = RewardAnimationState.Loading; | ||
|
|
@@ -1418,9 +1455,33 @@ | |
| ? strings('perps.tpsl.below') | ||
| : strings('perps.tpsl.above'), | ||
| })} | ||
| </Text> | ||
|
Check warning on line 1458 in app/components/UI/Perps/Views/PerpsOrderView/PerpsOrderView.tsx
|
||
| </View> | ||
| )} | ||
| {!hideTPSL && isTakeProfitPriceInvalid && ( | ||
| <View style={styles.stopLossLiquidationWarning}> | ||
| <Text variant={TextVariant.BodySM} color={TextColor.Error}> | ||
|
Check warning on line 1463 in app/components/UI/Perps/Views/PerpsOrderView/PerpsOrderView.tsx
|
||
| {strings('perps.tpsl.take_profit_wrong_side_warning', { | ||
| direction: | ||
| orderForm.direction === 'long' | ||
| ? strings('perps.tpsl.above') | ||
| : strings('perps.tpsl.below'), | ||
| })} | ||
| </Text> | ||
|
Check warning on line 1470 in app/components/UI/Perps/Views/PerpsOrderView/PerpsOrderView.tsx
|
||
| </View> | ||
| )} | ||
| {!hideTPSL && isStopLossPriceInvalid && ( | ||
| <View style={styles.stopLossLiquidationWarning}> | ||
| <Text variant={TextVariant.BodySM} color={TextColor.Error}> | ||
|
Check warning on line 1475 in app/components/UI/Perps/Views/PerpsOrderView/PerpsOrderView.tsx
|
||
| {strings('perps.tpsl.stop_loss_wrong_side_warning', { | ||
| direction: | ||
| orderForm.direction === 'long' | ||
| ? strings('perps.tpsl.below') | ||
| : strings('perps.tpsl.above'), | ||
| })} | ||
| </Text> | ||
| </View> | ||
| )} | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| </View> | ||
| )} | ||
|
|
||
|
|
@@ -1652,6 +1713,7 @@ | |
| !orderValidation.isValid || | ||
| isPlacingOrder || | ||
| doesStopLossRiskLiquidation || | ||
| hasInvalidTPSL || | ||
| isAtOICap || | ||
| shouldBlockBecauseOfFeesLoading | ||
| } | ||
|
|
@@ -1672,6 +1734,7 @@ | |
| !orderValidation.isValid || | ||
| isPlacingOrder || | ||
| doesStopLossRiskLiquidation || | ||
| hasInvalidTPSL || | ||
| isAtOICap || | ||
| shouldBlockBecauseOfFeesLoading | ||
| } | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.