mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
fix rounding when calc max (#1564)
This commit is contained in:
parent
423a4d90ac
commit
2e1618db3f
@ -17,6 +17,7 @@ import { calcMaxExactIn, LoggerInstance, Pool } from '@oceanprotocol/lib'
|
|||||||
import { usePool } from '@context/Pool'
|
import { usePool } from '@context/Pool'
|
||||||
import { MAX_DECIMALS } from '@utils/constants'
|
import { MAX_DECIMALS } from '@utils/constants'
|
||||||
import { getMaxDecimalsValidation } from '@utils/numbers'
|
import { getMaxDecimalsValidation } from '@utils/numbers'
|
||||||
|
import Decimal from 'decimal.js'
|
||||||
|
|
||||||
export interface FormAddLiquidity {
|
export interface FormAddLiquidity {
|
||||||
amount: number
|
amount: number
|
||||||
@ -81,11 +82,11 @@ export default function Add({
|
|||||||
)
|
)
|
||||||
|
|
||||||
const amountMaxPool = calcMaxExactIn(poolReserve)
|
const amountMaxPool = calcMaxExactIn(poolReserve)
|
||||||
const amountMax =
|
const oceanDecimal = new Decimal(balance.ocean)
|
||||||
Number(balance.ocean) > Number(amountMaxPool)
|
const amountMax = oceanDecimal.greaterThan(amountMaxPool)
|
||||||
? amountMaxPool
|
? amountMaxPool
|
||||||
: balance.ocean
|
: oceanDecimal
|
||||||
setAmountMax(Number(amountMax).toFixed(3))
|
setAmountMax(amountMax.toFixed(3, Decimal.ROUND_DOWN))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LoggerInstance.error(error.message)
|
LoggerInstance.error(error.message)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user