Skip to content

Commit

Permalink
lint (#1384)
Browse files Browse the repository at this point in the history
  • Loading branch information
fan-zhang-sv authored and bangtoven committed Sep 16, 2024
1 parent 7d2e9c2 commit c37ac19
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
40 changes: 23 additions & 17 deletions src/components/RpcMethods/RpcMethodCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,22 +42,28 @@ export function RpcMethodCard({ format, method, params, shortcuts }) {
formState: { errors },
} = useForm();

const verify = useCallback(async (response: ResponseType, data: Record<string, string>) => {
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<string, string>) => {
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<string, string>) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/RpcMethods/method/signMessageMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { base, baseSepolia, harmonyOne, mainnet } from 'viem/chains';

import { ShortcutType } from './ShortcutType';

const walletSwitchEthereumChainShortcuts: ShortcutType[] = [
Expand Down
2 changes: 1 addition & 1 deletion src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}
Expand Down

0 comments on commit c37ac19

Please sign in to comment.