Skip to content

Commit 0a7b75f

Browse files
authored
fix: patch native currencies filter (#869)
1 parent c2b984e commit 0a7b75f

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

packages/checkout/widgets-lib/src/lib/balance.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ describe('getAllowedBalances', () => {
1313
formattedBalance: '12.34',
1414
};
1515

16+
const nativeTokenInfo = {
17+
balance: BigNumber.from(2),
18+
token: { symbol: 'AAA', name: 'AAA' } as TokenInfo,
19+
formattedBalance: '6.34',
20+
};
21+
1622
const balances: GetBalanceResult[] = [
1723
tokenInfo,
1824
{
@@ -27,7 +33,7 @@ describe('getAllowedBalances', () => {
2733
},
2834
{
2935
balance: BigNumber.from(1),
30-
token: { symbol: 'CCC', name: 'CCC', address: 'NATIVE' } as TokenInfo,
36+
token: { symbol: 'CCC', name: 'CCC', address: '0xC' } as TokenInfo,
3137
formattedBalance: '36.34',
3238
},
3339
];
@@ -51,6 +57,7 @@ describe('getAllowedBalances', () => {
5157
{
5258
address: '0xQ',
5359
} as unknown as TokenInfo,
60+
{} as unknown as TokenInfo, // <<< allows NATIVE -- no address
5461
],
5562
});
5663

@@ -62,9 +69,15 @@ describe('getAllowedBalances', () => {
6269

6370
expect(resp).toEqual({
6471
allowList: {
65-
tokens: [{ address: tokenInfo.token.address }],
72+
tokens: [
73+
{ address: tokenInfo.token.address },
74+
{ address: nativeTokenInfo.token.address },
75+
],
6676
},
67-
allowedBalances: [tokenInfo],
77+
allowedBalances: [
78+
tokenInfo,
79+
nativeTokenInfo,
80+
],
6881
});
6982
});
7083

packages/checkout/widgets-lib/src/lib/balance.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
TokenFilterTypes,
88
} from '@imtbl/checkout-sdk';
99
import { RetryType, retry } from './retry';
10-
import { DEFAULT_BALANCE_RETRY_POLICY } from './constants';
10+
import { DEFAULT_BALANCE_RETRY_POLICY, NATIVE } from './constants';
1111

1212
export type GetAllowedBalancesParamsType = {
1313
checkout: Checkout,
@@ -49,13 +49,13 @@ export const getAllowedBalances = async ({
4949
});
5050

5151
const tokensAddresses = new Map();
52-
allowList.tokens.forEach((token) => tokensAddresses.set(token.address || '', true));
52+
allowList.tokens.forEach((token) => tokensAddresses.set(token.address || NATIVE, true));
5353

5454
const allowedBalances = tokenBalances.balances.filter((balance) => {
5555
// Balance is <= 0 and it is not allow to have zeros
5656
if (balance.balance.lte(0) && !allowZero) return false;
5757

58-
return tokensAddresses.get(balance.token.address);
58+
return tokensAddresses.get(balance.token.address || NATIVE);
5959
});
6060

6161
return { allowList, allowedBalances };

0 commit comments

Comments
 (0)