Skip to content

Commit 47019c8

Browse files
committed
feat: log the failing of fetching of tokens
1 parent 0d978bf commit 47019c8

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

apps/main/src/dex/store/createUserBalancesSlice.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,26 @@ const createUserBalancesSlice = (
6161
sliceState.setStateByKey('loading', true)
6262

6363
// This gets multicall batched by Wagmi and Viem internally
64-
const balances = await Promise.all(
64+
const balances = await Promise.allSettled(
6565
filteredBadTokens.map((token) =>
6666
fetchTokenBalance(config, {
6767
chainId,
6868
userAddress: signerAddress,
6969
tokenAddress: token as Address,
70-
}).then((balance) => [token, balance]),
70+
}).then((balance) => [token, balance] as const),
7171
),
7272
)
7373

74-
const userBalancesMapper = Object.fromEntries(balances)
74+
balances.forEach((result, index) => {
75+
if (result.status === 'rejected') {
76+
console.warn(`Failed to fetch balance for token ${filteredBadTokens[index]}:`, result.reason)
77+
}
78+
})
79+
80+
const userBalancesMapper = Object.fromEntries(
81+
balances.filter((x) => x.status === 'fulfilled').map((x) => x.value),
82+
)
83+
7584
sliceState.setStateByKeys({
7685
userBalancesMapper: { ...storedUserBalancesMapper, ...userBalancesMapper },
7786
loading: false,

0 commit comments

Comments
 (0)