Skip to content

Commit 0509f94

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

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,27 @@ 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 and filter out zero balances
124+
const tokensWithBalance = batch
125+
.filter((b) => b.value > 0n)
126+
.map((b) => ({
127+
balance: b.value,
128+
originToken: {
129+
address: b.tokenAddress,
130+
chainId: b.chainId,
131+
decimals: b.decimals,
132+
iconUri: "",
133+
name: b.name,
134+
prices: {
135+
USD: 0,
136+
},
137+
symbol: b.symbol,
138+
} as Token,
139+
}));
140+
141+
allOwnedTokens = [...allOwnedTokens, ...tokensWithBalance];
142+
break;
122143
}
123144

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

0 commit comments

Comments
 (0)