diff --git a/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx b/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx index 6198fbfb897..49c04ae4a05 100644 --- a/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx +++ b/apps/dashboard/src/components/contract-components/contract-deploy-form/custom-contract.tsx @@ -145,7 +145,7 @@ export const CustomContractForm: React.FC = ({ const customFactoryAbi = useCustomFactoryAbi( customFactoryAddress, - Number(customFactoryNetwork), + customFactoryNetwork ? Number(customFactoryNetwork) : undefined, ); const isTWPublisher = checkTwPublisher(metadata?.publisher); diff --git a/apps/dashboard/src/components/contract-components/hooks.ts b/apps/dashboard/src/components/contract-components/hooks.ts index 14c4f312978..9d3721856ee 100644 --- a/apps/dashboard/src/components/contract-components/hooks.ts +++ b/apps/dashboard/src/components/contract-components/hooks.ts @@ -212,19 +212,32 @@ export function useContractEvents(abi: Abi) { return abi.filter((a) => a.type === "event"); } -export function useCustomFactoryAbi(contractAddress: string, chainId: number) { +export function useCustomFactoryAbi( + contractAddress: string, + chainId: number | undefined, +) { const chain = useV5DashboardChain(chainId); const client = useThirdwebClient(); const contract = useMemo(() => { + if (!chain) { + return undefined; + } + return getContract({ client, address: contractAddress, chain, }); }, [contractAddress, chain, client]); + return useQuery({ queryKey: ["custom-factory-abi", contract], - queryFn: () => resolveContractAbi(contract), + queryFn: () => { + if (!contract) { + throw new Error("Contract not found"); + } + return resolveContractAbi(contract); + }, enabled: !!contract, }); }