Skip to content

Commit 4ec515b

Browse files
Fix CheckoutWidget transaction invalidation and NFT filtering in connect UI
1 parent be80318 commit 4ec515b

File tree

8 files changed

+25
-21
lines changed

8 files changed

+25
-21
lines changed

.changeset/petite-wasps-leave.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 CheckoutWidget transaction invalidation and fix nft filtering in connect UI

packages/thirdweb/src/extensions/erc1155/read/getOwnedNFTs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async function getOwnedNFTsFromInsight(
6262
chains: [options.contract.chain],
6363
client: options.contract.client,
6464
ownerAddress: options.address,
65-
contractAddress: options.contract.address,
65+
contractAddresses: [options.contract.address],
6666
queryOptions: {
6767
limit,
6868
page,

packages/thirdweb/src/extensions/erc721/read/getOwnedNFTs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async function getOwnedNFTsFromInsight(
7878
chains: [options.contract.chain],
7979
client: options.contract.client,
8080
ownerAddress: options.owner,
81-
contractAddress: options.contract.address,
81+
contractAddresses: [options.contract.address],
8282
queryOptions: {
8383
limit,
8484
page,

packages/thirdweb/src/insight/get-nfts.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function getOwnedNFTs(args: {
3333
client: ThirdwebClient;
3434
chains: Chain[];
3535
ownerAddress: string;
36-
contractAddress?: string;
36+
contractAddresses?: string[];
3737
includeMetadata?: boolean;
3838
queryOptions?: Omit<GetV1NftsData["query"], "owner_address" | "chain">;
3939
}): Promise<(NFT & { quantityOwned: bigint })[]> {
@@ -51,7 +51,7 @@ export async function getOwnedNFTs(args: {
5151
import("viem"),
5252
]);
5353

54-
const { client, chains, ownerAddress, contractAddress, queryOptions } = args;
54+
const { client, chains, ownerAddress, contractAddresses, queryOptions } = args;
5555

5656
await assertInsightEnabled(chains);
5757

@@ -60,7 +60,7 @@ export async function getOwnedNFTs(args: {
6060
// metadata: includeMetadata ? "true" : "false", TODO (insight): add support for this
6161
limit: 50,
6262
owner_address: [ownerAddress],
63-
contract_address: contractAddress ? [contractAddress] : undefined,
63+
contract_address: contractAddresses ? contractAddresses : undefined,
6464
};
6565

6666
const result = await getV1Nfts({

packages/thirdweb/src/insight/get-tokens.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function getOwnedTokens(args: {
2626
client: ThirdwebClient;
2727
chains: Chain[];
2828
ownerAddress: string;
29-
tokenAddress?: string;
29+
tokenAddresses?: string[];
3030
queryOptions?: Omit<
3131
GetV1TokensData["query"],
3232
"owner_address" | "chain_id" | "chain"
@@ -46,7 +46,7 @@ export async function getOwnedTokens(args: {
4646
import("../utils/json.js"),
4747
]);
4848

49-
const { client, chains, ownerAddress, tokenAddress, queryOptions } = args;
49+
const { client, chains, ownerAddress, tokenAddresses, queryOptions } = args;
5050

5151
await assertInsightEnabled(chains);
5252

@@ -57,7 +57,8 @@ export async function getOwnedTokens(args: {
5757
limit: 50,
5858
metadata: "true",
5959
owner_address: [ownerAddress],
60-
token_address: tokenAddress ? [tokenAddress] : undefined,
60+
token_address: tokenAddresses ? tokenAddresses : undefined,
61+
sort_by: "balance",
6162
};
6263

6364
const result = await getV1Tokens({

packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
formatTokenAmount,
2323
} from "../../web/ui/ConnectWallet/screens/formatTokenBalance.js";
2424
import { useChainMetadata } from "./others/useChainQuery.js";
25+
import { stringify } from "../../../utils/json.js";
2526

2627
interface TransactionDetails {
2728
contractMetadata: CompilerMetadata | null;
@@ -180,9 +181,7 @@ export function useTransactionDetails({
180181
},
181182
queryKey: [
182183
"transaction-details",
183-
transaction.to,
184-
transaction.chain.id,
185-
transaction.erc20Value?.toString(),
184+
stringify(transaction),
186185
hasSponsoredTransactions,
187186
],
188187
});

packages/thirdweb/src/react/core/providers/invalidateWalletBalance.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ export function invalidateWalletBalance(
55
chainId?: number,
66
) {
77
queryClient.invalidateQueries({
8-
// invalidate any walletBalance queries for this chainId
9-
// TODO: add wallet address in here if we can get it somehow
108
queryKey: chainId ? ["walletBalance", chainId] : ["walletBalance"],
119
});
1210
queryClient.invalidateQueries({
1311
queryKey: chainId
1412
? ["internal_account_balance", chainId]
1513
: ["internal_account_balance"],
1614
});
15+
queryClient.invalidateQueries({
16+
queryKey: chainId ? ["nfts", chainId] : ["nfts"],
17+
});
18+
queryClient.invalidateQueries({
19+
queryKey: chainId ? ["tokens", chainId] : ["tokens"],
20+
});
1721
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export function ViewNFTsContent(props: {
127127
chains: [activeChain],
128128
client: props.client,
129129
ownerAddress: activeAccount.address,
130+
contractAddresses: props.supportedNFTs?.[activeChain.id]?.map((nft) => nft.toLowerCase()),
130131
});
131132

132133
return result
@@ -139,20 +140,14 @@ export function ViewNFTsContent(props: {
139140
};
140141
});
141142
},
142-
queryKey: ["nfts", activeChain?.id, activeAccount?.address],
143+
queryKey: ["nfts", activeChain?.id, activeAccount?.address, props.supportedNFTs],
143144
});
144145

145146
if (!activeChain?.id || !activeAccount?.address) {
146147
return null;
147148
}
148149

149-
const filteredNFTs = props.supportedNFTs?.[activeChain.id]
150-
? nftQuery.data?.filter((nft) =>
151-
props.supportedNFTs?.[activeChain.id]
152-
?.map((supportedNFTAddress) => supportedNFTAddress.toLowerCase())
153-
.includes(nft.address.toLowerCase()),
154-
)
155-
: nftQuery.data;
150+
const filteredNFTs = nftQuery.data;
156151

157152
return (
158153
<>

0 commit comments

Comments
 (0)