From c091640061d2d39eea09b01aab06487e22d57a10 Mon Sep 17 00:00:00 2001 From: snoopy1412 Date: Sun, 29 Sep 2024 13:32:27 +0800 Subject: [PATCH 1/2] add catch logging --- src/components/collator/join.tsx | 1 + src/components/collator/manage.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/src/components/collator/join.tsx b/src/components/collator/join.tsx index afad4ce..88698f4 100644 --- a/src/components/collator/join.tsx +++ b/src/components/collator/join.tsx @@ -65,6 +65,7 @@ const CollatorJoin = ({ hasSessionKey, sessionKey, hasPool, refetch }: CollatorJ const handleSetSessionKey = useCallback(async () => { if (validSessionKey(sessionKeyValue)) { const tx = await setSessionKey(sessionKeyValue)?.catch((e) => { + console.warn('setSessionKey error: ', e); error(e.shortMessage); }); if (tx) { diff --git a/src/components/collator/manage.tsx b/src/components/collator/manage.tsx index 457d145..a638a3c 100644 --- a/src/components/collator/manage.tsx +++ b/src/components/collator/manage.tsx @@ -111,6 +111,7 @@ const CollatorManagement = ({ const handleSetSessionKey = useCallback(async () => { if (validSessionKey(sessionKeyValue)) { const tx = await setSessionKey(sessionKeyValue)?.catch((e) => { + console.warn('setSessionKey error: ', e); error(e.shortMessage); }); if (tx) { From d0b23674a81360cc34025817259ad615b2928a33 Mon Sep 17 00:00:00 2001 From: snoopy1412 Date: Sun, 29 Sep 2024 13:48:11 +0800 Subject: [PATCH 2/2] Refactor set-session-key hook to support multiple chains --- .../collator/_hooks/set-session-key.ts | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/collator/_hooks/set-session-key.ts b/src/components/collator/_hooks/set-session-key.ts index d0cbf23..7f848b5 100644 --- a/src/components/collator/_hooks/set-session-key.ts +++ b/src/components/collator/_hooks/set-session-key.ts @@ -1,11 +1,29 @@ +import useWalletStatus from '@/hooks/useWalletStatus'; +import { ChainId } from '@/types/chains'; import { useSendTransaction } from 'wagmi'; +const getData = (sessionKey: string, chainId: ChainId) => { + switch (chainId) { + case ChainId.DARWINIA: + case ChainId.CRAB: + return `0x0d00${sessionKey}00`; + case ChainId.KOI: + return `0x0a00${sessionKey}00`; + default: + return ''; + } +}; + export const useSetSessionKey = () => { - const { sendTransactionAsync, isPending } = useSendTransaction(); + const { currentChainId } = useWalletStatus(); + const { sendTransactionAsync, isPending } = useSendTransaction(); const setSessionKey = async (sessionKey: string) => { + if (!currentChainId) { + return; + } const cleanSessionKey = sessionKey.startsWith('0x') ? sessionKey.slice(2) : sessionKey; - const data = `0x0a00${cleanSessionKey}00`; + const data = getData(cleanSessionKey, currentChainId); return sendTransactionAsync({ to: '0x0000000000000000000000000000000000000401', data: data as `0x${string}`