Skip to content

Commit

Permalink
Merge pull request #517 from us3r-network/B-signerChain-ttang
Browse files Browse the repository at this point in the history
fix: switch network
  • Loading branch information
Tonyce authored Feb 2, 2024
2 parents c582b99 + 32283cd commit eb4797d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions apps/u3/src/components/social/farcaster/signupv2/AddAccountKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import { optimism } from 'viem/chains';
import { toast } from 'react-toastify';
import { NobleEd25519Signer, ViemWalletEip712Signer } from '@farcaster/hub-web';
import { useConnectModal } from '@rainbow-me/rainbowkit';
import { useAccount, usePublicClient, useWalletClient } from 'wagmi';
import {
useAccount,
useNetwork,
usePublicClient,
useWalletClient,
} from 'wagmi';
import {
waitForTransaction,
writeContract,
prepareWriteContract,
switchNetwork,
} from '@wagmi/core';
import * as ed25519 from '@noble/ed25519';

Expand Down Expand Up @@ -37,6 +43,7 @@ export default function AddAccountKey({
const { address } = useAccount();
const account = useAccount();
const wallet = useWalletClient();
const network = useNetwork();

const publicClient = usePublicClient({
chainId: optimism.id,
Expand All @@ -59,6 +66,9 @@ export default function AddAccountKey({
setSigner(ed25519Signer);
return;
}
if (network.chain?.id !== optimism.id) {
await switchNetwork({ chainId: optimism.id });
}
// const privateKey = ed25519.utils.randomPrivateKey();
// const publicKey = toHex(ed25519.getPublicKey(privateKey));
const privateKey = ed25519.utils.randomPrivateKey();
Expand Down Expand Up @@ -118,7 +128,7 @@ export default function AddAccountKey({
console.error(error);
toast.error(error.message);
}
}, [fid, account, publicClient]);
}, [fid, account, publicClient, network]);

return (
<div
Expand Down

0 comments on commit eb4797d

Please sign in to comment.