Skip to content

Commit

Permalink
[SDK, React] - useContract fail fast (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnsdls committed Dec 5, 2022
1 parent e173636 commit 7a37e56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/sour-numbers-refuse.md
@@ -0,0 +1,6 @@
---
"@thirdweb-dev/react": patch
"@thirdweb-dev/sdk": patch
---

[EVM] - allow `useContract` to fail faster to enable the import case
4 changes: 3 additions & 1 deletion packages/react/src/evm/hooks/async/contracts.ts
Expand Up @@ -238,7 +238,7 @@ export function useContract(
await queryClient.fetchQuery(
compilerMetadata.cacheKey(contractAddress, activeChainId),
() => compilerMetadata.fetchQuery(contractAddress, sdk),
{ cacheTime: Infinity, staleTime: Infinity },
{ cacheTime: Infinity, staleTime: Infinity, retry: 0 },
)
)?.abi;
}
Expand All @@ -258,6 +258,8 @@ export function useContract(
cacheTime: Infinity,
staleTime: Infinity,
enabled: !!contractAddress && !!sdk && !!activeChainId,
// never retry
retry: 0,
},
);

Expand Down
5 changes: 5 additions & 0 deletions packages/sdk/src/evm/common/feature-detection.ts
Expand Up @@ -442,6 +442,11 @@ export async function fetchContractMetadata(
storage: ThirdwebStorage,
): Promise<PublishedMetadata> {
const metadata = await storage.downloadJSON(compilerMetadataUri);
if (!metadata || !metadata.output) {
throw new Error(
`Could not resolve metadata for contract at ${compilerMetadataUri}`,
);
}
const abi = AbiSchema.parse(metadata.output.abi);
const compilationTarget = metadata.settings.compilationTarget;
const targets = Object.keys(compilationTarget);
Expand Down

0 comments on commit 7a37e56

Please sign in to comment.