Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge-ui-v2): check destination funds for ETH #14762

Merged
merged 10 commits into from
Sep 20, 2023
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