Skip to content

Commit d35b6fc

Browse files
Fix CheckoutWidget transaction invalidation and NFT filtering in connect UI (#7761)
1 parent bcb3b92 commit d35b6fc

File tree

8 files changed

+33
-21
lines changed

8 files changed

+33
-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: 4 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,8 @@ 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 } =
55+
args;
5556

5657
await assertInsightEnabled(chains);
5758

@@ -60,7 +61,7 @@ export async function getOwnedNFTs(args: {
6061
// metadata: includeMetadata ? "true" : "false", TODO (insight): add support for this
6162
limit: 50,
6263
owner_address: [ownerAddress],
63-
contract_address: contractAddress ? [contractAddress] : undefined,
64+
contract_address: contractAddresses ? contractAddresses : undefined,
6465
};
6566

6667
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
@@ -13,6 +13,7 @@ import type { SupportedFiatCurrency } from "../../../pay/convert/type.js";
1313
import { encode } from "../../../transaction/actions/encode.js";
1414
import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js";
1515
import { getTransactionGasCost } from "../../../transaction/utils.js";
16+
import { stringify } from "../../../utils/json.js";
1617
import { resolvePromisedValue } from "../../../utils/promise/resolve-promised-value.js";
1718
import { toTokens } from "../../../utils/units.js";
1819
import type { Wallet } from "../../../wallets/interfaces/wallet.js";
@@ -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: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export function ViewNFTsContent(props: {
127127
chains: [activeChain],
128128
client: props.client,
129129
ownerAddress: activeAccount.address,
130+
contractAddresses: props.supportedNFTs?.[activeChain.id]?.map((nft) =>
131+
nft.toLowerCase(),
132+
),
130133
});
131134

132135
return result
@@ -139,20 +142,19 @@ export function ViewNFTsContent(props: {
139142
};
140143
});
141144
},
142-
queryKey: ["nfts", activeChain?.id, activeAccount?.address],
145+
queryKey: [
146+
"nfts",
147+
activeChain?.id,
148+
activeAccount?.address,
149+
props.supportedNFTs,
150+
],
143151
});
144152

145153
if (!activeChain?.id || !activeAccount?.address) {
146154
return null;
147155
}
148156

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;
157+
const filteredNFTs = nftQuery.data;
156158

157159
return (
158160
<>

0 commit comments

Comments
 (0)