Skip to content

Commit 3ead323

Browse files
committed
fix: handle error when creating public client in useHypercertClient hook
Added error handling for the public client creation process to prevent crashes when the wallet client is not properly initialized.
1 parent 8cee6c7 commit 3ead323

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

hooks/use-hypercert-client.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import { useEffect, useState } from "react";
44
import { useAccount, useWalletClient } from "wagmi";
55
import { ENVIRONMENT, SUPPORTED_CHAINS } from "@/configs/constants";
66
import { EvmClientFactory } from "@/lib/evmClient";
7+
import { PublicClient } from "viem";
78

89
export const useHypercertClient = () => {
910
const { data: walletClient } = useWalletClient();
1011
const { isConnected } = useAccount();
1112
const [client, setClient] = useState<HypercertClient>();
1213

13-
const publicClient = walletClient?.chain.id
14-
? EvmClientFactory.createClient(walletClient.chain.id)
15-
: undefined;
14+
let publicClient: PublicClient | undefined;
15+
try {
16+
publicClient = walletClient?.chain.id
17+
? EvmClientFactory.createClient(walletClient.chain.id)
18+
: undefined;
19+
} catch (error) {
20+
console.error(`Error creating public client: ${error}`);
21+
}
1622

1723
useEffect(() => {
1824
if (!walletClient || !isConnected) {

0 commit comments

Comments
 (0)