Skip to content

Commit 94edde6

Browse files
committed
Filter out zero balance tokens
1 parent 9345706 commit 94edde6

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

packages/checkout/sdk/src/balances/balances.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,19 @@ export const getBalances = async (
238238
});
239239

240240
const balanceResults = await Promise.allSettled(allBalancePromises);
241-
const balances = (balanceResults.filter(
242-
(result) => result.status === 'fulfilled',
243-
) as PromiseFulfilledResult<GetBalanceResult>[]
244-
).map((result) => {
245-
const resp = result;
246-
const { token } = resp.value;
247-
// For some reason isNativeToken always returns undefined.
248-
// We have spent way too much time figuring out why this is happening.
249-
// That we have given up -- keep it as it is for now.
250-
if (!token.address || isMatchingAddress(token.address, NATIVE)) resp.value.token.address = NATIVE;
251-
return resp.value;
252-
});
253241

254-
return { balances };
242+
return balanceResults.reduce((acc, resp) => {
243+
if (resp.status !== 'fulfilled' || resp.value.balance === 0n) return acc;
244+
245+
const { value: result } = resp;
246+
247+
if (!result.token.address || isMatchingAddress(result.token.address, NATIVE)) {
248+
result.token.address = NATIVE;
249+
}
250+
251+
acc.balances.push(result);
252+
return acc;
253+
}, { balances: new Array<GetBalanceResult>() });
255254
};
256255

257256
const getTokenBalances = async (

0 commit comments

Comments
 (0)