From 5a6b8a4d4430d25c8cc47ba2d9c4ee36e7208ae0 Mon Sep 17 00:00:00 2001 From: JayJay1024 Date: Wed, 13 Mar 2024 11:58:09 +0800 Subject: [PATCH] Fix deposit id type --- src/components/bond-more-deposit-modal.tsx | 13 +- src/components/bond-more-kton-modal.tsx | 11 +- src/components/bond-more-ring-modal.tsx | 13 +- src/components/records-bonded-tokens.tsx | 12 +- src/components/unbond-all-staked.tsx | 8 +- src/components/unbond-deposit-modal.tsx | 13 +- src/components/unbond-kton-modal.tsx | 11 +- src/components/unbond-ring-modal.tsx | 13 +- src/config/abi/staking-v2.json | 167 +++++++++++++++++++++ 9 files changed, 233 insertions(+), 28 deletions(-) create mode 100644 src/config/abi/staking-v2.json diff --git a/src/components/bond-more-deposit-modal.tsx b/src/components/bond-more-deposit-modal.tsx index f1ae3a3..da7cf19 100644 --- a/src/components/bond-more-deposit-modal.tsx +++ b/src/components/bond-more-deposit-modal.tsx @@ -6,6 +6,7 @@ import { ExtraPower } from "./balance-input"; import { useApp, useStaking } from "@/hooks"; import { notification } from "./notification"; import { writeContract, waitForTransaction } from "@wagmi/core"; +import { ChainID } from "@/types"; export default function BondMoreDepositModal({ commission, @@ -35,17 +36,21 @@ export default function BondMoreDepositModal({ ); const availableDeposits = deposits.filter(({ id }) => !stakedDeposits.includes(id)); - const { nativeToken, contract, explorer } = getChainConfig(activeChain); + const { nativeToken } = getChainConfig(activeChain); const handleBond = useCallback(async () => { setBusy(true); + const { contract, explorer } = getChainConfig(activeChain); try { - const contractAbi = (await import(`@/config/abi/${contract.staking.abiFile}`)).default; + const abi = + activeChain === ChainID.CRAB + ? (await import("@/config/abi/staking-v2.json")).default + : (await import(`@/config/abi/${contract.staking.abiFile}`)).default; const { hash } = await writeContract({ address: contract.staking.address, - abi: contractAbi, + abi, functionName: "stake", args: [0n, 0n, checkedDeposits], }); @@ -62,7 +67,7 @@ export default function BondMoreDepositModal({ } setBusy(false); - }, [explorer, contract.staking, checkedDeposits, onClose]); + }, [activeChain, checkedDeposits, onClose]); return ( { if ((ringBalance?.value || 0n) < inputAmount) { notification.warn({ description: "Your balance is insufficient." }); } else { setBusy(true); + const { contract, explorer } = getChainConfig(activeChain); try { - const contractAbi = (await import(`@/config/abi/${contract.staking.abiFile}`)).default; + const abi = + activeChain === ChainID.CRAB + ? (await import("@/config/abi/staking-v2.json")).default + : (await import(`@/config/abi/${contract.staking.abiFile}`)).default; const { hash } = await writeContract({ address: contract.staking.address, - abi: contractAbi, + abi, functionName: "stake", args: [inputAmount, 0n, []], }); @@ -53,7 +58,7 @@ export default function BondMoreRingModal({ setBusy(false); } - }, [contract.staking, explorer, inputAmount, ringBalance?.value, onClose]); + }, [activeChain, inputAmount, ringBalance?.value, onClose]); return ( stakedDeposits.includes(id)); - const { nativeToken, contract, explorer } = getChainConfig(activeChain); + const { nativeToken } = getChainConfig(activeChain); const handleUnbond = useCallback(async () => { setBusy(true); + const { contract, explorer } = getChainConfig(activeChain); try { - const contractAbi = (await import(`@/config/abi/${contract.staking.abiFile}`)).default; + const abi = + activeChain === ChainID.CRAB + ? (await import("@/config/abi/staking-v2.json")).default + : (await import(`@/config/abi/${contract.staking.abiFile}`)).default; const { hash } = await writeContract({ address: contract.staking.address, - abi: contractAbi, + abi, functionName: "unstake", args: [0n, 0n, checkedDeposits], }); @@ -62,7 +67,7 @@ export default function UnbondDepositModal({ } setBusy(false); - }, [explorer, contract.staking, checkedDeposits, onClose]); + }, [activeChain, checkedDeposits, onClose]); return ( { if (stakedRing < inputAmount) { @@ -32,13 +33,17 @@ export default function UnbondRingModal({ }); } else { setBusy(true); + const { contract, explorer } = getChainConfig(activeChain); try { - const contractAbi = (await import(`@/config/abi/${contract.staking.abiFile}`)).default; + const abi = + activeChain === ChainID.CRAB + ? (await import("@/config/abi/staking-v2.json")).default + : (await import(`@/config/abi/${contract.staking.abiFile}`)).default; const { hash } = await writeContract({ address: contract.staking.address, - abi: contractAbi, + abi, functionName: "unstake", args: [inputAmount, 0n, []], }); @@ -56,7 +61,7 @@ export default function UnbondRingModal({ setBusy(false); } - }, [explorer, contract.staking, stakedRing, inputAmount, nativeToken, onClose]); + }, [activeChain, stakedRing, inputAmount, nativeToken, onClose]); return (