@@ -6,8 +6,8 @@ import type { Abi } from "abitype";
66import { isEnsName , resolveEns } from "lib/ens" ;
77import { useV5DashboardChain } from "lib/v5-adapter" ;
88import { useMemo } from "react" ;
9- import { type ThirdwebContract , getContract } from "thirdweb" ;
10- import { resolveContractAbi } from "thirdweb/contract" ;
9+ import type { ThirdwebContract } from "thirdweb" ;
10+ import { getContract , resolveContractAbi } from "thirdweb/contract" ;
1111import { isAddress } from "thirdweb/utils" ;
1212import {
1313 type PublishedContractWithVersion ,
@@ -179,29 +179,24 @@ export function useCustomFactoryAbi(
179179) {
180180 const chain = useV5DashboardChain ( chainId ) ;
181181 const client = useThirdwebClient ( ) ;
182- const contract = useMemo ( ( ) => {
183- if ( ! chain ) {
184- return undefined ;
185- }
186-
187- try {
188- return getContract ( {
189- client,
190- address : contractAddress ,
191- chain,
192- } ) ;
193- } catch {
194- return undefined ;
195- }
196- } , [ contractAddress , chain , client ] ) ;
197182
198183 return useQuery ( {
199- queryKey : [ "custom-factory-abi" , contract ] ,
184+ queryKey : [ "custom-factory-abi" , { contractAddress , chainId } ] ,
200185 queryFn : ( ) => {
201- if ( contract ) {
202- return resolveContractAbi < Abi > ( contract ) ;
186+ const contract = chain
187+ ? getContract ( {
188+ client,
189+ address : contractAddress ,
190+ chain,
191+ } )
192+ : undefined ;
193+
194+ if ( ! contract ) {
195+ throw new Error ( "Contract not found" ) ;
203196 }
197+
198+ return resolveContractAbi < Abi > ( contract ) ;
204199 } ,
205- enabled : ! ! contract ,
200+ enabled : ! ! contractAddress && ! ! chainId ,
206201 } ) ;
207202}
0 commit comments