Skip to content

Commit

Permalink
Fix KTON param removement (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJay1024 authored Apr 29, 2024
1 parent 1b5bd25 commit 81bed7a
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 204 deletions.
2 changes: 1 addition & 1 deletion src/components/bond-more-deposit-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
34 changes: 2 additions & 32 deletions src/components/bond-more-kton-modal.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/bond-more-ring-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
87 changes: 6 additions & 81 deletions src/components/records-bonded-tokens.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 (
<div className="flex flex-col">
Expand Down
6 changes: 3 additions & 3 deletions src/components/unbond-all-staked.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 });

Expand All @@ -30,7 +30,7 @@ export default function UnbondAllStaked() {
}

setBusy(false);
}, [activeChain, stakedRing, stakedKton, stakedDeposits]);
}, [activeChain, stakedRing, stakedDeposits]);

return (
<RecordsActionButton busy={busy} onClick={handleUnbond}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/unbond-deposit-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
39 changes: 2 additions & 37 deletions src/components/unbond-kton-modal.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/unbond-ring-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
47 changes: 0 additions & 47 deletions src/config/abi/staking.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "claim",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -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": [
{
Expand All @@ -142,11 +100,6 @@
"name": "ringAmount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "ktonAmount",
"type": "uint256"
},
{
"internalType": "uint16[]",
"name": "depositIds",
Expand Down

0 comments on commit 81bed7a

Please sign in to comment.