From 5e8a3787585eb73c5207b8de4de76d30608f9787 Mon Sep 17 00:00:00 2001 From: Kobe Date: Fri, 6 Dec 2024 14:54:56 +0100 Subject: [PATCH] fix: not enough tokens disabled on looper --- .../components/bank-list/bank-list.tsx | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/mrgn-ui/src/components/action-box-v2/actions/loop-box/components/action-input/components/bank-select/components/bank-list/bank-list.tsx b/packages/mrgn-ui/src/components/action-box-v2/actions/loop-box/components/action-input/components/bank-select/components/bank-list/bank-list.tsx index dd59fd07b9..0b488b29c0 100644 --- a/packages/mrgn-ui/src/components/action-box-v2/actions/loop-box/components/action-input/components/bank-select/components/bank-list/bank-list.tsx +++ b/packages/mrgn-ui/src/components/action-box-v2/actions/loop-box/components/action-input/components/bank-select/components/bank-list/bank-list.tsx @@ -62,6 +62,30 @@ export const BankList = ({ } }, [isOpen]); + const isDisabled = React.useCallback( + (bank: ExtendedBankInfo) => { + const isBorrowing = actionMode === ActionType.Borrow; + + let isDisabled = false; + const noNativeBalance = bank?.info.state.mint.equals(WSOL_MINT) + ? nativeSolBalance === 0 + : bank?.userInfo.tokenAccount.balance === 0; + + if (isBorrowing) { + const isLending = bank.isActive && bank.position.isLending; + const isOtherBank = otherBank?.address.equals(bank.address) ?? false; + + isDisabled = isOtherBank || isLending || noNativeBalance; + } else { + const isBorrowing = bank.isActive && !bank.position.isLending; + isDisabled = isBorrowing || noNativeBalance; + } + + return isDisabled; + }, + [actionMode, otherBank, nativeSolBalance] + ); + return ( <> @@ -79,13 +103,7 @@ export const BankList = ({ onClose(); }} className="cursor-pointer h-[55px] px-3 font-medium flex items-center justify-between gap-2 data-[selected=true]:bg-mfi-action-box-accent data-[selected=true]:text-mfi-action-box-accent-foreground" - disabled={ - actionMode === ActionType.Borrow - ? otherBank?.address.equals(bank.address) - : bank.info.state.mint.equals(WSOL_MINT) - ? nativeSolBalance === 0 - : bank.userInfo.tokenAccount.balance === 0 - } + disabled={isDisabled(bank)} >