From c37ac19a0515e1d9df7feaeb565aaea16fa2ccaa Mon Sep 17 00:00:00 2001 From: Felix Zhang <22125939+fan-zhang-sv@users.noreply.github.com> Date: Thu, 5 Sep 2024 11:00:16 -0700 Subject: [PATCH] lint (#1384) --- src/components/RpcMethods/RpcMethodCard.tsx | 40 +++++++++++-------- .../RpcMethods/method/signMessageMethods.ts | 4 +- .../shortcut/multipleChainShortcuts.ts | 1 + src/pages/index.tsx | 2 +- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/components/RpcMethods/RpcMethodCard.tsx b/src/components/RpcMethods/RpcMethodCard.tsx index 6ecb013670..cbb3d00398 100644 --- a/src/components/RpcMethods/RpcMethodCard.tsx +++ b/src/components/RpcMethods/RpcMethodCard.tsx @@ -20,12 +20,12 @@ import { } from '@chakra-ui/react'; import React, { useCallback } from 'react'; import { useForm } from 'react-hook-form'; +import { Chain, hexToNumber } from 'viem'; +import { mainnet } from 'viem/chains'; import { useCBWSDK } from '../../context/CBWSDKReactContextProvider'; import { verifySignMsg } from './method/signMessageMethods'; import { ADDR_TO_FILL } from './shortcut/const'; -import { Chain, hexToNumber } from 'viem'; -import { mainnet } from 'viem/chains'; import { multiChainShortcutsMap } from './shortcut/multipleChainShortcuts'; type ResponseType = string; @@ -42,22 +42,28 @@ export function RpcMethodCard({ format, method, params, shortcuts }) { formState: { errors }, } = useForm(); - const verify = useCallback(async (response: ResponseType, data: Record) => { - const chainId = await provider.request({ method: "eth_chainId"}); - let chain = multiChainShortcutsMap['wallet_switchEthereumChain'].find((shortcut) => Number(shortcut.data.chainId) === hexToNumber(chainId))?.data.chain ?? mainnet; + const verify = useCallback( + async (response: ResponseType, data: Record) => { + const chainId = await provider.request({ method: 'eth_chainId' }); + const chain = + multiChainShortcutsMap['wallet_switchEthereumChain'].find( + (shortcut) => Number(shortcut.data.chainId) === hexToNumber(chainId) + )?.data.chain ?? mainnet; - const verifyResult = await verifySignMsg({ - method, - from: data.address?.toLowerCase(), - sign: response, - message: data.message, - chain: chain as Chain - }); - if (verifyResult) { - setVerifyResult(verifyResult); - return; - } - }, [provider]); + const verifyResult = await verifySignMsg({ + method, + from: data.address?.toLowerCase(), + sign: response, + message: data.message, + chain: chain as Chain, + }); + if (verifyResult) { + setVerifyResult(verifyResult); + return; + } + }, + [provider] + ); const submit = useCallback( async (data: Record) => { diff --git a/src/components/RpcMethods/method/signMessageMethods.ts b/src/components/RpcMethods/method/signMessageMethods.ts index c7abd740ca..8f8e9fd6d5 100644 --- a/src/components/RpcMethods/method/signMessageMethods.ts +++ b/src/components/RpcMethods/method/signMessageMethods.ts @@ -86,7 +86,7 @@ export const verifySignMsg = async ({ address: from as `0x${string}`, message: message as string, signature: sign as `0x${string}`, - }) + }); if (valid) { return `SigUtil Successfully verified signer as ${from}`; } else { @@ -108,7 +108,7 @@ export const verifySignMsg = async ({ primaryType: message['primaryType'] as string, message: message['message'] as any, signature: sign as `0x${string}`, - }) + }); if (valid) { return `SigUtil Successfully verified signer as ${from}`; } else { diff --git a/src/components/RpcMethods/shortcut/multipleChainShortcuts.ts b/src/components/RpcMethods/shortcut/multipleChainShortcuts.ts index 3d0052bd22..1727d2470f 100644 --- a/src/components/RpcMethods/shortcut/multipleChainShortcuts.ts +++ b/src/components/RpcMethods/shortcut/multipleChainShortcuts.ts @@ -1,4 +1,5 @@ import { base, baseSepolia, harmonyOne, mainnet } from 'viem/chains'; + import { ShortcutType } from './ShortcutType'; const walletSwitchEthereumChainShortcuts: ShortcutType[] = [ diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 408c7e8def..4f71761ac6 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -42,7 +42,7 @@ export default function Home() { useEffect(() => { if (connected) { - provider?.request({ method: "eth_chainId"}).then((chainId) => { + provider?.request({ method: 'eth_chainId' }).then((chainId) => { setChainId(parseInt(chainId, 16)); }); }