Skip to content

Commit b6d685f

Browse files
Fix query cache for block explorers for raw chains
1 parent 47354d5 commit b6d685f

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

.changeset/eight-zoos-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix query cache for block explorers for raw chains

packages/thirdweb/src/react/core/hooks/others/useChainQuery.ts

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@ export function useChainName(chain?: Chain) {
1515
// only if we have a chain and no chain name!
1616
const isEnabled = !!chain && !chain.name;
1717
const chainQuery = useQuery({
18-
enabled: isEnabled,
1918
queryFn: async () => {
2019
if (!chain) {
2120
throw new Error("chain is required");
2221
}
2322
return convertApiChainToChain(await getChainMetadata(chain));
2423
},
25-
queryKey: ["chain", chain?.id],
24+
...getQueryOptions(chain),
25+
enabled: isEnabled,
2626
retry: false,
27-
// 1 hour
28-
staleTime: 60 * 60 * 1000,
2927
});
3028

3129
return {
@@ -39,17 +37,15 @@ export function useChainIconUrl(chain?: Chain) {
3937
const isEnabled = !!chain && !chain.icon?.url;
4038
const chainQuery = useQuery({
4139
// only if we have a chain and no chain icon url!
42-
enabled: isEnabled,
4340
queryFn: async () => {
4441
if (!chain) {
4542
throw new Error("chain is required");
4643
}
4744
return convertApiChainToChain(await getChainMetadata(chain));
4845
},
49-
queryKey: ["chain", chain?.id],
46+
...getQueryOptions(chain),
47+
enabled: isEnabled,
5048
retry: false,
51-
// 1 hour
52-
staleTime: 60 * 60 * 1000,
5349
});
5450

5551
return {
@@ -67,17 +63,14 @@ export function useChainFaucets(chain?: Chain) {
6763
chain.id !== 1337;
6864

6965
const chainQuery = useQuery({
70-
enabled: isEnabled,
7166
queryFn: async () => {
7267
if (!chain) {
7368
throw new Error("chain is required");
7469
}
75-
return convertApiChainToChain(await getChainMetadata(chain));
70+
return getChainMetadata(chain);
7671
},
77-
queryKey: ["chain", chain?.id],
78-
retry: false,
79-
// 1 hour
80-
staleTime: 60 * 60 * 1000,
72+
...getQueryOptions(chain),
73+
enabled: isEnabled,
8174
});
8275

8376
return {
@@ -90,18 +83,14 @@ export function useChainSymbol(chain?: Chain) {
9083
// only if we have a chain and no chain icon url!
9184
const isEnabled = !!chain && !chain.nativeCurrency?.symbol;
9285
const chainQuery = useQuery({
93-
// only if we have a chain and no chain icon url!
94-
enabled: isEnabled,
9586
queryFn: async () => {
9687
if (!chain) {
9788
throw new Error("chain is required");
9889
}
99-
return convertApiChainToChain(await getChainMetadata(chain));
90+
return getChainMetadata(chain);
10091
},
101-
queryKey: ["chain", chain?.id],
102-
retry: false,
103-
// 1 hour
104-
staleTime: 60 * 60 * 1000,
92+
...getQueryOptions(chain),
93+
enabled: isEnabled,
10594
});
10695

10796
return {
@@ -116,21 +105,19 @@ export function useChainExplorers(chain?: Chain) {
116105
const isEnabled = !!chain && !chain.blockExplorers?.length;
117106

118107
const chainQuery = useQuery({
119-
enabled: isEnabled,
120108
queryFn: async () => {
121109
if (!chain) {
122110
throw new Error("chain is required");
123111
}
124-
return convertApiChainToChain(await getChainMetadata(chain));
112+
return getChainMetadata(chain);
125113
},
126-
queryKey: ["chain", chain?.id],
127-
retry: false,
128-
// 1 hour
129-
staleTime: 60 * 60 * 1000,
114+
...getQueryOptions(chain),
115+
enabled: isEnabled,
130116
});
131117

118+
const toChain = chainQuery.data ?convertApiChainToChain(chainQuery.data) : undefined;
132119
return {
133-
explorers: chain?.blockExplorers ?? chainQuery.data?.blockExplorers ?? [],
120+
explorers: chain?.blockExplorers && chain?.blockExplorers?.length > 0 ? chain?.blockExplorers : toChain?.blockExplorers ?? [],
134121
isLoading: isEnabled && chainQuery.isLoading,
135122
};
136123
}

packages/thirdweb/src/transaction/transaction-store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export async function getPastTransactions(options: {
9090
? Number(tx.chain_id)
9191
: (tx.chain_id as number),
9292
receipt: {
93-
status: tx.status === 1 ? "success" : "failed",
93+
status: tx.status === 0 ? "failed" : "success",
9494
to: tx.to_address,
9595
},
9696
transactionHash: tx.hash as Hex,

0 commit comments

Comments
 (0)