Skip to content

Commit

Permalink
fix(bridge-ui-v2): check destination funds for ETH (#14762)
Browse files Browse the repository at this point in the history
  • Loading branch information
KorbinianK authored Sep 20, 2023
1 parent c6e23ad commit fa2e842
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
export let calculating = false;
export let error = false;
async function compute(token: Maybe<Token>, userAddress?: Address, srcChainId?: number, destChainId?: number) {
if (!token || !userAddress || !srcChainId || !destChainId) {
async function compute(token: Maybe<Token>, userAddress?: Address, srcChain?: number, destChain?: number) {
if (!token || !userAddress || !srcChain || !destChain) {
enoughEth = false;
return;
}
Expand All @@ -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?
Expand Down
5 changes: 4 additions & 1 deletion packages/bridge-ui-v2/src/libs/token/getBalance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge-ui-v2/src/libs/token/getBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

1 comment on commit fa2e842

@vercel
Copy link

@vercel vercel bot commented on fa2e842 Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bridge-ui-v2-internal – ./packages/bridge-ui-v2

bridge-ui-v2-internal-git-main-taikoxyz.vercel.app
bridge-ui-v2-internal-taikoxyz.vercel.app
bridge-ui-v2-internal.vercel.app

Please sign in to comment.