1
0
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:
mihaisc 2022-07-01 13:46:37 -07:00 committed by GitHub
parent 423a4d90ac
commit 2e1618db3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ import { calcMaxExactIn, LoggerInstance, Pool } from '@oceanprotocol/lib'
import { usePool } from '@context/Pool'
import { MAX_DECIMALS } from '@utils/constants'
import { getMaxDecimalsValidation } from '@utils/numbers'
import Decimal from 'decimal.js'
export interface FormAddLiquidity {
amount: number
@ -81,11 +82,11 @@ export default function Add({
)
const amountMaxPool = calcMaxExactIn(poolReserve)
const amountMax =
Number(balance.ocean) > Number(amountMaxPool)
const oceanDecimal = new Decimal(balance.ocean)
const amountMax = oceanDecimal.greaterThan(amountMaxPool)
? amountMaxPool
: balance.ocean
setAmountMax(Number(amountMax).toFixed(3))
: oceanDecimal
setAmountMax(amountMax.toFixed(3, Decimal.ROUND_DOWN))
} catch (error) {
LoggerInstance.error(error.message)
}