Skip to content

Commit 5f8e570

Browse files
committed
[TOOL-2814] Fix custom factory publish form (#5819)
TOOL-2814 ## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## 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}` <!-- end pr-codex -->
1 parent cb66be4 commit 5f8e570

File tree

1 file changed

+13
-15
lines changed
  • apps/dashboard/src/components/contract-components

1 file changed

+13
-15
lines changed

apps/dashboard/src/components/contract-components/hooks.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type { Abi } from "abitype";
66
import { isEnsName, resolveEns } from "lib/ens";
77
import { useV5DashboardChain } from "lib/v5-adapter";
88
import { 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";
1111
import { isAddress } from "thirdweb/utils";
1212
import {
1313
type PublishedContractWithVersion,
@@ -179,26 +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-
return getContract({
188-
client,
189-
address: contractAddress,
190-
chain,
191-
});
192-
}, [contractAddress, chain, client]);
193182

194183
return useQuery({
195-
queryKey: ["custom-factory-abi", contract],
184+
queryKey: ["custom-factory-abi", { contractAddress, chainId }],
196185
queryFn: () => {
186+
const contract = chain
187+
? getContract({
188+
client,
189+
address: contractAddress,
190+
chain,
191+
})
192+
: undefined;
193+
197194
if (!contract) {
198195
throw new Error("Contract not found");
199196
}
197+
200198
return resolveContractAbi<Abi>(contract);
201199
},
202-
enabled: !!contract,
200+
enabled: !!contractAddress && !!chainId,
203201
});
204202
}

0 commit comments

Comments
 (0)