From 0299ac6ee502e8a3463bcfb5f4a98923ce35ac23 Mon Sep 17 00:00:00 2001 From: DaveVodrazka Date: Mon, 1 Jul 2024 10:45:29 +0200 Subject: [PATCH] fix: handle input as bigint --- src/components/CarmineStaking/StakeCRM.tsx | 11 ++++++++--- src/components/CarmineStaking/StakingModal.tsx | 12 ++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/components/CarmineStaking/StakeCRM.tsx b/src/components/CarmineStaking/StakeCRM.tsx index 246d457d..abd3df0f 100644 --- a/src/components/CarmineStaking/StakeCRM.tsx +++ b/src/components/CarmineStaking/StakeCRM.tsx @@ -85,6 +85,7 @@ const stake = async ( export const StakeCrm = ({ account, carmBalance }: Props) => { const [inputValue, setInputValue] = useState(""); + const [amount, setSelectedAmount] = useState(0n); const [monthState, setMonthState] = useState(TransactionState.Initial); const [sixMonthsState, setSixMonthsState] = useState( @@ -93,7 +94,6 @@ export const StakeCrm = ({ account, carmBalance }: Props) => { const [yearState, setYearState] = useState(TransactionState.Initial); const numCarmBalance = shortInteger(carmBalance, 18); - const amount = longInteger(parseFloat(inputValue), 18); const handle1month = () => { setSixMonthsState(TransactionState.Processing); @@ -128,16 +128,21 @@ export const StakeCrm = ({ account, carmBalance }: Props) => { value === "" || /^\d*\.?\d{0,6}$/.test(value) ? value : inputValue; const num = parseFloat(numericValue); + const long = longInteger(num, 18); - if (num && num > numCarmBalance) { + if (long > carmBalance) { // cannot set more than holds return; } setInputValue(numericValue); + setSelectedAmount(long); }; - const handleAll = () => setInputValue(numCarmBalance.toString(10)); + const handleAll = () => { + setInputValue(numCarmBalance.toString(10)); + setSelectedAmount(carmBalance); + }; return (
diff --git a/src/components/CarmineStaking/StakingModal.tsx b/src/components/CarmineStaking/StakingModal.tsx index 1bfa66f6..241df293 100644 --- a/src/components/CarmineStaking/StakingModal.tsx +++ b/src/components/CarmineStaking/StakingModal.tsx @@ -106,6 +106,7 @@ export const stateToClassName = (state: TransactionState) => { export const StakingModal = ({ account, amount, open, setOpen }: Props) => { const numCarmBalance = shortInteger(amount, 18); const [inputValue, setInputValue] = useState(numCarmBalance.toString(10)); + const [selectedAmount, setSelectedAmount] = useState(amount); const [unstakeState, setUnstakeState] = useState(TransactionState.Initial); const [monthState, setMonthState] = useState(TransactionState.Initial); const [sixMonthsState, setSixMonthsState] = useState( @@ -113,8 +114,6 @@ export const StakingModal = ({ account, amount, open, setOpen }: Props) => { ); const [yearState, setYearState] = useState(TransactionState.Initial); - const selectedAmount = longInteger(parseFloat(inputValue), 18); - const handleClose = () => { setOpen(false); setUnstakeState(TransactionState.Initial); @@ -171,16 +170,21 @@ export const StakingModal = ({ account, amount, open, setOpen }: Props) => { value === "" || /^\d*\.?\d{0,6}$/.test(value) ? value : inputValue; const num = parseFloat(numericValue); + const long = longInteger(num, 18); - if (num && num > numCarmBalance) { + if (long > amount) { // cannot set more than holds return; } setInputValue(numericValue); + setSelectedAmount(long); }; - const handleAll = () => setInputValue(numCarmBalance.toString(10)); + const handleAll = () => { + setInputValue(numCarmBalance.toString(10)); + setSelectedAmount(amount); + }; return (