diff --git a/components/swap/useTokenMax.tsx b/components/swap/useTokenMax.tsx index 5b676433..a721b557 100644 --- a/components/swap/useTokenMax.tsx +++ b/components/swap/useTokenMax.tsx @@ -53,15 +53,17 @@ export const getTokenInMax = ( ? inputTokenBalance : new Decimal(0) - const maxUiAmountWithBorrow = floorToDecimal( - mangoAccount.getMaxSourceUiForTokenSwap( - group, - inputBank.mint, - outputBank.mint - ), - inputBank.mintDecimals + const rawMaxUiAmountWithBorrow = mangoAccount.getMaxSourceUiForTokenSwap( + group, + inputBank.mint, + outputBank.mint ) + const maxUiAmountWithBorrow = + rawMaxUiAmountWithBorrow > 0 + ? floorToDecimal(rawMaxUiAmountWithBorrow, inputBank.mintDecimals) + : new Decimal(0) + const inputBankVaultBalance = floorToDecimal( group .getTokenVaultBalanceByMintUi(inputBank.mint)