From 2e1618db3ffe2be82c07737acbba59ac7aea9d99 Mon Sep 17 00:00:00 2001 From: mihaisc Date: Fri, 1 Jul 2022 13:46:37 -0700 Subject: [PATCH] fix rounding when calc max (#1564) --- src/components/Asset/AssetActions/Pool/Add/index.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/components/Asset/AssetActions/Pool/Add/index.tsx b/src/components/Asset/AssetActions/Pool/Add/index.tsx index 7840a5742..007e4903b 100644 --- a/src/components/Asset/AssetActions/Pool/Add/index.tsx +++ b/src/components/Asset/AssetActions/Pool/Add/index.tsx @@ -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) - ? amountMaxPool - : balance.ocean - setAmountMax(Number(amountMax).toFixed(3)) + const oceanDecimal = new Decimal(balance.ocean) + const amountMax = oceanDecimal.greaterThan(amountMaxPool) + ? amountMaxPool + : oceanDecimal + setAmountMax(amountMax.toFixed(3, Decimal.ROUND_DOWN)) } catch (error) { LoggerInstance.error(error.message) }