Adds post only slide input

This commit is contained in:
Kieran Gillen 2022-03-17 17:18:48 +01:00
parent 398f8af80e
commit c6dc8777b9
2 changed files with 45 additions and 27 deletions

View File

@ -113,10 +113,7 @@ export default function AdvancedTradeForm({
const isTriggerOrder = TRIGGER_ORDER_TYPES.includes(tradeType) 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 [postOnlySlide, setPostOnlySlide] = useState(false)
const [postOnly, setPostOnly] = useState(false) const [postOnly, setPostOnly] = useState(false)
const [ioc, setIoc] = 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) => { const postOnlySlideOnChange = (checked) => {
if (checked) { if (checked) {
setIoc(false) setIoc(false)
@ -412,7 +407,6 @@ export default function AdvancedTradeForm({
} }
setPostOnlySlide(checked) setPostOnlySlide(checked)
} }
const postOnChange = (checked) => { const postOnChange = (checked) => {
if (checked) { if (checked) {
setIoc(false) setIoc(false)
@ -630,7 +624,9 @@ export default function AdvancedTradeForm({
let perpOrderPrice: number = orderPrice let perpOrderPrice: number = orderPrice
if (isMarketOrder) { if (isMarketOrder) {
if (tradeType === 'Market' && maxSlippage !== undefined) { if (postOnlySlide) {
perpOrderType = 'postOnlySlide'
} else if (tradeType === 'Market' && maxSlippage !== undefined) {
perpOrderType = 'ioc' perpOrderType = 'ioc'
if (side === 'buy') { if (side === 'buy') {
perpOrderPrice = markPrice * (1 + parseFloat(maxSlippage)) perpOrderPrice = markPrice * (1 + parseFloat(maxSlippage))
@ -791,15 +787,19 @@ export default function AdvancedTradeForm({
min="0" min="0"
step={tickSize} step={tickSize}
onChange={(e) => onSetPrice(e.target.value)} onChange={(e) => onSetPrice(e.target.value)}
value={price} value={postOnlySlide ? '' : price}
disabled={isMarketOrder} disabled={isMarketOrder || postOnlySlide}
placeholder={tradeType === 'Market' ? markPrice : null} placeholder={tradeType === 'Market' ? markPrice : null}
prefix={ prefix={
<img <>
src={`/assets/icons/${groupConfig.quoteSymbol.toLowerCase()}.svg`} {!postOnlySlide && (
width="16" <img
height="16" src={`/assets/icons/${groupConfig.quoteSymbol.toLowerCase()}.svg`}
/> width="16"
height="16"
/>
)}
</>
} }
/> />
</> </>
@ -893,8 +893,8 @@ export default function AdvancedTradeForm({
: ['10', '25', '50', '75', '100'] : ['10', '25', '50', '75', '100']
} }
/> />
{marketConfig.kind === 'perp' ? ( {marketConfig.kind === 'perp' &&
side === 'sell' ? ( (side === 'sell' ? (
roundedDeposits > 0 ? ( roundedDeposits > 0 ? (
<div className="mt-2 text-xs tracking-normal text-th-fgd-4"> <div className="mt-2 text-xs tracking-normal text-th-fgd-4">
<span>{closeDepositString}</span> <span>{closeDepositString}</span>
@ -904,10 +904,9 @@ export default function AdvancedTradeForm({
<div className="mt-2 text-xs tracking-normal text-th-fgd-4"> <div className="mt-2 text-xs tracking-normal text-th-fgd-4">
<span>{closeBorrowString}</span> <span>{closeBorrowString}</span>
</div> </div>
) : null ) : null)}
) : null}
<div className="sm:flex"> <div className="sm:flex">
{isLimitOrder ? ( {isLimitOrder && (
<div className="flex"> <div className="flex">
<div className="mr-4 mt-3"> <div className="mr-4 mt-3">
<Tooltip <Tooltip
@ -942,14 +941,14 @@ export default function AdvancedTradeForm({
</Tooltip> </Tooltip>
</div> </div>
</div> </div>
) : null} )}
{/* {/*
Add the following line to the ternary below once we are Add the following line to the ternary below once we are
auto updating the reduceOnly state when doing a market order: auto updating the reduceOnly state when doing a market order:
&& showReduceOnly(perpAccount?.basePosition.toNumber()) && showReduceOnly(perpAccount?.basePosition.toNumber())
*/} */}
{marketConfig.kind === 'perp' ? ( {marketConfig.kind === 'perp' && (
<div className="mt-3"> <div className="mr-4 mt-3">
<Tooltip <Tooltip
className="hidden md:block" className="hidden md:block"
delay={250} delay={250}
@ -965,8 +964,26 @@ export default function AdvancedTradeForm({
</Checkbox> </Checkbox>
</Tooltip> </Tooltip>
</div> </div>
) : null} )}
{marketConfig.kind === 'spot' ? ( {marketConfig.kind === 'perp' && (
<div className="mt-3">
<Tooltip
className="hidden md:block"
delay={250}
placement="left"
content={t('tooltip-post-and-slide')}
>
<Checkbox
checked={postOnlySlide}
onChange={(e) => postOnlySlideOnChange(e.target.checked)}
disabled={isTriggerOrder}
>
Post & Slide
</Checkbox>
</Tooltip>
</div>
)}
{marketConfig.kind === 'spot' && (
<div className="mt-3"> <div className="mt-3">
<Tooltip <Tooltip
delay={250} delay={250}
@ -981,16 +998,16 @@ export default function AdvancedTradeForm({
</Checkbox> </Checkbox>
</Tooltip> </Tooltip>
</div> </div>
) : null} )}
</div> </div>
{warnUserSlippage ? ( {warnUserSlippage && (
<div className="mt-1 flex items-center text-th-red"> <div className="mt-1 flex items-center text-th-red">
<div> <div>
<ExclamationIcon className="mr-2 h-5 w-5" /> <ExclamationIcon className="mr-2 h-5 w-5" />
</div> </div>
<div className="text-xs">{t('slippage-warning')}</div> <div className="text-xs">{t('slippage-warning')}</div>
</div> </div>
) : null} )}
<div className={`mt-3 flex`}> <div className={`mt-3 flex`}>
{canTrade ? ( {canTrade ? (
<button <button

View File

@ -370,6 +370,7 @@
"tooltip-lock-layout": "Lock Layout", "tooltip-lock-layout": "Lock Layout",
"tooltip-name-onchain": "Account names are stored on-chain", "tooltip-name-onchain": "Account names are stored on-chain",
"tooltip-post": "Post only orders are guaranteed to be the maker order or else it will be canceled.", "tooltip-post": "Post only orders are guaranteed to be the maker order or else it will be canceled.",
"tooltip-post-and-slide": "Post only slide is a type of limit order that will place your order one penny less than the opposite side of the book.",
"tooltip-projected-leverage": "Projected Leverage", "tooltip-projected-leverage": "Projected Leverage",
"tooltip-reduce": "Reduce only orders will only reduce your overall position.", "tooltip-reduce": "Reduce only orders will only reduce your overall position.",
"tooltip-reset-layout": "Reset Layout", "tooltip-reset-layout": "Reset Layout",