Skip to content

Commit 2dbc389

Browse files
[React] Fix native token fallback when insight query fails
1 parent 22bf68a commit 2dbc389

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

.changeset/eighty-rings-think.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 native token fallback when insight query fails

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ export function usePaymentMethods(options: {
7070
getInsightEnabledChainIds(),
7171
]);
7272

73-
// 2. Check insight availability for all chains
73+
// 2. Check insight availability for all chains, limited to 50 chains (FIXME move this logic to the backend)
7474
const insightEnabledChains = allChains.filter((c) =>
7575
insightEnabledChainIds.includes(c.chainId),
76-
);
76+
).slice(0, 50);
7777

7878
// 3. Get all owned tokens for insight-enabled chains
7979
let allOwnedTokens: Array<{
@@ -119,6 +119,26 @@ export function usePaymentMethods(options: {
119119
.filter((result) => result.status === "fulfilled")
120120
.map((result) => result.value)
121121
.filter((balance) => balance.value > 0n);
122+
123+
// Convert to our format
124+
const tokensWithBalance = batch
125+
.map((b) => ({
126+
balance: b.value,
127+
originToken: {
128+
address: b.tokenAddress,
129+
chainId: b.chainId,
130+
decimals: b.decimals,
131+
iconUri: "",
132+
name: b.name,
133+
prices: {
134+
USD: 0,
135+
},
136+
symbol: b.symbol,
137+
} as Token,
138+
}));
139+
140+
allOwnedTokens = [...allOwnedTokens, ...tokensWithBalance];
141+
break;
122142
}
123143

124144
if (batch.length === 0) {

0 commit comments

Comments
 (0)