Skip to content

Commit

Permalink
fix: input & action lending & borrowing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
k0beLeenders authored and chambaz committed Dec 7, 2023
1 parent d810ea7 commit 0d459d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ const AssetRow: FC<{
}, [bank, currentAction]);
const isDust = bank.isActive && bank.position.isDust;
const showCloseBalance = currentAction === ActionType.Withdraw && isDust; // Only case we should show close balance is when we are withdrawing a dust balance, since user receives 0 tokens back (vs repaying a dust balance where the input box will show the smallest unit of the token)
const isActionDisabled = maxAmount === 0 && !showCloseBalance;
const isActionDisabled = useMemo(() => {
const isValidInput = amount > 0;
return (maxAmount === 0 || !isValidInput) && !showCloseBalance;
}, [amount, showCloseBalance, maxAmount]);
const isInputDisabled = useMemo(() => maxAmount === 0 && !showCloseBalance, [maxAmount, showCloseBalance]);

// Reset b/l amounts on toggle
useEffect(() => {
Expand Down Expand Up @@ -528,7 +532,7 @@ const AssetRow: FC<{
maxValue={maxAmount}
maxDecimals={bank.info.state.mintDecimals}
inputRefs={inputRefs}
disabled={showCloseBalance || isActionDisabled}
disabled={isInputDisabled}
onEnter={handleLendingAction}
/>
</Badge>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,13 @@ export const AssetCardActions: FC<{
}
}, [bank.userInfo, currentAction]);

const isDust = useMemo(
() => bank.isActive && uiToNative(bank.position.amount, bank.info.state.mintDecimals).isZero(),
[bank]
);

const isDisabled = useMemo(
() =>
(isDust &&
uiToNative(bank.userInfo.tokenAccount.balance, bank.info.state.mintDecimals).isZero() &&
currentAction == ActionType.Borrow) ||
(!isDust && maxAmount === 0),
[currentAction, bank, isDust, maxAmount]
);
const isDust = useMemo(() => bank.isActive && bank.position.isDust, [bank]);
const showCloseBalance = useMemo(() => currentAction === ActionType.Withdraw && isDust, [isDust, currentAction]); // Only case we should show close balance is when we are withdrawing a dust balance, since user receives 0 tokens back (vs repaying a dust balance where the input box will show the smallest unit of the token)
const isActionDisabled = useMemo(() => {
const isValidInput = borrowOrLendAmount > 0;
return (maxAmount === 0 || !isValidInput) && !showCloseBalance;
}, [borrowOrLendAmount, showCloseBalance, maxAmount]);
const isInputDisabled = useMemo(() => maxAmount === 0 && !showCloseBalance, [maxAmount, showCloseBalance]);

return (
<>
Expand All @@ -51,7 +45,7 @@ export const AssetCardActions: FC<{
maxValue={maxAmount}
maxDecimals={bank.info.state.mintDecimals}
inputRefs={inputRefs}
disabled={isDust || maxAmount === 0}
disabled={isInputDisabled}
onEnter={() => onBorrowOrLend(borrowOrLendAmount)}
/>
<AssetRowAction
Expand All @@ -60,10 +54,10 @@ export const AssetCardActions: FC<{
? "rgb(227, 227, 227)"
: "rgba(0,0,0,0)"
}
onClick={() => (isDust ? onCloseBalance() : onBorrowOrLend(borrowOrLendAmount))}
disabled={isDisabled}
onClick={() => (showCloseBalance ? onCloseBalance() : onBorrowOrLend(borrowOrLendAmount))}
disabled={isActionDisabled}
>
{isDust ? "Close" : currentAction}
{showCloseBalance ? "Close" : currentAction}
</AssetRowAction>
</div>
</>
Expand Down

1 comment on commit 0d459d3

@vercel
Copy link

@vercel vercel bot commented on 0d459d3 Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.