fix trigger price when changing tokens
This commit is contained in:
parent
e4b3e95d8f
commit
ba859597ef
|
@ -54,6 +54,7 @@ const priceToDisplayString = (price: number | Decimal | string): string => {
|
||||||
}
|
}
|
||||||
|
|
||||||
type LimitSwapFormProps = {
|
type LimitSwapFormProps = {
|
||||||
|
showTokenSelect: SwapFormTokenListType
|
||||||
setShowTokenSelect: Dispatch<SetStateAction<SwapFormTokenListType>>
|
setShowTokenSelect: Dispatch<SetStateAction<SwapFormTokenListType>>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +95,10 @@ const getOrderTypeMultiplier = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const LimitSwapForm = ({ setShowTokenSelect }: LimitSwapFormProps) => {
|
const LimitSwapForm = ({
|
||||||
|
showTokenSelect,
|
||||||
|
setShowTokenSelect,
|
||||||
|
}: LimitSwapFormProps) => {
|
||||||
const { t } = useTranslation(['common', 'swap', 'trade'])
|
const { t } = useTranslation(['common', 'swap', 'trade'])
|
||||||
const { mangoAccountAddress } = useMangoAccount()
|
const { mangoAccountAddress } = useMangoAccount()
|
||||||
const { ipAllowed, ipCountry } = useIpAddress()
|
const { ipAllowed, ipCountry } = useIpAddress()
|
||||||
|
@ -166,14 +170,21 @@ const LimitSwapForm = ({ setShowTokenSelect }: LimitSwapFormProps) => {
|
||||||
|
|
||||||
// set default trigger price
|
// set default trigger price
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!quotePrice || triggerPrice) return
|
if (!quotePrice || triggerPrice || showTokenSelect) return
|
||||||
const multiplier = getOrderTypeMultiplier(
|
const multiplier = getOrderTypeMultiplier(
|
||||||
OrderTypes.STOP_LOSS,
|
orderType,
|
||||||
flipPrices,
|
flipPrices,
|
||||||
isReducingShort,
|
isReducingShort,
|
||||||
)
|
)
|
||||||
setTriggerPrice(priceToDisplayString(quotePrice * multiplier))
|
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
|
// flip trigger price and set amount out when chart direction is flipped
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
|
|
|
@ -178,7 +178,10 @@ const SwapForm = () => {
|
||||||
{swapOrLimit === 'swap' ? (
|
{swapOrLimit === 'swap' ? (
|
||||||
<MarketSwapForm setShowTokenSelect={setShowTokenSelect} />
|
<MarketSwapForm setShowTokenSelect={setShowTokenSelect} />
|
||||||
) : (
|
) : (
|
||||||
<LimitSwapForm setShowTokenSelect={setShowTokenSelect} />
|
<LimitSwapForm
|
||||||
|
showTokenSelect={showTokenSelect}
|
||||||
|
setShowTokenSelect={setShowTokenSelect}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
{inputBank ? (
|
{inputBank ? (
|
||||||
<TokenVaultWarnings bank={inputBank} type="swap" />
|
<TokenVaultWarnings bank={inputBank} type="swap" />
|
||||||
|
|
|
@ -295,7 +295,7 @@ const SwapFormTokenList = ({
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between rounded bg-th-bkg-2 p-2">
|
<div className="flex justify-between rounded bg-th-bkg-2 p-2">
|
||||||
<p className="text-xs text-th-fgd-4">{t('token')}</p>
|
<p className="text-xs text-th-fgd-4">{t('token')}</p>
|
||||||
{type !== 'output' ? (
|
{!type?.includes('output') ? (
|
||||||
<p className="text-xs text-th-fgd-4">{t('max')}</p>
|
<p className="text-xs text-th-fgd-4">{t('max')}</p>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue