Skip to content

Commit 9e63e63

Browse files
[SDK] Include native tokens in Insight.getOwnedTokens
1 parent f10fbc8 commit 9e63e63

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

.changeset/shaky-seals-cheer.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+
Include native tokens in Insight.getOwnedTokens

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {
2-
GetV1TokensErc20ByOwnerAddressData,
2+
GetV1TokensData,
33
GetV1TokensErc20ByOwnerAddressResponse,
44
} from "@thirdweb-dev/insight";
55
import type { Chain } from "../chains/types.js";
@@ -26,10 +26,13 @@ export async function getOwnedTokens(args: {
2626
client: ThirdwebClient;
2727
chains: Chain[];
2828
ownerAddress: string;
29-
queryOptions?: GetV1TokensErc20ByOwnerAddressData["query"];
29+
queryOptions?: Omit<
30+
GetV1TokensData["query"],
31+
"owner_address" | "chain_id" | "chain"
32+
>;
3033
}): Promise<GetWalletBalanceResult[]> {
3134
const [
32-
{ getV1TokensErc20ByOwnerAddress },
35+
{ getV1Tokens },
3336
{ getThirdwebDomains },
3437
{ getClientFetch },
3538
{ assertInsightEnabled },
@@ -46,19 +49,17 @@ export async function getOwnedTokens(args: {
4649

4750
await assertInsightEnabled(chains);
4851

49-
const defaultQueryOptions: GetV1TokensErc20ByOwnerAddressData["query"] = {
50-
chain: chains.map((chain) => chain.id),
51-
include_spam: "false",
52+
const defaultQueryOptions: GetV1TokensData["query"] = {
53+
owner_address: ownerAddress,
54+
chain_id: chains.map((chain) => chain.id),
55+
include_native: "true",
5256
metadata: "true",
5357
limit: 50,
5458
};
5559

56-
const result = await getV1TokensErc20ByOwnerAddress({
60+
const result = await getV1Tokens({
5761
baseUrl: `https://${getThirdwebDomains().insight}`,
5862
fetch: getClientFetch(client),
59-
path: {
60-
ownerAddress: ownerAddress,
61-
},
6263
query: {
6364
...defaultQueryOptions,
6465
...queryOptions,

packages/thirdweb/src/react/web/ui/ConnectWallet/screens/Buy/swap/fetchBalancesForWallet.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ async function fetchBalancesForWallet({
145145
ownerAddress: account.address,
146146
chains: chunk,
147147
client,
148+
queryOptions: {
149+
limit: 100,
150+
},
148151
});
149152

150153
for (const b of owned) {
@@ -194,7 +197,7 @@ async function fetchBalancesForWallet({
194197
b.chain.id === chainId &&
195198
b.token.address.toLowerCase() === token.address.toLowerCase(),
196199
);
197-
if (isAlreadyFetched && !isNative) {
200+
if (isAlreadyFetched) {
198201
// ERC20 on insight-enabled chain already handled by insight call
199202
continue;
200203
}

0 commit comments

Comments
 (0)