fix trade max size button

This commit is contained in:
saml33 2023-04-01 21:05:53 +11:00
parent c594011202
commit e0463a9863
1 changed files with 14 additions and 11 deletions

View File

@ -7,7 +7,7 @@ import useSelectedMarket from 'hooks/useSelectedMarket'
import useUnownedAccount from 'hooks/useUnownedAccount'
import { useTranslation } from 'next-i18next'
import { useCallback, useMemo } from 'react'
import { formatNumericValue } from 'utils/numbers'
import { floorToDecimal } from 'utils/numbers'
import { useSpotMarketMax } from './SpotSlider'
const MaxSizeButton = ({
@ -59,30 +59,33 @@ const MaxSizeButton = ({
const set = mangoStore.getState().set
set((state) => {
if (side === 'buy') {
state.tradeForm.quoteSize = formatNumericValue(max, tickDecimals)
state.tradeForm.quoteSize = floorToDecimal(max, tickDecimals).toFixed()
if (tradeType === 'Market' || !price) {
state.tradeForm.baseSize = formatNumericValue(
state.tradeForm.baseSize = floorToDecimal(
max / oraclePrice,
minOrderDecimals
)
).toFixed()
} else {
state.tradeForm.baseSize = formatNumericValue(
state.tradeForm.baseSize = floorToDecimal(
max / parseFloat(price),
minOrderDecimals
)
).toFixed()
}
} else {
state.tradeForm.baseSize = formatNumericValue(max, minOrderDecimals)
state.tradeForm.baseSize = floorToDecimal(
max,
minOrderDecimals
).toFixed()
if (tradeType === 'Market' || !price) {
state.tradeForm.quoteSize = formatNumericValue(
state.tradeForm.quoteSize = floorToDecimal(
max * oraclePrice,
minOrderDecimals
)
).toFixed()
} else {
state.tradeForm.quoteSize = formatNumericValue(
state.tradeForm.quoteSize = floorToDecimal(
max * parseFloat(price),
minOrderDecimals
)
).toFixed()
}
}
})