mirror of https://github.com/certusone/oyster.git
max slider amount can't exceed current balance is user wallet
This commit is contained in:
parent
9fe4d6bda5
commit
404770aea1
|
@ -38,6 +38,9 @@ export const RepayInput = (props: {
|
||||||
const obligation = props.obligation;
|
const obligation = props.obligation;
|
||||||
|
|
||||||
const liquidityMint = useMint(repayReserve.info.liquidityMint);
|
const liquidityMint = useMint(repayReserve.info.liquidityMint);
|
||||||
|
const { balance: tokenBalance } = useUserBalance(
|
||||||
|
repayReserve.info.liquidityMint
|
||||||
|
);
|
||||||
|
|
||||||
const borrowAmountLamports = wadToLamports(
|
const borrowAmountLamports = wadToLamports(
|
||||||
obligation.info.borrowAmountWad
|
obligation.info.borrowAmountWad
|
||||||
|
@ -53,14 +56,15 @@ export const RepayInput = (props: {
|
||||||
|
|
||||||
const convert = useCallback(
|
const convert = useCallback(
|
||||||
(val: string | number) => {
|
(val: string | number) => {
|
||||||
|
const minAmount = Math.min(tokenBalance, borrowAmount);
|
||||||
setLastTyped("repay");
|
setLastTyped("repay");
|
||||||
if (typeof val === "string") {
|
if (typeof val === "string") {
|
||||||
return (parseFloat(val) / borrowAmount) * 100;
|
return (parseFloat(val) / minAmount) * 100;
|
||||||
} else {
|
} else {
|
||||||
return (val * borrowAmount) / 100;
|
return (val * minAmount) / 100;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[borrowAmount]
|
[borrowAmount, tokenBalance]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { value, setValue, pct, setPct, type } = useSliderInput(convert);
|
const { value, setValue, pct, setPct, type } = useSliderInput(convert);
|
||||||
|
@ -221,7 +225,7 @@ export const RepayInput = (props: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
justifyContent: "space-evenly",
|
justifyContent: "space-evenly",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
marginBottom: 20
|
marginBottom: 20,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CollateralInput
|
<CollateralInput
|
||||||
|
|
Loading…
Reference in New Issue