diff --git a/composables/zksync/deposit/useFee.ts b/composables/zksync/deposit/useFee.ts index 167f713ea..fb843580f 100644 --- a/composables/zksync/deposit/useFee.ts +++ b/composables/zksync/deposit/useFee.ts @@ -59,24 +59,12 @@ export default (tokens: Ref, balances: Ref) const signer = getL1VoidSigner(); if (!signer) throw new Error("Signer is not available"); - return await retry(async () => { - try { - return await signer.getFullRequiredDepositFee({ - token: ETH_TOKEN.l1Address!, - to: params.to, - }); - } catch (err) { - if (err instanceof Error && err.message.startsWith("Not enough balance for deposit!")) { - const match = err.message.match(/([\d\\.]+) ETH/); - if (feeToken.value && match?.length) { - const ethAmount = match[1].split(" ")?.[0]; - recommendedBalance.value = parseEther(ethAmount); - return; - } - } - throw err; - } - }); + return await retry(() => + signer.getFullRequiredDepositFee({ + token: ETH_TOKEN.l1Address!, + to: params.to, + }) + ); }; const getERC20TransactionFee = () => { return { @@ -98,10 +86,25 @@ export default (tokens: Ref, balances: Ref) recommendedBalance.value = undefined; if (!feeToken.value) throw new Error("Fee tokens is not available"); - if (params.tokenAddress === feeToken.value?.address) { - fee.value = await getEthTransactionFee(); - } else { - fee.value = getERC20TransactionFee(); + try { + if (params.tokenAddress === feeToken.value?.address) { + fee.value = await getEthTransactionFee(); + } else { + fee.value = getERC20TransactionFee(); + } + } catch (err) { + const message = (err as any)?.message; + if (message?.startsWith("Not enough balance for deposit!")) { + const match = message.match(/([\d\\.]+) ETH/); + if (feeToken.value && match?.length) { + const ethAmount = match[1].split(" ")?.[0]; + recommendedBalance.value = parseEther(ethAmount); + return; + } + } else if (message?.includes("insufficient funds for gas * price + value")) { + throw new Error("Insufficient funds to cover deposit fee! Please, top up your account with ETH."); + } + throw err; } /* It can be either maxFeePerGas or gasPrice */ if (fee.value && !fee.value?.maxFeePerGas) { diff --git a/utils/formatters.ts b/utils/formatters.ts index 834c892c4..6d8309dc7 100644 --- a/utils/formatters.ts +++ b/utils/formatters.ts @@ -121,6 +121,8 @@ export function formatError(error?: Error) { (error instanceof BaseError && error?.details?.startsWith("Failed to fetch")) ) { return new Error("Network error. Check your internet connection and try again."); + } else if (message.includes("missing response")) { + return new Error("Server error. Please try again later."); } else if ( // eslint-disable-next-line prettier/prettier message.includes("\"finalizeEthWithdrawal\" reverted with the following reason: xx") ||