From fa2e842c256c28713c3ebd9a50a99f945048df12 Mon Sep 17 00:00:00 2001 From: Korbinian Date: Wed, 20 Sep 2023 14:53:15 +0200 Subject: [PATCH] fix(bridge-ui-v2): check destination funds for ETH (#14762) --- .../components/Bridge/ProcessingFee/NoneOption.svelte | 10 +++++----- .../bridge-ui-v2/src/libs/token/getBalance.test.ts | 5 ++++- packages/bridge-ui-v2/src/libs/token/getBalance.ts | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/bridge-ui-v2/src/components/Bridge/ProcessingFee/NoneOption.svelte b/packages/bridge-ui-v2/src/components/Bridge/ProcessingFee/NoneOption.svelte index 603c6aaf41c..6cf2d4da7ec 100644 --- a/packages/bridge-ui-v2/src/components/Bridge/ProcessingFee/NoneOption.svelte +++ b/packages/bridge-ui-v2/src/components/Bridge/ProcessingFee/NoneOption.svelte @@ -11,8 +11,8 @@ export let calculating = false; export let error = false; - async function compute(token: Maybe, userAddress?: Address, srcChainId?: number, destChainId?: number) { - if (!token || !userAddress || !srcChainId || !destChainId) { + async function compute(token: Maybe, userAddress?: Address, srcChain?: number, destChain?: number) { + if (!token || !userAddress || !srcChain || !destChain) { enoughEth = false; return; } @@ -25,14 +25,14 @@ // Get the balance of the user on the destination chain destBalance = await getBalance({ userAddress, - srcChainId: destChainId, + srcChainId: destChain, }); // Calculate the recommended amount of ETH needed for processMessage call const recommendedAmount = await recommendProcessingFee({ token, - destChainId, - srcChainId, + destChainId: destChain, + srcChainId: srcChain, }); // Does the user have enough ETH to claim manually on the destination chain? diff --git a/packages/bridge-ui-v2/src/libs/token/getBalance.test.ts b/packages/bridge-ui-v2/src/libs/token/getBalance.test.ts index 6a17133be05..e0873f2336c 100644 --- a/packages/bridge-ui-v2/src/libs/token/getBalance.test.ts +++ b/packages/bridge-ui-v2/src/libs/token/getBalance.test.ts @@ -64,7 +64,10 @@ describe('getBalance', () => { expect(balance).toEqual(mockBalanceForETH); expect(getAddress).not.toHaveBeenCalled(); - expect(fetchBalance).toHaveBeenCalledWith({ address: mockWalletClient.account.address }); + expect(fetchBalance).toHaveBeenCalledWith({ + address: mockWalletClient.account.address, + chainId: Number(PUBLIC_L1_CHAIN_ID), + }); }); it('should return the balance of ERC20 token', async () => { diff --git a/packages/bridge-ui-v2/src/libs/token/getBalance.ts b/packages/bridge-ui-v2/src/libs/token/getBalance.ts index a4710f8c79f..feeb240b3b3 100644 --- a/packages/bridge-ui-v2/src/libs/token/getBalance.ts +++ b/packages/bridge-ui-v2/src/libs/token/getBalance.ts @@ -20,7 +20,7 @@ export async function getBalance({ userAddress, token, srcChainId, destChainId } if (!token || token.type === TokenType.ETH) { // If no token is passed in, we assume is ETH - tokenBalance = await fetchBalance({ address: userAddress }); + tokenBalance = await fetchBalance({ address: userAddress, chainId: srcChainId }); } else { // We need at least the source chain to find the address if (!srcChainId) return;