Skip to content

Commit

Permalink
Fix deposit id type (#78)
Browse files Browse the repository at this point in the history
* Fix deposit id type

* Push to main branch triggle stging deploy

* Remove ci.yml

* Fix available deposits to bond

* Improve unbonding deposits id display
  • Loading branch information
JayJay1024 authored Mar 13, 2024
1 parent 99b2370 commit be17fa2
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 65 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/ci.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/deploy-stg.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Deploy staging

on:
push:
branches: [main]
workflow_dispatch:

jobs:
Expand Down
17 changes: 11 additions & 6 deletions src/components/bond-more-deposit-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -16,7 +17,7 @@ export default function BondMoreDepositModal({
isOpen: boolean;
onClose?: () => void;
}) {
const { deposits, stakedDeposits, calcExtraPower } = useStaking();
const { deposits, calcExtraPower } = useStaking();
const { activeChain } = useApp();

const [checkedDeposits, setCheckedDeposits] = useState<number[]>([]);
Expand All @@ -34,18 +35,22 @@ export default function BondMoreDepositModal({
[deposits, commission, checkedDeposits, calcExtraPower]
);

const availableDeposits = deposits.filter(({ id }) => !stakedDeposits.includes(id));
const { nativeToken, contract, explorer } = getChainConfig(activeChain);
const availableDeposits = deposits.filter(({ inUse }) => !inUse);
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],
});
Expand All @@ -62,7 +67,7 @@ export default function BondMoreDepositModal({
}

setBusy(false);
}, [explorer, contract.staking, checkedDeposits, onClose]);
}, [activeChain, checkedDeposits, onClose]);

return (
<Modal
Expand Down
11 changes: 8 additions & 3 deletions src/components/bond-more-kton-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useAccount, useBalance } from "wagmi";
import { useCallback, useState } from "react";
import { notification } from "./notification";
import { writeContract, waitForTransaction } from "@wagmi/core";
import { ChainID } from "@/types";

export default function BondMoreKtonModal({
commission,
Expand All @@ -30,13 +31,17 @@ export default function BondMoreKtonModal({
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: [0n, inputAmount, []],
});
Expand All @@ -54,7 +59,7 @@ export default function BondMoreKtonModal({

setBusy(false);
}
}, [contract.staking, explorer, inputAmount, ktonBalance?.value, onClose]);
}, [activeChain, inputAmount, ktonBalance?.value, onClose]);

return (
ktonToken && (
Expand Down
13 changes: 9 additions & 4 deletions src/components/bond-more-ring-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useApp, useStaking } from "@/hooks";
import { useCallback, useState } from "react";
import { notification } from "./notification";
import { writeContract, waitForTransaction } from "@wagmi/core";
import { ChainID } from "@/types";

export default function BondMoreRingModal({
commission,
Expand All @@ -23,20 +24,24 @@ export default function BondMoreRingModal({
const [inputAmount, setInputAmount] = useState(0n);
const [busy, setBusy] = useState(false);

const { nativeToken, contract, explorer } = getChainConfig(activeChain);
const { nativeToken } = getChainConfig(activeChain);

const handleBond = useCallback(async () => {
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, []],
});
Expand All @@ -53,7 +58,7 @@ export default function BondMoreRingModal({

setBusy(false);
}
}, [contract.staking, explorer, inputAmount, ringBalance?.value, onClose]);
}, [activeChain, inputAmount, ringBalance?.value, onClose]);

return (
<BondMoreTokenModal
Expand Down
12 changes: 8 additions & 4 deletions src/components/records-bonded-tokens.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useApp } from "@/hooks";
import { StakingRecordsDataSource } from "@/types";
import { ChainID, StakingRecordsDataSource } from "@/types";
import { formatBlanace, getChainConfig, notifyTransaction } from "@/utils";
import UnbondingTokenTooltip from "./unbonding-token-tooltip";
import UnbondingDepositTooltip from "./unbonding-deposit-tooltip";
Expand Down Expand Up @@ -35,13 +35,17 @@ export default function RecordsBondedTokens({ row }: { row: StakingRecordsDataSo
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 args = activeChain === ChainID.CRAB ? [ring, depositIds] : [ring, kton, depositIds];

const { hash } = await writeContract({
address: contract.staking.address,
abi: contractAbi,
abi,
functionName: "restake",
args: [ring, kton, depositIds],
args,
});
const receipt = await waitForTransaction({ hash });

Expand Down
8 changes: 6 additions & 2 deletions src/components/unbond-all-staked.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useCallback, useState } from "react";
import { writeContract, waitForTransaction } from "@wagmi/core";
import { notification } from "./notification";
import { getChainConfig, notifyTransaction } from "@/utils";
import { ChainID } from "@/types";

export default function UnbondAllStaked() {
const { stakedRing, stakedKton, stakedDeposits } = useStaking();
Expand All @@ -15,11 +16,14 @@ export default function UnbondAllStaked() {
setBusy(true);

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: [stakedRing, stakedKton, stakedDeposits],
});
Expand Down
13 changes: 9 additions & 4 deletions src/components/unbond-deposit-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 UnbondDepositModal({
commission,
Expand Down Expand Up @@ -35,17 +36,21 @@ export default function UnbondDepositModal({
);

const availableDeposits = deposits.filter(({ id }) => 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],
});
Expand All @@ -62,7 +67,7 @@ export default function UnbondDepositModal({
}

setBusy(false);
}, [explorer, contract.staking, checkedDeposits, onClose]);
}, [activeChain, checkedDeposits, onClose]);

return (
<Modal
Expand Down
11 changes: 8 additions & 3 deletions src/components/unbond-kton-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useApp, useStaking } from "@/hooks";
import { useCallback, useState } from "react";
import { notification } from "./notification";
import { writeContract, waitForTransaction } from "@wagmi/core";
import { ChainID } from "@/types";

export default function UnbondKtonModal({
commission,
Expand Down Expand Up @@ -32,13 +33,17 @@ export default function UnbondKtonModal({
});
} 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: [0n, inputAmount, []],
});
Expand All @@ -56,7 +61,7 @@ export default function UnbondKtonModal({

setBusy(false);
}
}, [explorer, contract.staking, stakedKton, inputAmount, ktonToken, onClose]);
}, [activeChain, stakedKton, inputAmount, ktonToken, onClose]);

return (
ktonToken && (
Expand Down
13 changes: 9 additions & 4 deletions src/components/unbond-ring-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useApp, useStaking } from "@/hooks";
import { useCallback, useState } from "react";
import { notification } from "./notification";
import { writeContract, waitForTransaction } from "@wagmi/core";
import { ChainID } from "@/types";

export default function UnbondRingModal({
commission,
Expand All @@ -20,7 +21,7 @@ export default function UnbondRingModal({
const [inputAmount, setInputAmount] = useState(0n);
const [busy, setBusy] = useState(false);

const { nativeToken, contract, explorer } = getChainConfig(activeChain);
const { nativeToken } = getChainConfig(activeChain);

const handleUnbond = useCallback(async () => {
if (stakedRing < inputAmount) {
Expand All @@ -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, []],
});
Expand All @@ -56,7 +61,7 @@ export default function UnbondRingModal({

setBusy(false);
}
}, [explorer, contract.staking, stakedRing, inputAmount, nativeToken, onClose]);
}, [activeChain, stakedRing, inputAmount, nativeToken, onClose]);

return (
<UnbondTokenModal
Expand Down
4 changes: 2 additions & 2 deletions src/components/unbonding-deposit-tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function UnbondingDeposit({ unbondings, token, onCancelUnbonding, onRelease }: P
key={`${index}${depositId}${amount.toString()}${expiredAtBlock}${expiredTimestamp}`}
className="text-xs font-light text-white"
>
{`#${index + 1} ${formatBlanace(amount, token.decimals, { keepZero: false })} Deposit ${
{`#${depositId} ${formatBlanace(amount, token.decimals, { keepZero: false })} Deposit ${
token.symbol
} is unbonding and will be released to deposit in ${formatDistanceStrict(
expiredTimestamp,
Expand All @@ -75,7 +75,7 @@ function UnbondingDeposit({ unbondings, token, onCancelUnbonding, onRelease }: P
key={`${index}${depositId}${amount.toString()}${expiredAtBlock}${expiredTimestamp}`}
className="text-xs font-bold text-white"
>
{`#${index + 1} ${formatBlanace(amount, token.decimals, { keepZero: false })} ${
{`#${depositId} ${formatBlanace(amount, token.decimals, { keepZero: false })} ${
token.symbol
} has complete the unbonding exit delay period. `}
<EnsureMatchNetworkButton className="text-primary" onClick={() => onRelease("deposit")}>
Expand Down
Loading

0 comments on commit be17fa2

Please sign in to comment.