Skip to content

Commit

Permalink
fix: not enough tokens disabled on looper
Browse files Browse the repository at this point in the history
  • Loading branch information
k0beLeenders committed Dec 6, 2024
1 parent b23ea0b commit 5e8a378
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<BankListCommand selectedBank={selectedBank} onClose={onClose} onSetSearchQuery={setSearchQuery}>
Expand All @@ -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)}
>
<BankItem
rate={calculateRate(bank)}
Expand Down

0 comments on commit 5e8a378

Please sign in to comment.