Skip to content

Commit

Permalink
fix: improve errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JackHamer09 committed May 23, 2024
1 parent 33153b5 commit ce4f257
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
47 changes: 25 additions & 22 deletions composables/zksync/deposit/useFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,12 @@ export default (tokens: Ref<Token[]>, balances: Ref<TokenAmount[] | undefined>)
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 {
Expand All @@ -98,10 +86,25 @@ export default (tokens: Ref<Token[]>, balances: Ref<TokenAmount[] | undefined>)
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) {
Expand Down
2 changes: 2 additions & 0 deletions utils/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") ||
Expand Down

0 comments on commit ce4f257

Please sign in to comment.