Skip to content

Commit

Permalink
[TOOL-2814] Fix custom factory publish form (#5819)
Browse files Browse the repository at this point in the history
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 -->
  • Loading branch information
kumaryash90 committed Dec 20, 2024
1 parent cb66be4 commit 5f8e570
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions apps/dashboard/src/components/contract-components/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Abi>(contract);
},
enabled: !!contract,
enabled: !!contractAddress && !!chainId,
});
}

0 comments on commit 5f8e570

Please sign in to comment.