Skip to content

Commit b767f93

Browse files
committed
cleanup
1 parent fc332c1 commit b767f93

File tree

1 file changed

+16
-21
lines changed
  • apps/dashboard/src/components/contract-components

1 file changed

+16
-21
lines changed

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

Lines changed: 16 additions & 21 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,29 +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-
try {
188-
return getContract({
189-
client,
190-
address: contractAddress,
191-
chain,
192-
});
193-
} catch {
194-
return undefined;
195-
}
196-
}, [contractAddress, chain, client]);
197182

198183
return useQuery({
199-
queryKey: ["custom-factory-abi", contract],
184+
queryKey: ["custom-factory-abi", { contractAddress, chainId }],
200185
queryFn: () => {
201-
if (contract) {
202-
return resolveContractAbi<Abi>(contract);
186+
const contract = chain
187+
? getContract({
188+
client,
189+
address: contractAddress,
190+
chain,
191+
})
192+
: undefined;
193+
194+
if (!contract) {
195+
throw new Error("Contract not found");
203196
}
197+
198+
return resolveContractAbi<Abi>(contract);
204199
},
205-
enabled: !!contract,
200+
enabled: !!contractAddress && !!chainId,
206201
});
207202
}

0 commit comments

Comments
 (0)