Skip to content

Commit

Permalink
Refactor set-session-key hook to support multiple chains
Browse files Browse the repository at this point in the history
  • Loading branch information
snoopy1412 committed Sep 29, 2024
1 parent c091640 commit d0b2367
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/components/collator/_hooks/set-session-key.ts
Original file line number Diff line number Diff line change
@@ -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}`
Expand Down

0 comments on commit d0b2367

Please sign in to comment.