From 5f8e57014d02f7d62d859d680b8a444d7ba14dda Mon Sep 17 00:00:00 2001 From: kumaryash90 Date: Fri, 20 Dec 2024 19:09:13 +0000 Subject: [PATCH] [TOOL-2814] Fix custom factory publish form (#5819) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TOOL-2814 ## Problem solved Short description of the bug fixed or feature added --- ## PR-Codex overview This PR refactors the `useCustomFactoryAbi` function in `hooks.ts` to improve contract handling and query logic. It changes how the contract is retrieved and updates the query's enabled condition. ### Detailed summary - Changed import statements for `ThirdwebContract` and `getContract`. - Refactored the `contract` retrieval logic to be more concise. - Updated `queryKey` to include `contractAddress` and `chainId`. - Modified the `enabled` condition to check for `contractAddress` and `chainId`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .../components/contract-components/hooks.ts | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/apps/dashboard/src/components/contract-components/hooks.ts b/apps/dashboard/src/components/contract-components/hooks.ts index 56a83bf6f85..c3d8d1cb425 100644 --- a/apps/dashboard/src/components/contract-components/hooks.ts +++ b/apps/dashboard/src/components/contract-components/hooks.ts @@ -6,8 +6,8 @@ import type { Abi } from "abitype"; import { isEnsName, resolveEns } from "lib/ens"; import { useV5DashboardChain } from "lib/v5-adapter"; import { useMemo } from "react"; -import { type ThirdwebContract, getContract } from "thirdweb"; -import { resolveContractAbi } from "thirdweb/contract"; +import type { ThirdwebContract } from "thirdweb"; +import { getContract, resolveContractAbi } from "thirdweb/contract"; import { isAddress } from "thirdweb/utils"; import { type PublishedContractWithVersion, @@ -179,26 +179,24 @@ export function useCustomFactoryAbi( ) { 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], + queryKey: ["custom-factory-abi", { contractAddress, chainId }], queryFn: () => { + const contract = chain + ? getContract({ + client, + address: contractAddress, + chain, + }) + : undefined; + if (!contract) { throw new Error("Contract not found"); } + return resolveContractAbi(contract); }, - enabled: !!contract, + enabled: !!contractAddress && !!chainId, }); }