max slider amount can't exceed current balance is user wallet

This commit is contained in:
juan 2021-01-27 12:44:14 -05:00
parent 9fe4d6bda5
commit 404770aea1
1 changed files with 8 additions and 4 deletions

View File

@ -38,6 +38,9 @@ export const RepayInput = (props: {
const obligation = props.obligation;
const liquidityMint = useMint(repayReserve.info.liquidityMint);
const { balance: tokenBalance } = useUserBalance(
repayReserve.info.liquidityMint
);
const borrowAmountLamports = wadToLamports(
obligation.info.borrowAmountWad
@ -53,14 +56,15 @@ export const RepayInput = (props: {
const convert = useCallback(
(val: string | number) => {
const minAmount = Math.min(tokenBalance, borrowAmount);
setLastTyped("repay");
if (typeof val === "string") {
return (parseFloat(val) / borrowAmount) * 100;
return (parseFloat(val) / minAmount) * 100;
} else {
return (val * borrowAmount) / 100;
return (val * minAmount) / 100;
}
},
[borrowAmount]
[borrowAmount, tokenBalance]
);
const { value, setValue, pct, setPct, type } = useSliderInput(convert);
@ -221,7 +225,7 @@ export const RepayInput = (props: {
flexDirection: "row",
justifyContent: "space-evenly",
alignItems: "center",
marginBottom: 20
marginBottom: 20,
}}
>
<CollateralInput