From 81bed7ab09610e1e837d33981eaea0ce4d772637 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 29 Apr 2024 11:28:45 +0800 Subject: [PATCH] Fix KTON param removement (#90) --- src/components/bond-more-deposit-modal.tsx | 2 +- src/components/bond-more-kton-modal.tsx | 34 +-------- src/components/bond-more-ring-modal.tsx | 2 +- src/components/records-bonded-tokens.tsx | 87 ++-------------------- src/components/unbond-all-staked.tsx | 6 +- src/components/unbond-deposit-modal.tsx | 2 +- src/components/unbond-kton-modal.tsx | 39 +--------- src/components/unbond-ring-modal.tsx | 2 +- src/config/abi/staking.json | 47 ------------ 9 files changed, 17 insertions(+), 204 deletions(-) diff --git a/src/components/bond-more-deposit-modal.tsx b/src/components/bond-more-deposit-modal.tsx index 47d5e0b..d7f6802 100644 --- a/src/components/bond-more-deposit-modal.tsx +++ b/src/components/bond-more-deposit-modal.tsx @@ -39,7 +39,7 @@ export default function BondMoreDepositModal({ address: contract.staking.address, abi: (await import(`@/config/abi/${contract.staking.abiFile}`)).default, functionName: "stake", - args: [0n, 0n, checkedDeposits], + args: [0n, checkedDeposits], }); const receipt = await waitForTransaction({ hash }); diff --git a/src/components/bond-more-kton-modal.tsx b/src/components/bond-more-kton-modal.tsx index 6860b66..d2f8a3b 100644 --- a/src/components/bond-more-kton-modal.tsx +++ b/src/components/bond-more-kton-modal.tsx @@ -1,10 +1,8 @@ -import { getChainConfig, notifyTransaction } from "@/utils"; +import { getChainConfig } from "@/utils"; import BondMoreTokenModal from "./bond-more-token-modal"; import { useApp } from "@/hooks"; import { useAccount, useBalance } from "wagmi"; import { useCallback, useState } from "react"; -import { notification } from "./notification"; -import { writeContract, waitForTransaction } from "@wagmi/core"; export default function BondMoreKtonModal({ isOpen, @@ -22,35 +20,7 @@ export default function BondMoreKtonModal({ const { ktonToken } = getChainConfig(activeChain); const { data: ktonBalance } = useBalance({ address, token: ktonToken?.address, watch: true }); - const handleBond = useCallback(async () => { - if ((ktonBalance?.value || 0n) < inputAmount) { - notification.warn({ description: "Your balance is insufficient." }); - } else { - setBusy(true); - const { contract, explorer } = getChainConfig(activeChain); - - try { - const { hash } = await writeContract({ - address: contract.staking.address, - abi: (await import(`@/config/abi/${contract.staking.abiFile}`)).default, - functionName: "stake", - args: [0n, inputAmount, []], - }); - const receipt = await waitForTransaction({ hash }); - - if (receipt.status === "success") { - setInputAmount(0n); - onClose(); - } - notifyTransaction(receipt, explorer); - } catch (err) { - console.error(err); - notification.error({ description: (err as Error).message }); - } - - setBusy(false); - } - }, [activeChain, inputAmount, ktonBalance?.value, onClose]); + const handleBond = useCallback(() => setBusy(false), []); return ( ktonToken && ( diff --git a/src/components/bond-more-ring-modal.tsx b/src/components/bond-more-ring-modal.tsx index 7cd1c4e..2657f8d 100644 --- a/src/components/bond-more-ring-modal.tsx +++ b/src/components/bond-more-ring-modal.tsx @@ -42,7 +42,7 @@ export default function BondMoreRingModal({ address: contract.staking.address, abi: (await import(`@/config/abi/${contract.staking.abiFile}`)).default, functionName: "stake", - args: [inputAmount, 0n, []], + args: [inputAmount, []], }); const receipt = await waitForTransaction({ hash }); diff --git a/src/components/records-bonded-tokens.tsx b/src/components/records-bonded-tokens.tsx index 466c35c..87f4057 100644 --- a/src/components/records-bonded-tokens.tsx +++ b/src/components/records-bonded-tokens.tsx @@ -1,6 +1,6 @@ import { useApp, useDip6 } from "@/hooks"; import { StakingRecordsDataSource } from "@/types"; -import { formatBlanace, getChainConfig, notifyTransaction } from "@/utils"; +import { formatBlanace, getChainConfig } from "@/utils"; import UnbondingTokenTooltip from "./unbonding-token-tooltip"; import UnbondingDepositTooltip from "./unbonding-deposit-tooltip"; import { useCallback, useState } from "react"; @@ -12,93 +12,18 @@ import UnbondRingModal from "./unbond-ring-modal"; import UnbondKtonModal from "./unbond-kton-modal"; import UnbondDepositModal from "./unbond-deposit-modal"; import Image from "next/image"; -import { writeContract, waitForTransaction } from "@wagmi/core"; -import { notification } from "./notification"; export default function RecordsBondedTokens({ row }: { row: StakingRecordsDataSource }) { - const [ringBusy, setRingBusy] = useState(false); - const [depositBusy, setDepositBusy] = useState(false); - const [ktonBusy, setKtonBusy] = useState(false); + const [ringBusy, _setRingBusy] = useState(false); + const [depositBusy, _setDepositBusy] = useState(false); + const [ktonBusy, _setKtonBusy] = useState(false); const { activeChain } = useApp(); const { isDip6Implemented } = useDip6(); const { nativeToken, ktonToken } = getChainConfig(activeChain); - const handleCancelUnbonding = useCallback( - async (ring: bigint, kton: bigint, depositIds: number[]) => { - if (ring > 0) { - setRingBusy(true); - } else if (kton > 0) { - setKtonBusy(true); - } else if (depositIds.length) { - setDepositBusy(true); - } - const { contract, explorer } = getChainConfig(activeChain); - - try { - const { hash } = await writeContract({ - address: contract.staking.address, - abi: (await import(`@/config/abi/${contract.staking.abiFile}`)).default, - functionName: "restake", - args: [ring, depositIds], - }); - const receipt = await waitForTransaction({ hash }); - - notifyTransaction(receipt, explorer); - } catch (err) { - console.error(err); - notification.error({ description: (err as Error).message }); - } - - if (ring > 0) { - setRingBusy(false); - } else if (kton > 0) { - setKtonBusy(false); - } else if (depositIds.length) { - setDepositBusy(false); - } - }, - [activeChain] - ); - - const handleRelease = useCallback( - async (type: "ring" | "kton" | "deposit") => { - if (type === "ring") { - setRingBusy(true); - } else if (type === "kton") { - setKtonBusy(true); - } else { - setDepositBusy(true); - } - const { contract, explorer } = getChainConfig(activeChain); - - try { - const contractAbi = (await import(`@/config/abi/${contract.staking.abiFile}`)).default; - - const { hash } = await writeContract({ - address: contract.staking.address, - abi: contractAbi, - functionName: "claim", - args: [], - }); - const receipt = await waitForTransaction({ hash }); - - notifyTransaction(receipt, explorer); - } catch (err) { - console.error(err); - notification.error({ description: (err as Error).message }); - } - - if (type === "ring") { - setRingBusy(false); - } else if (type === "kton") { - setKtonBusy(false); - } else { - setDepositBusy(false); - } - }, - [activeChain] - ); + const handleCancelUnbonding = useCallback(async (_ring: bigint, _kton: bigint, _depositIds: number[]) => {}, []); + const handleRelease = useCallback(async (_type: "ring" | "kton" | "deposit") => {}, []); return (
diff --git a/src/components/unbond-all-staked.tsx b/src/components/unbond-all-staked.tsx index 28268da..0780b4c 100644 --- a/src/components/unbond-all-staked.tsx +++ b/src/components/unbond-all-staked.tsx @@ -6,7 +6,7 @@ import { notification } from "./notification"; import { getChainConfig, notifyTransaction } from "@/utils"; export default function UnbondAllStaked() { - const { stakedRing, stakedKton, stakedDeposits } = useStaking(); + const { stakedRing, stakedDeposits } = useStaking(); const { activeChain } = useApp(); const [busy, setBusy] = useState(false); @@ -19,7 +19,7 @@ export default function UnbondAllStaked() { address: contract.staking.address, abi: (await import(`@/config/abi/${contract.staking.abiFile}`)).default, functionName: "unstake", - args: [stakedRing, stakedKton, stakedDeposits], + args: [stakedRing, stakedDeposits], }); const receipt = await waitForTransaction({ hash }); @@ -30,7 +30,7 @@ export default function UnbondAllStaked() { } setBusy(false); - }, [activeChain, stakedRing, stakedKton, stakedDeposits]); + }, [activeChain, stakedRing, stakedDeposits]); return ( diff --git a/src/components/unbond-deposit-modal.tsx b/src/components/unbond-deposit-modal.tsx index fead4f1..dd0fb1f 100644 --- a/src/components/unbond-deposit-modal.tsx +++ b/src/components/unbond-deposit-modal.tsx @@ -39,7 +39,7 @@ export default function UnbondDepositModal({ address: contract.staking.address, abi: (await import(`@/config/abi/${contract.staking.abiFile}`)).default, functionName: "unstake", - args: [0n, 0n, checkedDeposits], + args: [0n, checkedDeposits], }); const receipt = await waitForTransaction({ hash }); diff --git a/src/components/unbond-kton-modal.tsx b/src/components/unbond-kton-modal.tsx index e05df15..b8a8ab0 100644 --- a/src/components/unbond-kton-modal.tsx +++ b/src/components/unbond-kton-modal.tsx @@ -1,9 +1,7 @@ -import { formatBlanace, getChainConfig, notifyTransaction } from "@/utils"; +import { getChainConfig } from "@/utils"; import UnbondTokenModal from "./unbond-token-modal"; import { useApp, useStaking } from "@/hooks"; import { useCallback, useState } from "react"; -import { notification } from "./notification"; -import { writeContract, waitForTransaction } from "@wagmi/core"; export default function UnbondKtonModal({ isOpen, @@ -20,40 +18,7 @@ export default function UnbondKtonModal({ const { ktonToken } = getChainConfig(activeChain); - const handleUnbond = useCallback(async () => { - if (stakedKton < inputAmount) { - notification.warn({ - description: `You can't unbond more than ${formatBlanace(stakedKton, ktonToken?.decimals, { - precision: 4, - keepZero: false, - })} ${ktonToken?.symbol}`, - }); - } else { - setBusy(true); - const { contract, explorer } = getChainConfig(activeChain); - - try { - const { hash } = await writeContract({ - address: contract.staking.address, - abi: (await import(`@/config/abi/${contract.staking.abiFile}`)).default, - functionName: "unstake", - args: [0n, inputAmount, []], - }); - const receipt = await waitForTransaction({ hash }); - - if (receipt.status === "success") { - setInputAmount(0n); - onClose(); - } - notifyTransaction(receipt, explorer); - } catch (err) { - console.error(err); - notification.error({ description: (err as Error).message }); - } - - setBusy(false); - } - }, [activeChain, stakedKton, inputAmount, ktonToken, onClose]); + const handleUnbond = useCallback(() => setBusy(false), []); return ( ktonToken && ( diff --git a/src/components/unbond-ring-modal.tsx b/src/components/unbond-ring-modal.tsx index bf76aab..60399e4 100644 --- a/src/components/unbond-ring-modal.tsx +++ b/src/components/unbond-ring-modal.tsx @@ -45,7 +45,7 @@ export default function UnbondRingModal({ address: contract.staking.address, abi: (await import(`@/config/abi/${contract.staking.abiFile}`)).default, functionName: "unstake", - args: [inputAmount, 0n, []], + args: [inputAmount, []], }); const receipt = await waitForTransaction({ hash }); diff --git a/src/config/abi/staking.json b/src/config/abi/staking.json index 9dbec17..6377d62 100644 --- a/src/config/abi/staking.json +++ b/src/config/abi/staking.json @@ -12,19 +12,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [], - "name": "claim", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { @@ -95,35 +82,6 @@ "type": "uint16[]" } ], - "name": "restake", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "ringAmount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "ktonAmount", - "type": "uint256" - }, - { - "internalType": "uint16[]", - "name": "depositIds", - "type": "uint16[]" - } - ], "name": "stake", "outputs": [ { @@ -142,11 +100,6 @@ "name": "ringAmount", "type": "uint256" }, - { - "internalType": "uint256", - "name": "ktonAmount", - "type": "uint256" - }, { "internalType": "uint16[]", "name": "depositIds",