From 34351caf0b34550d47aae54642a030448055dc08 Mon Sep 17 00:00:00 2001 From: Mike Starr Date: Fri, 6 Oct 2023 08:32:20 -0400 Subject: [PATCH 1/9] changed decimals of stakingAmount in comparisons in StakingModal --- src/features/staking/StakingModal.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/features/staking/StakingModal.tsx b/src/features/staking/StakingModal.tsx index baf621d..0bb8336 100644 --- a/src/features/staking/StakingModal.tsx +++ b/src/features/staking/StakingModal.tsx @@ -22,7 +22,7 @@ export const StakingModal = () => { const formReturn = useForm(); const { getValues } = formReturn; - const stakingAmount = getValues().stakingAmount * 10 ** 4; + const stakingAmount = getValues().stakingAmount; const isSupportedChain = useIsSupportedChain(); const { switchNetwork } = useSwitchNetwork(); @@ -42,21 +42,23 @@ export const StakingModal = () => { const needsApproval = txType === TxType.STAKE && - Number(astAllowance) < Number(stakingAmount) && + Number(astAllowance) < Number(stakingAmount) * 10 ** 4 && validNumberInput; + console.log(needsApproval, astAllowance, stakingAmount); + const canStake = txType === TxType.STAKE && !needsApproval && validNumberInput; const canUnstake = - Number(stakingAmount) <= Number(unstakableSastBalance) && + Number(stakingAmount) * 10 ** 4 <= Number(unstakableSastBalance) && txType === TxType.UNSTAKE && validNumberInput; const isInsufficientBalance = txType === TxType.STAKE && stakingAmount - ? Number(stakingAmount) > Number(astBalance) - : Number(stakingAmount) > Number(unstakableSastBalance); + ? Number(stakingAmount) * 10 ** 4 > Number(astBalance) + : Number(stakingAmount) * 10 ** 4 > Number(unstakableSastBalance); const { writeAsync: approveAst, From be41383a6c03bbdcbe59f77f48e0be8ce17fb695 Mon Sep 17 00:00:00 2001 From: Mike Starr Date: Fri, 6 Oct 2023 08:41:10 -0400 Subject: [PATCH 2/9] remove console log --- src/features/staking/StakingModal.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/features/staking/StakingModal.tsx b/src/features/staking/StakingModal.tsx index 0bb8336..62e6fdf 100644 --- a/src/features/staking/StakingModal.tsx +++ b/src/features/staking/StakingModal.tsx @@ -45,8 +45,6 @@ export const StakingModal = () => { Number(astAllowance) < Number(stakingAmount) * 10 ** 4 && validNumberInput; - console.log(needsApproval, astAllowance, stakingAmount); - const canStake = txType === TxType.STAKE && !needsApproval && validNumberInput; From 7b804138eee610e4a241609217ed2495684bbce1 Mon Sep 17 00:00:00 2001 From: greypixel Date: Fri, 6 Oct 2023 14:38:25 +0100 Subject: [PATCH 3/9] Use bignumber amount for approval check --- src/features/staking/StakingModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/features/staking/StakingModal.tsx b/src/features/staking/StakingModal.tsx index 62e6fdf..ef93251 100644 --- a/src/features/staking/StakingModal.tsx +++ b/src/features/staking/StakingModal.tsx @@ -30,7 +30,7 @@ export const StakingModal = () => { // This state tracks whether the last transaction was an approval. const [isApproval, setIsApproval] = useState(false); - const { astAllowanceFormatted: astAllowance } = useAstAllowance(); + const { astAllowance } = useAstAllowance(); const { unstakableSastBalanceRaw: unstakableSastBalance, From 40533ac9061455d9cb65403bdc6390d46b62f5d3 Mon Sep 17 00:00:00 2001 From: Mike Starr Date: Fri, 6 Oct 2023 09:50:35 -0400 Subject: [PATCH 4/9] removed conversion 10**4 --- src/features/staking/StakingModal.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/features/staking/StakingModal.tsx b/src/features/staking/StakingModal.tsx index ef93251..69f4d49 100644 --- a/src/features/staking/StakingModal.tsx +++ b/src/features/staking/StakingModal.tsx @@ -42,21 +42,21 @@ export const StakingModal = () => { const needsApproval = txType === TxType.STAKE && - Number(astAllowance) < Number(stakingAmount) * 10 ** 4 && + Number(astAllowance) < Number(stakingAmount) && validNumberInput; const canStake = txType === TxType.STAKE && !needsApproval && validNumberInput; const canUnstake = - Number(stakingAmount) * 10 ** 4 <= Number(unstakableSastBalance) && + Number(stakingAmount) <= Number(unstakableSastBalance) && txType === TxType.UNSTAKE && validNumberInput; const isInsufficientBalance = txType === TxType.STAKE && stakingAmount - ? Number(stakingAmount) * 10 ** 4 > Number(astBalance) - : Number(stakingAmount) * 10 ** 4 > Number(unstakableSastBalance); + ? Number(stakingAmount) > Number(astBalance) + : Number(stakingAmount) > Number(unstakableSastBalance); const { writeAsync: approveAst, From 955af6a5598393c0e4313753a82d996047c9c2ab Mon Sep 17 00:00:00 2001 From: Mike Starr Date: Fri, 6 Oct 2023 09:57:08 -0400 Subject: [PATCH 5/9] fixed PieBar length on firefox --- src/features/staking/PieBar.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/features/staking/PieBar.tsx b/src/features/staking/PieBar.tsx index 557c425..a903d0e 100644 --- a/src/features/staking/PieBar.tsx +++ b/src/features/staking/PieBar.tsx @@ -15,9 +15,9 @@ export const PieBar = () => { const { unstakablePercent, stakedPercent, unstakedPercent } = calculateTokenProportions({ - unstakable: Number(unstakableSastBalanceRaw) / 10 ** 4, - staked: Number(sAstBalanceRaw) / 10 ** 4, - unstaked: Number(astBalanceRaw) / 10 ** 4, + unstakable: Number(unstakableSastBalanceRaw), + staked: Number(sAstBalanceRaw), + unstaked: Number(astBalanceRaw), }); const zeroBalance = !unstakablePercent && !stakedPercent && !unstakedPercent; @@ -43,6 +43,8 @@ export const PieBar = () => { }, ]; + console.log(unstakablePercent, stakedPercent, unstakedPercent); + const stakableRow = stakableData.map((stakable) => { return (
Date: Fri, 6 Oct 2023 09:58:01 -0400 Subject: [PATCH 6/9] undo piebar fix --- src/features/staking/PieBar.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/features/staking/PieBar.tsx b/src/features/staking/PieBar.tsx index a903d0e..dec9331 100644 --- a/src/features/staking/PieBar.tsx +++ b/src/features/staking/PieBar.tsx @@ -15,9 +15,9 @@ export const PieBar = () => { const { unstakablePercent, stakedPercent, unstakedPercent } = calculateTokenProportions({ - unstakable: Number(unstakableSastBalanceRaw), - staked: Number(sAstBalanceRaw), - unstaked: Number(astBalanceRaw), + unstakable: Number(unstakableSastBalanceRaw) / 10 ** 4, + staked: Number(sAstBalanceRaw) / 10 ** 4, + unstaked: Number(astBalanceRaw) / 10 ** 4, }); const zeroBalance = !unstakablePercent && !stakedPercent && !unstakedPercent; From 2d226a3b18b8fa0f8fc6707127ea814c79a2355f Mon Sep 17 00:00:00 2001 From: Mike Starr Date: Fri, 6 Oct 2023 10:41:35 -0400 Subject: [PATCH 7/9] remove comments, fix conversions --- src/features/staking/PieBar.tsx | 2 -- src/features/staking/StakingModal.tsx | 26 ++++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/features/staking/PieBar.tsx b/src/features/staking/PieBar.tsx index dec9331..557c425 100644 --- a/src/features/staking/PieBar.tsx +++ b/src/features/staking/PieBar.tsx @@ -43,8 +43,6 @@ export const PieBar = () => { }, ]; - console.log(unstakablePercent, stakedPercent, unstakedPercent); - const stakableRow = stakableData.map((stakable) => { return (
{ const formReturn = useForm(); const { getValues } = formReturn; - const stakingAmount = getValues().stakingAmount; + const stakingAmountFormatted = getValues().stakingAmount; const isSupportedChain = useIsSupportedChain(); const { switchNetwork } = useSwitchNetwork(); @@ -38,25 +38,27 @@ export const StakingModal = () => { } = useTokenBalances(); // stakingAmount default is NaN. Wagmi hooks need to validate that stakingAmount exists - const validNumberInput = !!stakingAmount && Number(stakingAmount) > 0; + const validNumberInput = + !!stakingAmountFormatted && Number(stakingAmountFormatted) * 10 ** 4 > 0; const needsApproval = txType === TxType.STAKE && - Number(astAllowance) < Number(stakingAmount) && + Number(astAllowance) < Number(stakingAmountFormatted) * 10 ** 4 && validNumberInput; const canStake = txType === TxType.STAKE && !needsApproval && validNumberInput; const canUnstake = - Number(stakingAmount) <= Number(unstakableSastBalance) && + Number(stakingAmountFormatted) * 10 ** 4 <= Number(unstakableSastBalance) && txType === TxType.UNSTAKE && validNumberInput; const isInsufficientBalance = - txType === TxType.STAKE && stakingAmount - ? Number(stakingAmount) > Number(astBalance) - : Number(stakingAmount) > Number(unstakableSastBalance); + txType === TxType.STAKE && stakingAmountFormatted + ? Number(stakingAmountFormatted) * 10 ** 4 > Number(astBalance) + : Number(stakingAmountFormatted) * 10 ** 4 > + Number(unstakableSastBalance); const { writeAsync: approveAst, @@ -64,7 +66,7 @@ export const StakingModal = () => { reset: resetApproveAst, isLoading: approvalAwaitingSignature, } = useApproveAst({ - stakingAmount: Number(stakingAmount) || 0, + stakingAmount: Number(stakingAmountFormatted) || 0, enabled: needsApproval, }); @@ -74,7 +76,7 @@ export const StakingModal = () => { data: dataStakeAst, isLoading: stakeAwaitingSignature, } = useStakeAst({ - stakingAmount: Number(stakingAmount) || 0, + stakingAmount: Number(stakingAmountFormatted) || 0, enabled: canStake, }); @@ -84,7 +86,7 @@ export const StakingModal = () => { data: dataUnstakeSast, isLoading: unstakeAwaitingSignature, } = useUnstakeSast({ - unstakingAmount: Number(stakingAmount) || 0, + unstakingAmount: Number(stakingAmountFormatted) || 0, canUnstake: canUnstake, }); @@ -123,7 +125,7 @@ export const StakingModal = () => { insufficientBalance: isInsufficientBalance, }); - const isAmountInvalid = Number(stakingAmount) <= 0; + const isAmountInvalid = Number(stakingAmountFormatted) * 10 ** 4 <= 0; const isStakeButtonDisabled = isAmountInvalid || isInsufficientBalance; @@ -185,7 +187,7 @@ export const StakingModal = () => { successContent={ You successfully {verb}{" "} - {stakingAmount} AST + {stakingAmountFormatted} AST } failureContent={"Your transaction has failed"} From 1b134f6fe8dcc1d5a472974591cf56e1dc3044a8 Mon Sep 17 00:00:00 2001 From: Mike Starr Date: Fri, 6 Oct 2023 10:54:57 -0400 Subject: [PATCH 8/9] change variable names in useStakeAst and useUnstakeAst --- src/features/staking/StakingModal.tsx | 4 ++-- src/features/staking/hooks/useStakeAst.ts | 6 +++--- src/features/staking/hooks/useUnstakeSast.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/features/staking/StakingModal.tsx b/src/features/staking/StakingModal.tsx index dbbf5c3..44e8f73 100644 --- a/src/features/staking/StakingModal.tsx +++ b/src/features/staking/StakingModal.tsx @@ -76,7 +76,7 @@ export const StakingModal = () => { data: dataStakeAst, isLoading: stakeAwaitingSignature, } = useStakeAst({ - stakingAmount: Number(stakingAmountFormatted) || 0, + stakingAmountFormatted: Number(stakingAmountFormatted) || 0, enabled: canStake, }); @@ -86,7 +86,7 @@ export const StakingModal = () => { data: dataUnstakeSast, isLoading: unstakeAwaitingSignature, } = useUnstakeSast({ - unstakingAmount: Number(stakingAmountFormatted) || 0, + unstakingAmountFormatted: Number(stakingAmountFormatted) || 0, canUnstake: canUnstake, }); diff --git a/src/features/staking/hooks/useStakeAst.ts b/src/features/staking/hooks/useStakeAst.ts index 866aa42..3f82abb 100644 --- a/src/features/staking/hooks/useStakeAst.ts +++ b/src/features/staking/hooks/useStakeAst.ts @@ -5,10 +5,10 @@ import { useContractAddresses } from "../../../config/hooks/useContractAddress"; import { stakingAbi } from "../../../contracts/stakingAbi"; export const useStakeAst = ({ - stakingAmount, + stakingAmountFormatted, enabled = true, }: { - stakingAmount: number; + stakingAmountFormatted: number; enabled?: boolean; }) => { const [airSwapStaking] = useContractAddresses( @@ -19,7 +19,7 @@ export const useStakeAst = ({ }, ); - const stakingAmountConversion = new BigNumber(stakingAmount) + const stakingAmountConversion = new BigNumber(stakingAmountFormatted) .multipliedBy(10 ** 4) .integerValue() .toString(); diff --git a/src/features/staking/hooks/useUnstakeSast.ts b/src/features/staking/hooks/useUnstakeSast.ts index 2f96669..d95057f 100644 --- a/src/features/staking/hooks/useUnstakeSast.ts +++ b/src/features/staking/hooks/useUnstakeSast.ts @@ -10,10 +10,10 @@ import { stakingAbi } from "../../../contracts/stakingAbi"; * @param canUnstake - boolean value, true if unstakingAmount (stakingAmount) > 0 and if unstakigAmount (stakingAmount) <= sAST balance */ export const useUnstakeSast = ({ - unstakingAmount, + unstakingAmountFormatted, canUnstake, }: { - unstakingAmount: number; + unstakingAmountFormatted: number; canUnstake: boolean; }) => { const [airSwapStaking] = useContractAddresses( @@ -24,7 +24,7 @@ export const useUnstakeSast = ({ }, ); - const unstakingAmountConversion = new BigNumber(unstakingAmount) + const unstakingAmountConversion = new BigNumber(unstakingAmountFormatted) .multipliedBy(10 ** 4) .integerValue() .toString(); From 750ca0da2dc89e0c80ff70120496ba67b5879454 Mon Sep 17 00:00:00 2001 From: Mike Starr Date: Fri, 6 Oct 2023 11:03:16 -0400 Subject: [PATCH 9/9] fix var names in useApproveAst --- src/features/staking/StakingModal.tsx | 2 +- src/features/staking/hooks/useApproveAst.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/features/staking/StakingModal.tsx b/src/features/staking/StakingModal.tsx index 44e8f73..bf952e2 100644 --- a/src/features/staking/StakingModal.tsx +++ b/src/features/staking/StakingModal.tsx @@ -66,7 +66,7 @@ export const StakingModal = () => { reset: resetApproveAst, isLoading: approvalAwaitingSignature, } = useApproveAst({ - stakingAmount: Number(stakingAmountFormatted) || 0, + stakingAmountFormatted: Number(stakingAmountFormatted) || 0, enabled: needsApproval, }); diff --git a/src/features/staking/hooks/useApproveAst.ts b/src/features/staking/hooks/useApproveAst.ts index b6d6eca..660ddbc 100644 --- a/src/features/staking/hooks/useApproveAst.ts +++ b/src/features/staking/hooks/useApproveAst.ts @@ -5,10 +5,10 @@ import { useContractAddresses } from "../../../config/hooks/useContractAddress"; import { astAbi } from "../../../contracts/astAbi"; export const useApproveAst = ({ - stakingAmount, + stakingAmountFormatted, enabled = true, }: { - stakingAmount: number; + stakingAmountFormatted: number; enabled?: boolean; }) => { const [airSwapToken] = useContractAddresses([ContractTypes.AirSwapToken], { @@ -24,7 +24,7 @@ export const useApproveAst = ({ }, ); - const stakingAmountConversion = new BigNumber(stakingAmount) + const stakingAmountConversion = new BigNumber(stakingAmountFormatted) .multipliedBy(10 ** 4) .integerValue() .toString();