Skip to content

Fix CheckoutWidget transaction invalidation and NFT filtering in connect UI #7761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/petite-wasps-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fix CheckoutWidget transaction invalidation and fix nft filtering in connect UI
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function getOwnedNFTsFromInsight(
chains: [options.contract.chain],
client: options.contract.client,
ownerAddress: options.address,
contractAddress: options.contract.address,
contractAddresses: [options.contract.address],
queryOptions: {
limit,
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function getOwnedNFTsFromInsight(
chains: [options.contract.chain],
client: options.contract.client,
ownerAddress: options.owner,
contractAddress: options.contract.address,
contractAddresses: [options.contract.address],
queryOptions: {
limit,
page,
Expand Down
7 changes: 4 additions & 3 deletions packages/thirdweb/src/insight/get-nfts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function getOwnedNFTs(args: {
client: ThirdwebClient;
chains: Chain[];
ownerAddress: string;
contractAddress?: string;
contractAddresses?: string[];
includeMetadata?: boolean;
queryOptions?: Omit<GetV1NftsData["query"], "owner_address" | "chain">;
}): Promise<(NFT & { quantityOwned: bigint })[]> {
Expand All @@ -51,7 +51,8 @@ export async function getOwnedNFTs(args: {
import("viem"),
]);

const { client, chains, ownerAddress, contractAddress, queryOptions } = args;
const { client, chains, ownerAddress, contractAddresses, queryOptions } =
args;

await assertInsightEnabled(chains);

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

const result = await getV1Nfts({
Expand Down
7 changes: 4 additions & 3 deletions packages/thirdweb/src/insight/get-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
client: ThirdwebClient;
chains: Chain[];
ownerAddress: string;
tokenAddress?: string;
tokenAddresses?: string[];
queryOptions?: Omit<
GetV1TokensData["query"],
"owner_address" | "chain_id" | "chain"
Expand All @@ -46,7 +46,7 @@
import("../utils/json.js"),
]);

const { client, chains, ownerAddress, tokenAddress, queryOptions } = args;
const { client, chains, ownerAddress, tokenAddresses, queryOptions } = args;

Check warning on line 49 in packages/thirdweb/src/insight/get-tokens.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L49 was not covered by tests

await assertInsightEnabled(chains);

Expand All @@ -57,7 +57,8 @@
limit: 50,
metadata: "true",
owner_address: [ownerAddress],
token_address: tokenAddress ? [tokenAddress] : undefined,
token_address: tokenAddresses ? tokenAddresses : undefined,
sort_by: "balance",

Check warning on line 61 in packages/thirdweb/src/insight/get-tokens.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/insight/get-tokens.ts#L60-L61

Added lines #L60 - L61 were not covered by tests
};

const result = await getV1Tokens({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import { encode } from "../../../transaction/actions/encode.js";
import type { PreparedTransaction } from "../../../transaction/prepare-transaction.js";
import { getTransactionGasCost } from "../../../transaction/utils.js";
import { stringify } from "../../../utils/json.js";
import { resolvePromisedValue } from "../../../utils/promise/resolve-promised-value.js";
import { toTokens } from "../../../utils/units.js";
import type { Wallet } from "../../../wallets/interfaces/wallet.js";
Expand Down Expand Up @@ -180,9 +181,7 @@
},
queryKey: [
"transaction-details",
transaction.to,
transaction.chain.id,
transaction.erc20Value?.toString(),
stringify(transaction),

Check warning on line 184 in packages/thirdweb/src/react/core/hooks/useTransactionDetails.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L184 was not covered by tests
hasSponsoredTransactions,
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ export function invalidateWalletBalance(
chainId?: number,
) {
queryClient.invalidateQueries({
// invalidate any walletBalance queries for this chainId
// TODO: add wallet address in here if we can get it somehow
queryKey: chainId ? ["walletBalance", chainId] : ["walletBalance"],
});
queryClient.invalidateQueries({
queryKey: chainId
? ["internal_account_balance", chainId]
: ["internal_account_balance"],
});
queryClient.invalidateQueries({
queryKey: chainId ? ["nfts", chainId] : ["nfts"],
});
queryClient.invalidateQueries({
queryKey: chainId ? ["tokens", chainId] : ["tokens"],
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
chains: [activeChain],
client: props.client,
ownerAddress: activeAccount.address,
contractAddresses: props.supportedNFTs?.[activeChain.id]?.map((nft) =>
nft.toLowerCase(),
),

Check warning on line 132 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx#L130-L132

Added lines #L130 - L132 were not covered by tests
});

return result
Expand All @@ -139,20 +142,19 @@
};
});
},
queryKey: ["nfts", activeChain?.id, activeAccount?.address],
queryKey: [
"nfts",
activeChain?.id,
activeAccount?.address,
props.supportedNFTs,
],

Check warning on line 150 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx#L145-L150

Added lines #L145 - L150 were not covered by tests
});

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

const filteredNFTs = props.supportedNFTs?.[activeChain.id]
? nftQuery.data?.filter((nft) =>
props.supportedNFTs?.[activeChain.id]
?.map((supportedNFTAddress) => supportedNFTAddress.toLowerCase())
.includes(nft.address.toLowerCase()),
)
: nftQuery.data;
const filteredNFTs = nftQuery.data;

Check warning on line 157 in packages/thirdweb/src/react/web/ui/ConnectWallet/screens/ViewNFTs.tsx

View check run for this annotation

Codecov / codecov/patch

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

Added line #L157 was not covered by tests

return (
<>
Expand Down
Loading