From 3ead3236f0c053e346ae73ef78f64aeaba95c067 Mon Sep 17 00:00:00 2001 From: jipstavenuiter Date: Thu, 27 Mar 2025 16:21:13 -0300 Subject: [PATCH] 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. --- hooks/use-hypercert-client.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hooks/use-hypercert-client.ts b/hooks/use-hypercert-client.ts index 55ad1416..3b6b441c 100644 --- a/hooks/use-hypercert-client.ts +++ b/hooks/use-hypercert-client.ts @@ -4,15 +4,21 @@ import { useEffect, useState } from "react"; import { useAccount, useWalletClient } from "wagmi"; import { ENVIRONMENT, SUPPORTED_CHAINS } from "@/configs/constants"; import { EvmClientFactory } from "@/lib/evmClient"; +import { PublicClient } from "viem"; export const useHypercertClient = () => { const { data: walletClient } = useWalletClient(); const { isConnected } = useAccount(); const [client, setClient] = useState(); - const publicClient = walletClient?.chain.id - ? EvmClientFactory.createClient(walletClient.chain.id) - : undefined; + let publicClient: PublicClient | undefined; + try { + publicClient = walletClient?.chain.id + ? EvmClientFactory.createClient(walletClient.chain.id) + : undefined; + } catch (error) { + console.error(`Error creating public client: ${error}`); + } useEffect(() => { if (!walletClient || !isConnected) {