From ba859597ef262fd6ced94df22e1fecb8b13a99bb Mon Sep 17 00:00:00 2001 From: saml33 Date: Thu, 7 Sep 2023 23:59:24 +1000 Subject: [PATCH] fix trigger price when changing tokens --- components/swap/LimitSwapForm.tsx | 19 +++++++++++++++---- components/swap/SwapForm.tsx | 5 ++++- components/swap/SwapFormTokenList.tsx | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/components/swap/LimitSwapForm.tsx b/components/swap/LimitSwapForm.tsx index 2d31acfd..06d035b5 100644 --- a/components/swap/LimitSwapForm.tsx +++ b/components/swap/LimitSwapForm.tsx @@ -54,6 +54,7 @@ const priceToDisplayString = (price: number | Decimal | string): string => { } type LimitSwapFormProps = { + showTokenSelect: SwapFormTokenListType setShowTokenSelect: Dispatch> } @@ -94,7 +95,10 @@ const getOrderTypeMultiplier = ( } } -const LimitSwapForm = ({ setShowTokenSelect }: LimitSwapFormProps) => { +const LimitSwapForm = ({ + showTokenSelect, + setShowTokenSelect, +}: LimitSwapFormProps) => { const { t } = useTranslation(['common', 'swap', 'trade']) const { mangoAccountAddress } = useMangoAccount() const { ipAllowed, ipCountry } = useIpAddress() @@ -166,14 +170,21 @@ const LimitSwapForm = ({ setShowTokenSelect }: LimitSwapFormProps) => { // set default trigger price useEffect(() => { - if (!quotePrice || triggerPrice) return + if (!quotePrice || triggerPrice || showTokenSelect) return const multiplier = getOrderTypeMultiplier( - OrderTypes.STOP_LOSS, + orderType, flipPrices, isReducingShort, ) setTriggerPrice(priceToDisplayString(quotePrice * multiplier)) - }, [flipPrices, quotePrice, triggerPrice, isReducingShort]) + }, [ + flipPrices, + isReducingShort, + orderType, + quotePrice, + showTokenSelect, + triggerPrice, + ]) // flip trigger price and set amount out when chart direction is flipped useLayoutEffect(() => { diff --git a/components/swap/SwapForm.tsx b/components/swap/SwapForm.tsx index 9650c5ac..269f9727 100644 --- a/components/swap/SwapForm.tsx +++ b/components/swap/SwapForm.tsx @@ -178,7 +178,10 @@ const SwapForm = () => { {swapOrLimit === 'swap' ? ( ) : ( - + )} {inputBank ? ( diff --git a/components/swap/SwapFormTokenList.tsx b/components/swap/SwapFormTokenList.tsx index ae6b212e..b49ae237 100644 --- a/components/swap/SwapFormTokenList.tsx +++ b/components/swap/SwapFormTokenList.tsx @@ -295,7 +295,7 @@ const SwapFormTokenList = ({

{t('token')}

- {type !== 'output' ? ( + {!type?.includes('output') ? (

{t('max')}

) : null}