Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mfi-v2-ui): input & action lending & borrowing issues #406

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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