Skip to content

Commit

Permalink
Merge pull request #16 from darwinia-network/enhance/catch-logging
Browse files Browse the repository at this point in the history
add catch logging
  • Loading branch information
1022ranji authored Sep 29, 2024
2 parents ca50325 + d0b2367 commit 5a7c5aa
Show file tree
Hide file tree
Showing 3 changed files with 22 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
1 change: 1 addition & 0 deletions src/components/collator/join.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/components/collator/manage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 5a7c5aa

Please sign in to comment.