Skip to content

Commit

Permalink
Use exact token balance when calculate max bridgeable amount
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboydiamonds committed Apr 3, 2024
1 parent 1496842 commit c01109f
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@ export const InputContainer = () => {

const dispatch = useDispatch()

const parsedBalance = balances[fromChainId]?.find(
(token) => token.tokenAddress === fromToken?.addresses[fromChainId]
)?.parsedBalance

const balance = balances[fromChainId]?.find(
(token) => token.tokenAddress === fromToken?.addresses[fromChainId]
)?.balance

const shortenedParsedBalance = balances[fromChainId]?.find(
(token) => token.tokenAddress === fromToken?.addresses[fromChainId]
)?.parsedBalance

const fullParsedBalance = formatBigIntToString(
balance,
fromToken?.decimals[fromChainId]
)

const estimatedGasCostInGwei = calculateGasFeeInGwei(gasPrice, 200_000)

const isNativeToken = fromToken?.addresses[fromChainId] === zeroAddress
Expand Down Expand Up @@ -93,7 +98,10 @@ export const InputContainer = () => {

const onMaxBridgeableBalance = useCallback(() => {
if (estimatedGasCostInGwei && isNativeToken) {
const maxBalance = Number(parsedBalance) - estimatedGasCostInGwei
const maxBalance = Number(fullParsedBalance) - estimatedGasCostInGwei

console.log('fullParsedBalance; ', fullParsedBalance)
console.log('estimatedGasCostInGwei:', estimatedGasCostInGwei)

if (maxBalance < 0) {
toast.error(`Balance is less than estimated gas fee.`, {
Expand All @@ -117,7 +125,7 @@ export const InputContainer = () => {
)
}
}, [
parsedBalance,
shortenedParsedBalance,
balance,
fromChainId,
fromToken,
Expand Down Expand Up @@ -189,7 +197,7 @@ export const InputContainer = () => {
className="text-xs text-white transition-all duration-150 transform-gpu hover:text-opacity-70 hover:cursor-pointer"
onClick={onMaxBalance}
>
{parsedBalance ?? '0.0'}
{shortenedParsedBalance ?? '0.0'}
<span className="text-opacity-50 text-secondaryTextColor">
{' '}
available
Expand Down

0 comments on commit c01109f

Please sign in to comment.