- {children}{" "}
+ {children}
{(onCancel || onOk) && (
<>
diff --git a/src/components/records-bonded-tokens.tsx b/src/components/records-bonded-tokens.tsx
index e2e6df6..3a27b11 100644
--- a/src/components/records-bonded-tokens.tsx
+++ b/src/components/records-bonded-tokens.tsx
@@ -1,5 +1,5 @@
-import { useApp } from "@/hooks";
-import { ChainID, StakingRecordsDataSource } from "@/types";
+import { useApp, useIsStakingV2 } from "@/hooks";
+import { StakingRecordsDataSource } from "@/types";
import { formatBlanace, getChainConfig, notifyTransaction } from "@/utils";
import UnbondingTokenTooltip from "./unbonding-token-tooltip";
import UnbondingDepositTooltip from "./unbonding-deposit-tooltip";
@@ -12,14 +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";
+import { usePublicClient, useWalletClient } from "wagmi";
export default function RecordsBondedTokens({ row }: { row: StakingRecordsDataSource }) {
const [ringBusy, setRingBusy] = useState(false);
const [depositBusy, setDepositBusy] = useState(false);
const [ktonBusy, setKtonBusy] = useState(false);
+ const publicClient = usePublicClient();
+ const { data: walletClient } = useWalletClient();
+
+ const isStakingV2 = useIsStakingV2();
const { activeChain } = useApp();
const { nativeToken, ktonToken } = getChainConfig(activeChain);
@@ -34,25 +38,26 @@ export default function RecordsBondedTokens({ row }: { row: StakingRecordsDataSo
}
const { contract, explorer } = getChainConfig(activeChain);
- try {
- const abi =
- activeChain === ChainID.CRAB
+ if (walletClient && publicClient) {
+ try {
+ const abi = isStakingV2
? (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];
+ : (await import("@/config/abi/staking.json")).default;
+ const args = isStakingV2 ? [ring, depositIds] : [ring, kton, depositIds];
- const { hash } = await writeContract({
- address: contract.staking.address,
- abi,
- functionName: "restake",
- args,
- });
- const receipt = await waitForTransaction({ hash });
+ const hash = await walletClient.writeContract({
+ address: contract.staking.address,
+ abi,
+ functionName: "restake",
+ args,
+ });
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
- notifyTransaction(receipt, explorer);
- } catch (err) {
- console.error(err);
- notification.error({ description: (err as Error).message });
+ notifyTransaction(receipt, explorer);
+ } catch (err) {
+ console.error(err);
+ notification.error({ description: (err as Error).message });
+ }
}
if (ring > 0) {
@@ -63,7 +68,7 @@ export default function RecordsBondedTokens({ row }: { row: StakingRecordsDataSo
setDepositBusy(false);
}
},
- [activeChain]
+ [activeChain, isStakingV2, walletClient, publicClient]
);
const handleRelease = useCallback(
@@ -77,21 +82,21 @@ export default function RecordsBondedTokens({ row }: { row: StakingRecordsDataSo
}
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 });
+ if (walletClient && publicClient) {
+ try {
+ const hash = await walletClient.writeContract({
+ address: contract.staking.address,
+ abi: (await import(`@/config/abi/${contract.staking.abiFile}`)).default,
+ functionName: "claim",
+ args: [],
+ });
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
- notifyTransaction(receipt, explorer);
- } catch (err) {
- console.error(err);
- notification.error({ description: (err as Error).message });
+ notifyTransaction(receipt, explorer);
+ } catch (err) {
+ console.error(err);
+ notification.error({ description: (err as Error).message });
+ }
}
if (type === "ring") {
@@ -102,7 +107,7 @@ export default function RecordsBondedTokens({ row }: { row: StakingRecordsDataSo
setDepositBusy(false);
}
},
- [activeChain]
+ [activeChain, walletClient, publicClient]
);
return (
diff --git a/src/components/records-select-collator.tsx b/src/components/records-select-collator.tsx
index 2d59519..9c4909f 100644
--- a/src/components/records-select-collator.tsx
+++ b/src/components/records-select-collator.tsx
@@ -1,10 +1,10 @@
import { useApp, useStaking } from "@/hooks";
import { getChainConfig, notifyTransaction } from "@/utils";
import { useCallback, useState } from "react";
-import { writeContract, waitForTransaction } from "@wagmi/core";
import { notification } from "./notification";
import RecordsActionButton from "./records-action-button";
import CollatorSelectModal from "./collator-select-modal";
+import { usePublicClient, useWalletClient } from "wagmi";
export default function RecordsSelectCollator({ text }: { text: string }) {
const [isOpen, setIsOpen] = useState(false);
@@ -12,35 +12,38 @@ export default function RecordsSelectCollator({ text }: { text: string }) {
const { activeChain } = useApp();
const { updateNominatorCollators } = useStaking();
+ const publicClient = usePublicClient();
+ const { data: walletClient } = useWalletClient();
+
const handleConfirm = useCallback(
async (collator: string) => {
setBusy(true);
setIsOpen(false);
const chainConfig = getChainConfig(activeChain);
- try {
- const contractAbi = (await import(`@/config/abi/${chainConfig.contract.staking.abiFile}`)).default;
-
- const { hash } = await writeContract({
- address: chainConfig.contract.staking.address,
- abi: contractAbi,
- functionName: "nominate",
- args: [collator],
- });
- const receipt = await waitForTransaction({ hash });
+ if (walletClient && publicClient) {
+ try {
+ const hash = await walletClient.writeContract({
+ address: chainConfig.contract.staking.address,
+ abi: (await import(`@/config/abi/${chainConfig.contract.staking.abiFile}`)).default,
+ functionName: "nominate",
+ args: [collator],
+ });
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
- if (receipt.status === "success") {
- updateNominatorCollators();
+ if (receipt.status === "success") {
+ updateNominatorCollators();
+ }
+ notifyTransaction(receipt, chainConfig.explorer);
+ } catch (err) {
+ console.error(err);
+ notification.error({ description: (err as Error).message });
}
- notifyTransaction(receipt, chainConfig.explorer);
- } catch (err) {
- console.error(err);
- notification.error({ description: (err as Error).message });
}
setBusy(false);
},
- [activeChain, updateNominatorCollators]
+ [activeChain, walletClient, publicClient, updateNominatorCollators]
);
return (
diff --git a/src/components/unbond-all-staked.tsx b/src/components/unbond-all-staked.tsx
index 1797f2e..77cd914 100644
--- a/src/components/unbond-all-staked.tsx
+++ b/src/components/unbond-all-staked.tsx
@@ -1,42 +1,45 @@
import { useApp, useStaking } from "@/hooks";
import RecordsActionButton from "./records-action-button";
import { useCallback, useState } from "react";
-import { writeContract, waitForTransaction } from "@wagmi/core";
import { notification } from "./notification";
import { getChainConfig, notifyTransaction } from "@/utils";
-import { ChainID } from "@/types";
+import { usePublicClient, useWalletClient } from "wagmi";
export default function UnbondAllStaked() {
- const { stakedRing, stakedKton, stakedDeposits } = useStaking();
+ const { stakedRing, stakedKton, stakedDeposits, isStakingV2 } = useStaking();
const { activeChain } = useApp();
const [busy, setBusy] = useState(false);
+ const publicClient = usePublicClient();
+ const { data: walletClient } = useWalletClient();
+
const handleUnbond = useCallback(async () => {
const { contract, explorer } = getChainConfig(activeChain);
setBusy(true);
- try {
- const abi =
- activeChain === ChainID.CRAB
+ if (walletClient && publicClient) {
+ try {
+ const abi = isStakingV2
? (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,
- functionName: "unstake",
- args: [stakedRing, stakedKton, stakedDeposits],
- });
- const receipt = await waitForTransaction({ hash });
-
- notifyTransaction(receipt, explorer);
- } catch (err) {
- console.error(err);
- notification.error({ description: (err as Error).message });
+ : (await import("@/config/abi/staking.json")).default;
+
+ const hash = await walletClient.writeContract({
+ address: contract.staking.address,
+ abi,
+ functionName: "unstake",
+ args: [stakedRing, stakedKton, stakedDeposits],
+ });
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
+
+ notifyTransaction(receipt, explorer);
+ } catch (err) {
+ console.error(err);
+ notification.error({ description: (err as Error).message });
+ }
}
setBusy(false);
- }, [activeChain, stakedRing, stakedKton, stakedDeposits]);
+ }, [activeChain, stakedRing, stakedKton, stakedDeposits, isStakingV2, walletClient, publicClient]);
return (
diff --git a/src/components/unbond-deposit-modal.tsx b/src/components/unbond-deposit-modal.tsx
index 2d08852..ca4513d 100644
--- a/src/components/unbond-deposit-modal.tsx
+++ b/src/components/unbond-deposit-modal.tsx
@@ -5,8 +5,7 @@ import { commissionWeightedPower, formatBlanace, getChainConfig, notifyTransacti
import { ExtraPower } from "./balance-input";
import { useApp, useStaking } from "@/hooks";
import { notification } from "./notification";
-import { writeContract, waitForTransaction } from "@wagmi/core";
-import { ChainID } from "@/types";
+import { usePublicClient, useWalletClient } from "wagmi";
export default function UnbondDepositModal({
commission,
@@ -17,12 +16,15 @@ export default function UnbondDepositModal({
isOpen: boolean;
onClose?: () => void;
}) {
- const { deposits, stakedDeposits, calcExtraPower } = useStaking();
+ const { deposits, stakedDeposits, isStakingV2, calcExtraPower } = useStaking();
const { activeChain } = useApp();
const [checkedDeposits, setCheckedDeposits] = useState([]);
const [busy, setBusy] = useState(false);
+ const publicClient = usePublicClient();
+ const { data: walletClient } = useWalletClient();
+
const extraPower = useMemo(
() =>
commissionWeightedPower(
@@ -42,32 +44,33 @@ export default function UnbondDepositModal({
setBusy(true);
const { contract, explorer } = getChainConfig(activeChain);
- try {
- const abi =
- activeChain === ChainID.CRAB
+ if (walletClient && publicClient) {
+ try {
+ const abi = isStakingV2
? (await import("@/config/abi/staking-v2.json")).default
- : (await import(`@/config/abi/${contract.staking.abiFile}`)).default;
+ : (await import("@/config/abi/staking.json")).default;
- const { hash } = await writeContract({
- address: contract.staking.address,
- abi,
- functionName: "unstake",
- args: [0n, 0n, checkedDeposits],
- });
- const receipt = await waitForTransaction({ hash });
+ const hash = await walletClient.writeContract({
+ address: contract.staking.address,
+ abi,
+ functionName: "unstake",
+ args: [0n, 0n, checkedDeposits],
+ });
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
- if (receipt.status === "success") {
- setCheckedDeposits([]);
- onClose();
+ if (receipt.status === "success") {
+ setCheckedDeposits([]);
+ onClose();
+ }
+ notifyTransaction(receipt, explorer);
+ } catch (err) {
+ console.error(err);
+ notification.error({ description: (err as Error).message });
}
- notifyTransaction(receipt, explorer);
- } catch (err) {
- console.error(err);
- notification.error({ description: (err as Error).message });
}
setBusy(false);
- }, [activeChain, checkedDeposits, onClose]);
+ }, [activeChain, checkedDeposits, isStakingV2, walletClient, publicClient, onClose]);
return (
void;
}) {
const { activeChain } = useApp();
- const { stakedKton, calcExtraPower } = useStaking();
+ const { stakedKton, isStakingV2, calcExtraPower } = useStaking();
const [inputAmount, setInputAmount] = useState(0n);
const [busy, setBusy] = useState(false);
- const { ktonToken, contract, explorer } = getChainConfig(activeChain);
+ const publicClient = usePublicClient();
+ const { data: walletClient } = useWalletClient();
+
+ const { ktonToken } = getChainConfig(activeChain);
const handleUnbond = useCallback(async () => {
if (stakedKton < inputAmount) {
@@ -31,23 +33,22 @@ export default function UnbondKtonModal({
keepZero: false,
})} ${ktonToken?.symbol}`,
});
- } else {
+ } else if (walletClient && publicClient) {
setBusy(true);
const { contract, explorer } = getChainConfig(activeChain);
try {
- const abi =
- activeChain === ChainID.CRAB
- ? (await import("@/config/abi/staking-v2.json")).default
- : (await import(`@/config/abi/${contract.staking.abiFile}`)).default;
+ const abi = isStakingV2
+ ? (await import("@/config/abi/staking-v2.json")).default
+ : (await import("@/config/abi/staking.json")).default;
- const { hash } = await writeContract({
+ const hash = await walletClient.writeContract({
address: contract.staking.address,
abi,
functionName: "unstake",
args: [0n, inputAmount, []],
});
- const receipt = await waitForTransaction({ hash });
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
if (receipt.status === "success") {
setInputAmount(0n);
@@ -61,7 +62,7 @@ export default function UnbondKtonModal({
setBusy(false);
}
- }, [activeChain, stakedKton, inputAmount, ktonToken, onClose]);
+ }, [activeChain, stakedKton, inputAmount, ktonToken, isStakingV2, walletClient, publicClient, onClose]);
return (
ktonToken && (
diff --git a/src/components/unbond-ring-modal.tsx b/src/components/unbond-ring-modal.tsx
index 9ecde7a..3987a51 100644
--- a/src/components/unbond-ring-modal.tsx
+++ b/src/components/unbond-ring-modal.tsx
@@ -3,8 +3,7 @@ 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";
-import { ChainID } from "@/types";
+import { usePublicClient, useWalletClient } from "wagmi";
export default function UnbondRingModal({
commission,
@@ -16,11 +15,14 @@ export default function UnbondRingModal({
onClose?: () => void;
}) {
const { activeChain } = useApp();
- const { stakedRing, calcExtraPower } = useStaking();
+ const { stakedRing, isStakingV2, calcExtraPower } = useStaking();
const [inputAmount, setInputAmount] = useState(0n);
const [busy, setBusy] = useState(false);
+ const publicClient = usePublicClient();
+ const { data: walletClient } = useWalletClient();
+
const { nativeToken } = getChainConfig(activeChain);
const handleUnbond = useCallback(async () => {
@@ -31,23 +33,22 @@ export default function UnbondRingModal({
keepZero: false,
})} ${nativeToken.symbol}`,
});
- } else {
+ } else if (walletClient && publicClient) {
setBusy(true);
const { contract, explorer } = getChainConfig(activeChain);
try {
- const abi =
- activeChain === ChainID.CRAB
- ? (await import("@/config/abi/staking-v2.json")).default
- : (await import(`@/config/abi/${contract.staking.abiFile}`)).default;
+ const abi = isStakingV2
+ ? (await import("@/config/abi/staking-v2.json")).default
+ : (await import("@/config/abi/staking.json")).default;
- const { hash } = await writeContract({
+ const hash = await walletClient.writeContract({
address: contract.staking.address,
abi,
functionName: "unstake",
args: [inputAmount, 0n, []],
});
- const receipt = await waitForTransaction({ hash });
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
if (receipt.status === "success") {
setInputAmount(0n);
@@ -61,7 +62,7 @@ export default function UnbondRingModal({
setBusy(false);
}
- }, [activeChain, stakedRing, inputAmount, nativeToken, onClose]);
+ }, [activeChain, stakedRing, inputAmount, nativeToken, isStakingV2, walletClient, publicClient, onClose]);
return (
void;
onChange?: (amount: bigint) => void;
}) {
+ const { isStakingV2 } = useStaking();
+
return (
<>
- This unbonding process will take 14 days to complete.
+
+ This unbonding process will take 14 days to complete.
+
+ {isStakingV2 && (
+ {`There is no longer a 14-day period for unbonding ${symbol}.`}
+ )}
undefined }: P
const [busy, setBusy] = useState(false);
const { activeChain } = useApp();
+ const publicClient = usePublicClient();
+ const { data: walletClient } = useWalletClient();
+
const handleUndelegate = useCallback(async () => {
const chainConfig = getChainConfig(activeChain);
setBusy(true);
- try {
- const contractAbi = (await import(`@/config/abi/${chainConfig.contract.staking.abiFile}`)).default;
-
- const { hash } = await writeContract({
- address: chainConfig.contract.staking.address,
- abi: contractAbi,
- functionName: "chill",
- args: [],
- });
- const receipt = await waitForTransaction({ hash });
+ if (walletClient && publicClient) {
+ try {
+ const hash = await walletClient.writeContract({
+ address: chainConfig.contract.staking.address,
+ abi: (await import(`@/config/abi/${chainConfig.contract.staking.abiFile}`)).default,
+ functionName: "chill",
+ args: [],
+ });
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
- if (receipt.status === "success") {
- onClose();
+ if (receipt.status === "success") {
+ onClose();
+ }
+ notifyTransaction(receipt, chainConfig.explorer);
+ } catch (err) {
+ console.error(err);
+ notification.error({ description: (err as Error).message });
}
- notifyTransaction(receipt, chainConfig.explorer);
- } catch (err) {
- console.error(err);
- notification.error({ description: (err as Error).message });
}
setBusy(false);
- }, [activeChain, onClose]);
+ }, [activeChain, walletClient, publicClient, onClose]);
return (
{
@@ -37,35 +40,37 @@ export default function WithdrawModal({
const handleWithdraw = useCallback(async () => {
setBusy(true);
- try {
- const contractAbi = (await import(`@/config/abi/${chainConfig.contract.deposit.abiFile}`)).default;
+ if (walletClient && publicClient) {
+ try {
+ const abi = (await import(`@/config/abi/${chainConfig.contract.deposit.abiFile}`)).default;
- const { hash } = await (type === "early"
- ? writeContract({
- address: chainConfig.contract.deposit.address,
- abi: contractAbi,
- functionName: "claim_with_penalty",
- args: [deposit?.id],
- })
- : writeContract({
- address: chainConfig.contract.deposit.address,
- abi: contractAbi,
- functionName: "claim",
- args: [],
- }));
- const receipt = await waitForTransaction({ hash });
+ const hash = await (type === "early"
+ ? walletClient.writeContract({
+ address: chainConfig.contract.deposit.address,
+ abi,
+ functionName: "claim_with_penalty",
+ args: [deposit?.id ?? 0],
+ })
+ : walletClient.writeContract({
+ address: chainConfig.contract.deposit.address,
+ abi,
+ functionName: "claim",
+ args: [],
+ }));
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
- if (receipt.status === "success") {
- onClose();
+ if (receipt.status === "success") {
+ onClose();
+ }
+ notifyTransaction(receipt, chainConfig.explorer);
+ } catch (err) {
+ console.error(err);
+ notification.error({ description: (err as Error).message });
}
- notifyTransaction(receipt, chainConfig.explorer);
- } catch (err) {
- console.error(err);
- notification.error({ description: (err as Error).message });
}
setBusy(false);
- }, [type, chainConfig.contract.deposit, chainConfig.explorer, deposit?.id, onClose]);
+ }, [type, chainConfig.contract.deposit, chainConfig.explorer, deposit?.id, walletClient, publicClient, onClose]);
return (
void) | null>(null);
- const { switchNetwork } = useSwitchNetwork();
- const { chain } = useNetwork();
const { activeChain } = useApp();
+ const account = useAccount();
+ const { switchChain } = useSwitchChain();
useEffect(() => {
- if (chain?.id && chain.id !== activeChain) {
- if (!closerRef.current && switchNetwork) {
+ if (account.chainId && account.chainId !== activeChain) {
+ if (!closerRef.current) {
const chainConfig = getChainConfig(activeChain);
closerRef.current = notification.warn({
@@ -24,7 +24,7 @@ export default function WrongChainAlert() {
You are connected to the Wrong Chain.{" "}
switchNetwork(activeChain)}
+ onClick={() => switchChain({ chainId: activeChain })}
>{`Change the selected Chain to ${chainConfig.name}`}{" "}
in MetaMask.
@@ -38,7 +38,7 @@ export default function WrongChainAlert() {
closerRef.current();
closerRef.current = null;
}
- }, [chain?.id, activeChain, switchNetwork]);
+ }, [account.chainId, activeChain, switchChain]);
return null;
}
diff --git a/src/hooks/index.ts b/src/hooks/index.ts
index 36e2ca2..2555f5d 100644
--- a/src/hooks/index.ts
+++ b/src/hooks/index.ts
@@ -13,3 +13,4 @@ export * from "./use-pool";
export * from "./use-active-collators";
export * from "./use-collator-last-session-blocks";
export * from "./use-collators-session-key";
+export * from "./use-is-staking-v2";
diff --git a/src/hooks/use-is-staking-v2.ts b/src/hooks/use-is-staking-v2.ts
new file mode 100644
index 0000000..6e885df
--- /dev/null
+++ b/src/hooks/use-is-staking-v2.ts
@@ -0,0 +1,31 @@
+import { useEffect, useState } from "react";
+import { useApi } from "./use-api";
+import { Subscription, from } from "rxjs";
+
+export function useIsStakingV2() {
+ const [isStakingV2, setIsStakingV2] = useState(false);
+ const { polkadotApi } = useApi();
+
+ useEffect(() => {
+ let sub$$: Subscription | undefined;
+
+ if (polkadotApi) {
+ sub$$ = from(polkadotApi.rpc.state.getRuntimeVersion()).subscribe({
+ next: ({ specName, specVersion }) => {
+ setIsStakingV2(
+ specName.toString() === "Crab2" || (specName.toString() === "Darwinia2" && 6600 < specVersion.toNumber())
+ );
+ },
+ error: (err) => {
+ console.error(err);
+ },
+ });
+ }
+
+ return () => {
+ sub$$?.unsubscribe();
+ };
+ }, [polkadotApi]);
+
+ return isStakingV2;
+}
diff --git a/src/libs/darwinia.js/chains/crab/calls/darwiniaStaking.ts b/src/libs/darwinia.js/chains/crab/calls/darwiniaStaking.ts
index a77fb04..d80bece 100644
--- a/src/libs/darwinia.js/chains/crab/calls/darwiniaStaking.ts
+++ b/src/libs/darwinia.js/chains/crab/calls/darwiniaStaking.ts
@@ -8,8 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
-import { TransactionReceipt, Hex } from "viem";
+import { TransactionReceipt, Hex, WalletClient } from "viem";
export const getDarwiniaStaking = (dispatch: Dispatch, metadata: Metadata) => {
return {
diff --git a/src/libs/darwinia.js/chains/crab/calls/index.ts b/src/libs/darwinia.js/chains/crab/calls/index.ts
index fe6c3f2..897274b 100644
--- a/src/libs/darwinia.js/chains/crab/calls/index.ts
+++ b/src/libs/darwinia.js/chains/crab/calls/index.ts
@@ -1,10 +1,10 @@
-import type { PublicClient } from "@wagmi/core";
import type { Metadata } from "@polkadot/types";
import { dispatch as dispatchCall } from "../../../src/call";
import { getUtility } from "./utility";
import { getDarwiniaStaking } from "./darwiniaStaking";
import { getSession } from "./session";
+import { PublicClient } from "viem";
export const buildCrabCallsClient = (publicClient: PublicClient, metadata: Metadata) => {
const dispatch = dispatchCall(publicClient, metadata);
diff --git a/src/libs/darwinia.js/chains/crab/calls/session.ts b/src/libs/darwinia.js/chains/crab/calls/session.ts
index a321809..f646ec6 100644
--- a/src/libs/darwinia.js/chains/crab/calls/session.ts
+++ b/src/libs/darwinia.js/chains/crab/calls/session.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getSession = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/chains/crab/calls/utility.ts b/src/libs/darwinia.js/chains/crab/calls/utility.ts
index cd81ffc..fceb4c0 100644
--- a/src/libs/darwinia.js/chains/crab/calls/utility.ts
+++ b/src/libs/darwinia.js/chains/crab/calls/utility.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getUtility = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/chains/darwinia/calls/darwiniaStaking.ts b/src/libs/darwinia.js/chains/darwinia/calls/darwiniaStaking.ts
index 6004fee..1ab34e8 100644
--- a/src/libs/darwinia.js/chains/darwinia/calls/darwiniaStaking.ts
+++ b/src/libs/darwinia.js/chains/darwinia/calls/darwiniaStaking.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getDarwiniaStaking = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/chains/darwinia/calls/index.ts b/src/libs/darwinia.js/chains/darwinia/calls/index.ts
index 5955970..1b8f049 100644
--- a/src/libs/darwinia.js/chains/darwinia/calls/index.ts
+++ b/src/libs/darwinia.js/chains/darwinia/calls/index.ts
@@ -1,4 +1,4 @@
-import type { PublicClient } from "@wagmi/core";
+import type { PublicClient } from "viem";
import type { Metadata } from "@polkadot/types";
import { dispatch as dispatchCall } from "../../../src/call";
diff --git a/src/libs/darwinia.js/chains/darwinia/calls/session.ts b/src/libs/darwinia.js/chains/darwinia/calls/session.ts
index da80d54..ae54110 100644
--- a/src/libs/darwinia.js/chains/darwinia/calls/session.ts
+++ b/src/libs/darwinia.js/chains/darwinia/calls/session.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getSession = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/chains/darwinia/calls/utility.ts b/src/libs/darwinia.js/chains/darwinia/calls/utility.ts
index 88e6f0a..c408b41 100644
--- a/src/libs/darwinia.js/chains/darwinia/calls/utility.ts
+++ b/src/libs/darwinia.js/chains/darwinia/calls/utility.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getUtility = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/chains/index.ts b/src/libs/darwinia.js/chains/index.ts
index 79ef5fc..4b5e200 100644
--- a/src/libs/darwinia.js/chains/index.ts
+++ b/src/libs/darwinia.js/chains/index.ts
@@ -3,7 +3,7 @@ import { crabStaticMetadata, buildCrabCallsClient } from "./crab";
import { darwiniaStaticMetadata, buildDarwiniaCallsClient } from "./darwinia";
import { pangoroStaticMetadata, buildPangoroCallsClient } from "./pongoro";
-import type { PublicClient } from "@wagmi/core";
+import type { PublicClient } from "viem";
import { buildMetadata } from "../src/helpers";
export const clientBuilder = {
diff --git a/src/libs/darwinia.js/chains/pangolin/calls/darwiniaStaking.ts b/src/libs/darwinia.js/chains/pangolin/calls/darwiniaStaking.ts
index 5ca7d17..e62b356 100644
--- a/src/libs/darwinia.js/chains/pangolin/calls/darwiniaStaking.ts
+++ b/src/libs/darwinia.js/chains/pangolin/calls/darwiniaStaking.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getDarwiniaStaking = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/chains/pangolin/calls/index.ts b/src/libs/darwinia.js/chains/pangolin/calls/index.ts
index 8649461..2debb8c 100644
--- a/src/libs/darwinia.js/chains/pangolin/calls/index.ts
+++ b/src/libs/darwinia.js/chains/pangolin/calls/index.ts
@@ -1,4 +1,4 @@
-import type { PublicClient } from "@wagmi/core";
+import type { PublicClient } from "viem";
import type { Metadata } from "@polkadot/types";
import { dispatch as dispatchCall } from "../../../src/call";
diff --git a/src/libs/darwinia.js/chains/pangolin/calls/session.ts b/src/libs/darwinia.js/chains/pangolin/calls/session.ts
index 1544899..661a806 100644
--- a/src/libs/darwinia.js/chains/pangolin/calls/session.ts
+++ b/src/libs/darwinia.js/chains/pangolin/calls/session.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getSession = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/chains/pangolin/calls/utility.ts b/src/libs/darwinia.js/chains/pangolin/calls/utility.ts
index 0d75f20..4dafa97 100644
--- a/src/libs/darwinia.js/chains/pangolin/calls/utility.ts
+++ b/src/libs/darwinia.js/chains/pangolin/calls/utility.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getUtility = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/chains/pongoro/calls/darwiniaStaking.ts b/src/libs/darwinia.js/chains/pongoro/calls/darwiniaStaking.ts
index ebfd18e..91c89fb 100644
--- a/src/libs/darwinia.js/chains/pongoro/calls/darwiniaStaking.ts
+++ b/src/libs/darwinia.js/chains/pongoro/calls/darwiniaStaking.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getDarwiniaStaking = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/chains/pongoro/calls/index.ts b/src/libs/darwinia.js/chains/pongoro/calls/index.ts
index 89ef921..294e29d 100644
--- a/src/libs/darwinia.js/chains/pongoro/calls/index.ts
+++ b/src/libs/darwinia.js/chains/pongoro/calls/index.ts
@@ -1,4 +1,4 @@
-import type { PublicClient } from "@wagmi/core";
+import type { PublicClient } from "viem";
import type { Metadata } from "@polkadot/types";
import { dispatch as dispatchCall } from "../../../src/call";
diff --git a/src/libs/darwinia.js/chains/pongoro/calls/session.ts b/src/libs/darwinia.js/chains/pongoro/calls/session.ts
index b891a5c..74dede3 100644
--- a/src/libs/darwinia.js/chains/pongoro/calls/session.ts
+++ b/src/libs/darwinia.js/chains/pongoro/calls/session.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getSession = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/chains/pongoro/calls/utility.ts b/src/libs/darwinia.js/chains/pongoro/calls/utility.ts
index ca9361b..4be0d02 100644
--- a/src/libs/darwinia.js/chains/pongoro/calls/utility.ts
+++ b/src/libs/darwinia.js/chains/pongoro/calls/utility.ts
@@ -8,7 +8,7 @@
import { Dispatch } from "../../../src/call";
import { buildRuntimeCall, decodeCall } from "../../../src/helpers";
import { Metadata } from "@polkadot/types";
-import type { WalletClient } from "@wagmi/core";
+import type { WalletClient } from "viem";
import { TransactionReceipt, Hex } from "viem";
export const getUtility = (dispatch: Dispatch, metadata: Metadata) => {
diff --git a/src/libs/darwinia.js/src/call.ts b/src/libs/darwinia.js/src/call.ts
index ff8037f..0fc581c 100644
--- a/src/libs/darwinia.js/src/call.ts
+++ b/src/libs/darwinia.js/src/call.ts
@@ -1,20 +1,20 @@
import { Metadata } from "@polkadot/types";
import { camelToSnakeCase } from "./utils";
import { encodeCall, getCallMeta } from "./helpers";
-import { PublicClient, WalletClient, sendTransaction } from "@wagmi/core";
-import { Hex, concat, toHex } from "viem";
+import { Hex, PublicClient, WalletClient, concat, toHex } from "viem";
async function doDispatch(publicClient: PublicClient, walletClient: WalletClient, data: Hex | Uint8Array) {
const contractAddress = "0x0000000000000000000000000000000000000401" as const;
const tx = {
- account: walletClient.account.address,
+ account: walletClient.account?.address || "0x",
data: toHex(data),
to: contractAddress,
+ chain: undefined,
};
await publicClient.call(tx);
- const { hash } = await sendTransaction(tx);
+ const hash = await walletClient.sendTransaction(tx);
return publicClient.waitForTransactionReceipt({ hash });
}
diff --git a/src/providers/rainbow-provider.tsx b/src/providers/rainbow-provider.tsx
index abc1260..626704a 100644
--- a/src/providers/rainbow-provider.tsx
+++ b/src/providers/rainbow-provider.tsx
@@ -1,90 +1,79 @@
"use client";
import "@rainbow-me/rainbowkit/styles.css";
-import { getDefaultWallets, RainbowKitProvider, connectorsForWallets, darkTheme } from "@rainbow-me/rainbowkit";
-import { trustWallet, imTokenWallet, okxWallet, talismanWallet, safeWallet } from "@rainbow-me/rainbowkit/wallets";
-import { configureChains, createConfig, WagmiConfig } from "wagmi";
-import { publicProvider } from "wagmi/providers/public";
+import { RainbowKitProvider, connectorsForWallets, darkTheme } from "@rainbow-me/rainbowkit";
+import {
+ safeWallet,
+ rainbowWallet,
+ metaMaskWallet,
+ walletConnectWallet,
+ talismanWallet,
+ okxWallet,
+} from "@rainbow-me/rainbowkit/wallets";
+import { createConfig, WagmiProvider } from "wagmi";
import { APP_NAME_CONF } from "@/config";
import { getChainConfigs } from "@/utils";
-import { PropsWithChildren, useEffect, useState } from "react";
-import { useApp } from "@/hooks";
+import { PropsWithChildren } from "react";
+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
+import { Chain, createClient, http } from "viem";
const projectId = process.env.NEXT_PUBLIC_WALLET_CONNECT_ID || "";
-
-export function RainbowProvider({ children }: PropsWithChildren) {
- const [mounted, setMounted] = useState(true); // temporarity set to true
- const { activeChain, activeRpc } = useApp();
-
- const { chains, publicClient } = configureChains(
- getChainConfigs().map(({ chainId, name, nativeToken, explorer }) => ({
- id: chainId,
- name,
- network: name.toLowerCase().split(" ").join("-"),
- nativeCurrency: {
- name: nativeToken.symbol,
- symbol: nativeToken.symbol,
- decimals: nativeToken.decimals,
- },
- rpcUrls: {
- default: {
- http: activeRpc.url.startsWith("http") ? [activeRpc.url] : [],
- webSocket: activeRpc.url.startsWith("ws") ? [activeRpc.url] : [],
- },
- public: {
- http: activeRpc.url.startsWith("http") ? [activeRpc.url] : [],
- webSocket: activeRpc.url.startsWith("ws") ? [activeRpc.url] : [],
- },
- },
- blockExplorers: {
- default: {
- url: explorer.url,
- name: explorer.name,
- },
- },
- })),
- [publicProvider()]
- );
-
- const { wallets } = getDefaultWallets({
- appName: APP_NAME_CONF,
- projectId,
- chains,
- });
-
- const connectors = connectorsForWallets([
- ...wallets,
+const queryClient = new QueryClient();
+const connectors = connectorsForWallets(
+ [
{
groupName: "More",
- wallets: [
- talismanWallet({ chains }),
- okxWallet({ projectId, chains }),
- imTokenWallet({ projectId, chains }),
- trustWallet({ projectId, chains }),
- safeWallet({ chains }),
- ],
+ wallets: [rainbowWallet, metaMaskWallet, walletConnectWallet, talismanWallet, okxWallet, safeWallet],
},
- ]);
+ ],
+ { appName: APP_NAME_CONF, projectId }
+);
- const wagmiConfig = createConfig({
- autoConnect: true,
- connectors,
- publicClient,
- });
-
- useEffect(() => setMounted(true), []);
+const chains = getChainConfigs().map(({ chainId, name, nativeToken, explorer, rpcMetas }) => ({
+ id: chainId,
+ name,
+ network: name.toLowerCase().split(" ").join("-"),
+ nativeCurrency: {
+ name: nativeToken.symbol,
+ symbol: nativeToken.symbol,
+ decimals: nativeToken.decimals,
+ },
+ rpcUrls: {
+ default: {
+ http: rpcMetas.filter(({ url }) => url.startsWith("http")).map(({ url }) => url),
+ webSocket: rpcMetas.filter(({ url }) => url.startsWith("ws")).map(({ url }) => url),
+ },
+ public: {
+ http: rpcMetas.filter(({ url }) => url.startsWith("http")).map(({ url }) => url),
+ webSocket: rpcMetas.filter(({ url }) => url.startsWith("ws")).map(({ url }) => url),
+ },
+ },
+ blockExplorers: {
+ default: {
+ url: explorer.url,
+ name: explorer.name,
+ },
+ },
+})) as unknown as [Chain, ...Chain[]];
+export function RainbowProvider({ children }: PropsWithChildren) {
return (
-
-
- {mounted && children}
-
-
+ createClient({ chain, transport: http() }),
+ })}
+ >
+
+
+ {children}
+
+
+
);
}
diff --git a/src/providers/staking-provider.tsx b/src/providers/staking-provider.tsx
index 9a355e4..d2fa9d8 100644
--- a/src/providers/staking-provider.tsx
+++ b/src/providers/staking-provider.tsx
@@ -9,6 +9,7 @@ import {
useCollatorPower,
useCollatorSessionKey,
useDeposits,
+ useIsStakingV2,
useLedger,
useNominatorCollators,
usePool,
@@ -39,6 +40,8 @@ interface StakingCtx {
minimumDeposit: bigint;
maxCommission: number;
+ isStakingV2: boolean;
+
isLedgersInitialized: boolean;
isDepositsInitialized: boolean;
isRingPoolInitialized: boolean;
@@ -81,6 +84,8 @@ const defaultValue: StakingCtx = {
minimumDeposit: 0n,
maxCommission: 100, // 100%
+ isStakingV2: false,
+
isLedgersInitialized: false,
isDepositsInitialized: false,
isRingPoolInitialized: false,
@@ -136,6 +141,7 @@ export function StakingProvider({ children }: PropsWithChildren) {
ktonPool,
defaultValue
);
+ const isStakingV2 = useIsStakingV2();
const power = useMemo(
() => stakingToPower(stakedRing + stakedDeposit, stakedKton, ringPool, ktonPool),
@@ -178,6 +184,8 @@ export function StakingProvider({ children }: PropsWithChildren) {
minimumDeposit,
maxCommission,
+ isStakingV2,
+
isLedgersInitialized,
isDepositsInitialized,
isRingPoolInitialized,