From c6dc8777b9802e593d3ee5d6e602fc2c1d3bf920 Mon Sep 17 00:00:00 2001 From: Kieran Gillen Date: Thu, 17 Mar 2022 17:18:48 +0100 Subject: [PATCH] Adds post only slide input --- components/trade_form/AdvancedTradeForm.tsx | 71 +++++++++++++-------- public/locales/en/common.json | 1 + 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/components/trade_form/AdvancedTradeForm.tsx b/components/trade_form/AdvancedTradeForm.tsx index 29cbaef6..653080cb 100644 --- a/components/trade_form/AdvancedTradeForm.tsx +++ b/components/trade_form/AdvancedTradeForm.tsx @@ -113,10 +113,7 @@ export default function AdvancedTradeForm({ const isTriggerOrder = TRIGGER_ORDER_TYPES.includes(tradeType) - // TODO saml - create a tick box on the UI; Only available on perps - // eslint-disable-next-line const [postOnlySlide, setPostOnlySlide] = useState(false) - const [postOnly, setPostOnly] = useState(false) const [ioc, setIoc] = useState(false) @@ -403,8 +400,6 @@ export default function AdvancedTradeForm({ } } - // TODO saml - use - // eslint-disable-next-line const postOnlySlideOnChange = (checked) => { if (checked) { setIoc(false) @@ -412,7 +407,6 @@ export default function AdvancedTradeForm({ } setPostOnlySlide(checked) } - const postOnChange = (checked) => { if (checked) { setIoc(false) @@ -630,7 +624,9 @@ export default function AdvancedTradeForm({ let perpOrderPrice: number = orderPrice if (isMarketOrder) { - if (tradeType === 'Market' && maxSlippage !== undefined) { + if (postOnlySlide) { + perpOrderType = 'postOnlySlide' + } else if (tradeType === 'Market' && maxSlippage !== undefined) { perpOrderType = 'ioc' if (side === 'buy') { perpOrderPrice = markPrice * (1 + parseFloat(maxSlippage)) @@ -791,15 +787,19 @@ export default function AdvancedTradeForm({ min="0" step={tickSize} onChange={(e) => onSetPrice(e.target.value)} - value={price} - disabled={isMarketOrder} + value={postOnlySlide ? '' : price} + disabled={isMarketOrder || postOnlySlide} placeholder={tradeType === 'Market' ? markPrice : null} prefix={ - + <> + {!postOnlySlide && ( + + )} + } /> @@ -893,8 +893,8 @@ export default function AdvancedTradeForm({ : ['10', '25', '50', '75', '100'] } /> - {marketConfig.kind === 'perp' ? ( - side === 'sell' ? ( + {marketConfig.kind === 'perp' && + (side === 'sell' ? ( roundedDeposits > 0 ? (
{closeDepositString} @@ -904,10 +904,9 @@ export default function AdvancedTradeForm({
{closeBorrowString}
- ) : null - ) : null} + ) : null)}
- {isLimitOrder ? ( + {isLimitOrder && (
- ) : null} + )} {/* Add the following line to the ternary below once we are auto updating the reduceOnly state when doing a market order: && showReduceOnly(perpAccount?.basePosition.toNumber()) */} - {marketConfig.kind === 'perp' ? ( -
+ {marketConfig.kind === 'perp' && ( +
- ) : null} - {marketConfig.kind === 'spot' ? ( + )} + {marketConfig.kind === 'perp' && ( +
+ + postOnlySlideOnChange(e.target.checked)} + disabled={isTriggerOrder} + > + Post & Slide + + +
+ )} + {marketConfig.kind === 'spot' && (
- ) : null} + )}
- {warnUserSlippage ? ( + {warnUserSlippage && (
{t('slippage-warning')}
- ) : null} + )}
{canTrade ? (