Skip to content

Commit

Permalink
Merge pull request #993 from mrgnlabs/fix/looper-bank-select
Browse files Browse the repository at this point in the history
fix(mfi-ui): not enough tokens disabled on looper
  • Loading branch information
k0beLeenders authored Dec 6, 2024
2 parents b23ea0b + 5e8a378 commit f2bd2b9
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 f2bd2b9

Please sign in to comment.