Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
chore: improve low gas balance message on Solana
  • Loading branch information
kyleleighton committed Sep 16, 2025
commit 21396e574e4d3068fbf0f4a9f8579adb03b9b4c0
31 changes: 19 additions & 12 deletions src/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import {
} from 'telemetry/types';
import { InsufficientFundsForGasError } from 'sdklegacy';
import { routes, amount as sdkAmount } from '@wormhole-foundation/sdk';
import { chainDisplayName, getGasToken, getTokenSymbol } from 'utils';

// TODO SDKV2
// attempt to capture errors using regex
export const INSUFFICIENT_ALLOWANCE_REGEX = /insufficient token allowance/im;
export const INSUFFICIENT_LAMPORTS_REGEX =
/insufficient lamports.*?(\d+).*?(\d+)/im;
export const SIMULATION_ACCOUNT_NOT_FOUND_REGEX =
/simulation failed:.*accountnotfound/i;
export const USER_REJECTED_REGEX = new RegExp(
'user rejected|rejected the request|rejected from user|user cancel|aborted by user|plugin closed|denied request signature',
'mi',
Expand Down Expand Up @@ -50,7 +53,8 @@ export function interpretTransferError(
uiErrorMessage = 'Transfer timed out, please try again';
internalErrorCode = ERR_TIMEOUT;
} else if (InsufficientFundsForGasError.MESSAGE_REGEX.test(e?.message)) {
uiErrorMessage = 'Insufficient funds';
uiErrorMessage =
'Insufficient funds for network fees, please add more funds and try again';
internalErrorCode = ERR_INSUFFICIENT_GAS;
} else if (USER_REJECTED_REGEX.test(e?.message)) {
uiErrorMessage = 'Transfer rejected in wallet, please try again';
Expand All @@ -74,17 +78,20 @@ export function interpretTransferError(
: '';
uiErrorMessage = `Amount exceeds Circle limit${limitString}. Please reduce transfer amount.`;
internalErrorCode = ERR_AMOUNT_TOO_LARGE;
} else if (INSUFFICIENT_LAMPORTS_REGEX.test(e?.message)) {
const lamportMatches = e?.message.match(INSUFFICIENT_LAMPORTS_REGEX);
const currentLamports = lamportMatches?.[1];
const requiredLamports = lamportMatches?.[2];
uiErrorMessage = `Insufficient funds for gas.`;
if (currentLamports && requiredLamports) {
const currentAmount = sdkAmount.fromBaseUnits(currentLamports, 9);
const requiredAmount = sdkAmount.fromBaseUnits(requiredLamports, 9);
uiErrorMessage += ` Current balance is ${sdkAmount.display(
currentAmount,
)} SOL, but required ${sdkAmount.display(requiredAmount)} SOL`;
} else if (
SIMULATION_ACCOUNT_NOT_FOUND_REGEX.test(e?.message) ||
INSUFFICIENT_LAMPORTS_REGEX.test(e?.message)
) {
const gasChain = transferDetails.fromChain;
try {
const gasToken = getGasToken(gasChain);
const gasSymbol = getTokenSymbol(gasToken);
const chainName = chainDisplayName(gasChain);
const chainSuffix = chainName ? ` on ${chainName}` : '';
uiErrorMessage = `Insufficient ${gasSymbol} for fees${chainSuffix}, please add more ${gasSymbol} and try again`;
} catch {
uiErrorMessage =
'Insufficient funds for network fees, please add more funds and try again';
}
internalErrorCode = ERR_INSUFFICIENT_GAS;
}
Expand Down