Skip to content

Commit

Permalink
fix: add const file for magic number
Browse files Browse the repository at this point in the history
  • Loading branch information
Wagalidoom committed Sep 11, 2024
1 parent fbf7509 commit 4e89325
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
1 change: 0 additions & 1 deletion components/deposit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import useDeposit from "@/hooks/use-deposit";
import {
ArrowUturnLeftIcon,
InformationCircleIcon,
CheckIcon,
} from "@heroicons/react/20/solid";
import Image from "next/image";
Expand Down
5 changes: 3 additions & 2 deletions hooks/use-autoclaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getPublicClient } from "wagmi/actions";
import { config } from "@/wagmi";
import { fetchRegister, fetchUnregister } from "@/utils/fetchEvents";
import { parseUnits } from "viem";
import { SECOND_IN_DAY } from "@/utils/constants";

function useAutoclaim(contractConfig: ContractNetwork | undefined, address: `0x${string}` | undefined, chainId: number) {
const [isRegister, setIsRegister] = useState(false);
Expand Down Expand Up @@ -44,7 +45,7 @@ function useAutoclaim(contractConfig: ContractNetwork | undefined, address: `0x$
const register = useCallback(
async (days: number, amount: number) => {
if (contractConfig) {
const timeStamp = BigInt(days * 86400);
const timeStamp = BigInt(days * SECOND_IN_DAY);
writeContract({ address: contractConfig.addresses.claimRegistry, abi: claimRegistryABI, functionName: "register", args: [address || "0x0", timeStamp, parseUnits(amount.toString(), 18)] });
}
},
Expand All @@ -54,7 +55,7 @@ function useAutoclaim(contractConfig: ContractNetwork | undefined, address: `0x$
const updateConfig = useCallback(
async (days: number, amount: number) => {
if (contractConfig) {
const timeStamp = BigInt(days * 86400);
const timeStamp = BigInt(days * SECOND_IN_DAY);
writeContract({ address: contractConfig.addresses.claimRegistry, abi: claimRegistryABI, functionName: "updateConfig", args: [address || "0x0", timeStamp, parseUnits(amount.toString(), 18)] });
}
},
Expand Down
5 changes: 3 additions & 2 deletions hooks/use-dappnode-deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { loadCachedDeposits } from "@/utils/deposit";
import { getPublicClient } from "wagmi/actions";
import { config } from "@/wagmi";
import { fetchDeposit } from "@/utils/fetchEvents";
import { DEPOSIT_TOKEN_AMOUNT_OLD, MAX_BATCH_DEPOSIT } from "@/utils/constants";

export type DepositDataJson = {
pubkey: string;
Expand Down Expand Up @@ -141,14 +142,14 @@ function useDappnodeDeposit(contractConfig: ContractNetwork | undefined, address
// check if withdrawal credential start with 0x00
_isBatch = !wc.startsWith("00");

if (_isBatch && newDeposits.length > 128) {
if (_isBatch && newDeposits.length > MAX_BATCH_DEPOSIT) {
throw Error(
"Number of validators exceeds the maximum batch size of 128. Please upload a file with 128 or fewer validators."
);
}

if (
!newDeposits.every((d) => BigInt(d.amount) === BigInt(32000000000))
!newDeposits.every((d) => BigInt(d.amount) === BigInt(DEPOSIT_TOKEN_AMOUNT_OLD))
) {
throw Error("Amount should be exactly 32 tokens for deposits.");
}
Expand Down
5 changes: 3 additions & 2 deletions hooks/use-deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { getPublicClient } from "wagmi/actions";
import { config } from "@/wagmi";
import { fetchDeposit } from "@/utils/fetchEvents";
import useBalance from "./use-balance";
import { DEPOSIT_TOKEN_AMOUNT_OLD, MAX_BATCH_DEPOSIT } from "@/utils/constants";

const depositAmountBN = parseUnits("1", 18);

Expand Down Expand Up @@ -120,14 +121,14 @@ function useDeposit(contractConfig: ContractNetwork | undefined, address: `0x${s
// check if withdrawal credential start with 0x00
_isBatch = !wc.startsWith("00");

if (_isBatch && newDeposits.length > 128) {
if (_isBatch && newDeposits.length > MAX_BATCH_DEPOSIT) {
throw Error(
"Number of validators exceeds the maximum batch size of 128. Please upload a file with 128 or fewer validators."
);
}

if (
!newDeposits.every((d) => BigInt(d.amount) === BigInt(32000000000))
!newDeposits.every((d) => BigInt(d.amount) === BigInt(DEPOSIT_TOKEN_AMOUNT_OLD))
) {
throw Error("Amount should be exactly 32 tokens for deposits.");
}
Expand Down
3 changes: 3 additions & 0 deletions utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const MAX_BATCH_DEPOSIT = 128;
export const DEPOSIT_TOKEN_AMOUNT_OLD = 32000000000;
export const SECOND_IN_DAY = 86400;

0 comments on commit 4e89325

Please sign in to comment.