Skip to content

Commit e7f42e6

Browse files
[SDK] Fix query cache for block explorers for raw chains (#8257)
1 parent 91ff13b commit e7f42e6

File tree

5 files changed

+48
-38
lines changed

5 files changed

+48
-38
lines changed

.changeset/eight-zoos-invent.md

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

packages/thirdweb/src/extensions/erc721/read/getNFTs.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
4141
"value": "tan",
4242
},
4343
],
44+
"contract_address": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
4445
"description": "A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.",
4546
"image": "ipfs://QmUEfFfwAh4wyB5UfHCVPUxis4j4Q4kJXtm5x5p3g1fVUn",
4647
"image_url": "ipfs://QmUEfFfwAh4wyB5UfHCVPUxis4j4Q4kJXtm5x5p3g1fVUn",
@@ -78,6 +79,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
7879
"value": "gradient 2",
7980
},
8081
],
82+
"contract_address": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
8183
"description": "A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.",
8284
"image": "ipfs://QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9",
8385
"image_url": "ipfs://QmTDxnzcvj2p3xBrKcGv1wxoyhAn2yzCQnZZ9LmFjReuH9",
@@ -115,6 +117,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
115117
"value": "purple",
116118
},
117119
],
120+
"contract_address": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
118121
"description": "A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.",
119122
"image": "ipfs://QmbvZ2hbF3nEq5r3ijMEiSGssAmJvtyFwiejTAGHv74LR5",
120123
"image_url": "ipfs://QmbvZ2hbF3nEq5r3ijMEiSGssAmJvtyFwiejTAGHv74LR5",
@@ -152,6 +155,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
152155
"value": "pale",
153156
},
154157
],
158+
"contract_address": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
155159
"description": "A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.",
156160
"image": "ipfs://QmVpwaCqLut3wqwB5KSQr2fGnbLuJt5e3LhNvzvcisewZB",
157161
"image_url": "ipfs://QmVpwaCqLut3wqwB5KSQr2fGnbLuJt5e3LhNvzvcisewZB",
@@ -189,6 +193,7 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
189193
"value": "purple",
190194
},
191195
],
196+
"contract_address": "0x8a90cab2b38dba80c64b7734e58ee1db38b8992e",
192197
"description": "A community-driven collectibles project featuring art by Burnt Toast. Doodles come in a joyful range of colors, traits and sizes with a collection size of 10,000. Each Doodle allows its owner to vote for experiences and activations paid for by the Doodles Community Treasury. Burnt Toast is the working alias for Scott Martin, a Canadian–based illustrator, designer, animator and muralist.",
193198
"image": "ipfs://QmcyuFVLbfBmSeQ9ynu4dk67r97nB1abEekotuVuRGWedm",
194199
"image_url": "ipfs://QmcyuFVLbfBmSeQ9ynu4dk67r97nB1abEekotuVuRGWedm",

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

Lines changed: 20 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,24 @@ 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
119+
? convertApiChainToChain(chainQuery.data)
120+
: undefined;
132121
return {
133-
explorers: chain?.blockExplorers ?? chainQuery.data?.blockExplorers ?? [],
122+
explorers:
123+
chain?.blockExplorers && chain?.blockExplorers?.length > 0
124+
? chain?.blockExplorers
125+
: (toChain?.blockExplorers ?? []),
134126
isLoading: isEnabled && chainQuery.isLoading,
135127
};
136128
}

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/WalletTransactionHistory.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { useActiveWalletChain } from "../../../../core/hooks/wallets/useActiveWa
2424
import { Container } from "../../components/basic.js";
2525
import { Button } from "../../components/buttons.js";
2626
import { ChainIcon } from "../../components/ChainIcon.js";
27-
import { ChainName } from "../../components/ChainName.js";
2827
import { Spacer } from "../../components/Spacer.js";
2928
import { Spinner } from "../../components/Spinner.js";
3029
import { Text } from "../../components/text.js";
@@ -141,6 +140,7 @@ function TransactionButton(props: {
141140
});
142141
const chainIconQuery = useChainIconUrl(getCachedChain(props.tx.chainId));
143142
const receipt = props.tx.receipt ?? fetchedReceipt;
143+
const decoded = props.tx.decoded;
144144

145145
const content = (
146146
<TxButton
@@ -181,9 +181,7 @@ function TransactionButton(props: {
181181
}}
182182
>
183183
<Text color="primaryText" size="sm">
184-
{receipt?.to
185-
? `Interacted with ${shortenHex(receipt?.to, 4)}`
186-
: `Hash: ${shortenHex(props.tx.transactionHash, 4)}`}
184+
{decoded ? decoded.name : `Transaction Sent`}
187185
</Text>
188186
</Container>
189187

@@ -198,11 +196,11 @@ function TransactionButton(props: {
198196
justifyContent: "space-between",
199197
}}
200198
>
201-
<ChainName
202-
chain={getCachedChain(props.tx.chainId)}
203-
client={props.client}
204-
size="xs"
205-
/>
199+
<Text color="secondaryText" size="xs">
200+
{receipt?.to
201+
? shortenHex(receipt?.to, 4)
202+
: shortenHex(props.tx.transactionHash, 4)}
203+
</Text>
206204
</Container>
207205
</div>
208206
</Container>

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ export type StoredTransaction = {
1111
status: "success" | "failed";
1212
to: string;
1313
};
14+
decoded?: {
15+
name: string;
16+
signature: string;
17+
inputs?: {
18+
[key: string]: unknown;
19+
};
20+
};
1421
};
1522

1623
const transactionsByAddress = new Map<string, Store<StoredTransaction[]>>();
@@ -81,6 +88,7 @@ export async function getPastTransactions(options: {
8188
queryOptions: {
8289
filter_block_timestamp_gte: oneMonthsAgoInSeconds,
8390
limit: 20,
91+
decode: true,
8492
},
8593
walletAddress,
8694
});
@@ -90,9 +98,10 @@ export async function getPastTransactions(options: {
9098
? Number(tx.chain_id)
9199
: (tx.chain_id as number),
92100
receipt: {
93-
status: tx.status === 1 ? "success" : "failed",
101+
status: tx.status === 0 ? "failed" : "success",
94102
to: tx.to_address,
95103
},
96104
transactionHash: tx.hash as Hex,
105+
decoded: tx.decoded,
97106
}));
98107
}

0 commit comments

Comments
 (0)