Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
});
}
Loading