From 205892badac02d58cb04bf840687704ed231cbef Mon Sep 17 00:00:00 2001 From: Fishon Amos Date: Mon, 9 Sep 2024 21:15:00 +0100 Subject: [PATCH] resolve max withdraw bug --- src/components/Deposit.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/Deposit.tsx b/src/components/Deposit.tsx index 8e5d573..6e7d58b 100755 --- a/src/components/Deposit.tsx +++ b/src/components/Deposit.tsx @@ -32,6 +32,7 @@ import { useAtomValue } from 'jotai'; import mixpanel from 'mixpanel-browser'; import { useMemo, useState } from 'react'; import { ProviderInterface } from 'starknet'; +import { BigNumber } from 'ethers'; import LoadingWrap from './LoadingWrap'; import TxButton from './TxButton'; @@ -95,6 +96,14 @@ export default function Deposit(props: DepositProps) { }, [balData]); // const { balance, isLoading, isError } = useERC20Balance(selectedMarket); const maxAmount: MyNumber = useMemo(() => { + if (props.buttonText === 'Redeem') { + // For withdrawals, use the maximum possible value + return MyNumber.fromEther( + BigNumber.from(2).pow(256).sub(1).toString(), + selectedMarket.decimals + ); + } + const currentTVl = tvlInfo.data?.amount || MyNumber.fromZero(); const maxAllowed = props.strategy.settings.maxTVL - Number(currentTVl.toEtherStr()); @@ -118,7 +127,7 @@ export default function Deposit(props: DepositProps) { console.log('Deposit:: reducedBalance2', reducedBalance.toEtherStr()); const min = MyNumber.min(reducedBalance, adjustedMaxAllowed); return MyNumber.max(min, MyNumber.fromEther('0', selectedMarket.decimals)); - }, [balance, props.strategy, selectedMarket]); + }, [balance, props.strategy, selectedMarket, props.buttonText]); function BalanceComponent(props: { token: TokenInfo; @@ -248,7 +257,7 @@ export default function Deposit(props: DepositProps) { {/* add min max validations and show err */} '} 0 )} - {amount.compare(maxAmount.toEtherStr(), 'gt') && ( + {props.buttonText === 'Deposit' && amount.compare(maxAmount.toEtherStr(), 'gt') && ( Amount to be less than {maxAmount.toEtherToFixedDecimals(2)}