diff --git a/packages/checkout/widgets-lib/src/lib/balance.test.ts b/packages/checkout/widgets-lib/src/lib/balance.test.ts index 88194c4ff1..946fe22096 100644 --- a/packages/checkout/widgets-lib/src/lib/balance.test.ts +++ b/packages/checkout/widgets-lib/src/lib/balance.test.ts @@ -36,6 +36,11 @@ describe('getAllowedBalances', () => { token: { symbol: 'CCC', name: 'CCC', address: '0xC' } as TokenInfo, formattedBalance: '36.34', }, + { + balance: BigNumber.from(1), + token: { symbol: 'DDD', name: 'DDD', address: '0xd' } as TokenInfo, + formattedBalance: '36.34', + }, ]; it('should return allowList and allowedBalances', async () => { @@ -271,6 +276,46 @@ describe('getAllowedBalances', () => { }); }); + it('should return allowedBalances when casing on address is different', async () => { + const checkout = new Checkout({ + baseConfig: { environment: Environment.PRODUCTION }, + }); + + const mockProvider = { + getSigner: jest.fn().mockReturnValue({ + getAddress: jest.fn().mockResolvedValue('0xaddress'), + }), + }; + jest.spyOn(checkout, 'getNetworkInfo').mockResolvedValue( + { chainId: ChainId.IMTBL_ZKEVM_MAINNET } as unknown as NetworkInfo, + ); + jest.spyOn(checkout, 'getAllBalances').mockResolvedValue({ balances }); + jest.spyOn(checkout, 'getTokenAllowList').mockResolvedValue({ + tokens: [ + { + address: '0xD', + } as unknown as TokenInfo, + ], + }); + + const resp = await getAllowedBalances({ + checkout, + provider: mockProvider as unknown as Web3Provider, + allowTokenListType: TokenFilterTypes.BRIDGE, + }); + + expect(resp).toEqual({ + allowList: { + tokens: [{ address: '0xD' }], + }, + allowedBalances: [{ + balance: BigNumber.from(1), + token: { symbol: 'DDD', name: 'DDD', address: '0xd' } as TokenInfo, + formattedBalance: '36.34', + }], + }); + }); + it('should not return native address or empty address', async () => { const checkout = new Checkout({ baseConfig: { environment: Environment.PRODUCTION }, diff --git a/packages/checkout/widgets-lib/src/lib/balance.ts b/packages/checkout/widgets-lib/src/lib/balance.ts index 6051992ea0..3532f6bdd8 100644 --- a/packages/checkout/widgets-lib/src/lib/balance.ts +++ b/packages/checkout/widgets-lib/src/lib/balance.ts @@ -60,13 +60,13 @@ export const getAllowedBalances = async ({ }); const tokensAddresses = new Map(); - allowList.tokens.forEach((token) => tokensAddresses.set(token.address || NATIVE, true)); + allowList.tokens.forEach((token) => tokensAddresses.set(token.address?.toLowerCase() || NATIVE, true)); const allowedBalances = tokenBalances.balances.filter((balance) => { // Balance is <= 0 and it is not allow to have zeros if (balance.balance.lte(0) && !allowZero) return false; - return tokensAddresses.get(balance.token.address || NATIVE); + return tokensAddresses.get(balance.token.address?.toLowerCase() || NATIVE); }) ?? []; return { allowList, allowedBalances };