Skip to content

[SDK] Include native tokens in Insight.getOwnedTokens #7243

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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/shaky-seals-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Include native tokens in Insight.getOwnedTokens
21 changes: 11 additions & 10 deletions packages/thirdweb/src/insight/get-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {
GetV1TokensErc20ByOwnerAddressData,
GetV1TokensData,
GetV1TokensErc20ByOwnerAddressResponse,
} from "@thirdweb-dev/insight";
import type { Chain } from "../chains/types.js";
Expand All @@ -26,10 +26,13 @@ export async function getOwnedTokens(args: {
client: ThirdwebClient;
chains: Chain[];
ownerAddress: string;
queryOptions?: GetV1TokensErc20ByOwnerAddressData["query"];
queryOptions?: Omit<
GetV1TokensData["query"],
"owner_address" | "chain_id" | "chain"
>;
}): Promise<GetWalletBalanceResult[]> {
const [
{ getV1TokensErc20ByOwnerAddress },
{ getV1Tokens },
{ getThirdwebDomains },
{ getClientFetch },
{ assertInsightEnabled },
Expand All @@ -46,19 +49,17 @@ export async function getOwnedTokens(args: {

await assertInsightEnabled(chains);

const defaultQueryOptions: GetV1TokensErc20ByOwnerAddressData["query"] = {
chain: chains.map((chain) => chain.id),
include_spam: "false",
const defaultQueryOptions: GetV1TokensData["query"] = {
owner_address: ownerAddress,
chain_id: chains.map((chain) => chain.id),
include_native: "true",
metadata: "true",
limit: 50,
};

const result = await getV1TokensErc20ByOwnerAddress({
const result = await getV1Tokens({
baseUrl: `https://${getThirdwebDomains().insight}`,
fetch: getClientFetch(client),
path: {
ownerAddress: ownerAddress,
},
query: {
...defaultQueryOptions,
...queryOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ async function fetchBalancesForWallet({
ownerAddress: account.address,
chains: chunk,
client,
queryOptions: {
limit: 100,
},
});

for (const b of owned) {
Expand Down Expand Up @@ -194,7 +197,7 @@ async function fetchBalancesForWallet({
b.chain.id === chainId &&
b.token.address.toLowerCase() === token.address.toLowerCase(),
);
if (isAlreadyFetched && !isNative) {
if (isAlreadyFetched) {
// ERC20 on insight-enabled chain already handled by insight call
continue;
}
Expand Down
Loading