@@ -15,17 +15,22 @@ import {
1515} from 'telemetry/types' ;
1616import { InsufficientFundsForGasError } from 'sdklegacy' ;
1717import { routes , amount as sdkAmount } from '@wormhole-foundation/sdk' ;
18+ import { chainDisplayName , getGasToken , getTokenSymbol } from 'utils' ;
1819
1920// TODO SDKV2
2021// attempt to capture errors using regex
2122export const INSUFFICIENT_ALLOWANCE_REGEX = / i n s u f f i c i e n t t o k e n a l l o w a n c e / im;
2223export const INSUFFICIENT_LAMPORTS_REGEX =
2324 / i n s u f f i c i e n t l a m p o r t s .* ?( \d + ) .* ?( \d + ) / im;
25+ export const SIMULATION_ACCOUNT_NOT_FOUND_REGEX =
26+ / s i m u l a t i o n f a i l e d : .* a c c o u n t n o t f o u n d / i;
2427export const USER_REJECTED_REGEX = new RegExp (
2528 'user rejected|rejected the request|rejected from user|user cancel|aborted by user|plugin closed|denied request signature' ,
2629 'mi' ,
2730) ;
2831export const AMOUNT_IN_TOO_SMALL = new RegExp ( 'AmountInTooSmall' , 'm' ) ;
32+ const INSUFFICIENT_FUNDS_FOR_GAS_ERROR =
33+ 'Insufficient funds for network fees. Please add more funds and try again' ;
2934
3035export function interpretTransferError (
3136 e : any ,
@@ -50,7 +55,7 @@ export function interpretTransferError(
5055 uiErrorMessage = 'Transfer timed out, please try again' ;
5156 internalErrorCode = ERR_TIMEOUT ;
5257 } else if ( InsufficientFundsForGasError . MESSAGE_REGEX . test ( e ?. message ) ) {
53- uiErrorMessage = 'Insufficient funds' ;
58+ uiErrorMessage = INSUFFICIENT_FUNDS_FOR_GAS_ERROR ;
5459 internalErrorCode = ERR_INSUFFICIENT_GAS ;
5560 } else if ( USER_REJECTED_REGEX . test ( e ?. message ) ) {
5661 uiErrorMessage = 'Transfer rejected in wallet, please try again' ;
@@ -74,17 +79,19 @@ export function interpretTransferError(
7479 : '' ;
7580 uiErrorMessage = `Amount exceeds Circle limit${ limitString } . Please reduce transfer amount.` ;
7681 internalErrorCode = ERR_AMOUNT_TOO_LARGE ;
77- } else if ( INSUFFICIENT_LAMPORTS_REGEX . test ( e ?. message ) ) {
78- const lamportMatches = e ?. message . match ( INSUFFICIENT_LAMPORTS_REGEX ) ;
79- const currentLamports = lamportMatches ?. [ 1 ] ;
80- const requiredLamports = lamportMatches ?. [ 2 ] ;
81- uiErrorMessage = `Insufficient funds for gas.` ;
82- if ( currentLamports && requiredLamports ) {
83- const currentAmount = sdkAmount . fromBaseUnits ( currentLamports , 9 ) ;
84- const requiredAmount = sdkAmount . fromBaseUnits ( requiredLamports , 9 ) ;
85- uiErrorMessage += ` Current balance is ${ sdkAmount . display (
86- currentAmount ,
87- ) } SOL, but required ${ sdkAmount . display ( requiredAmount ) } SOL`;
82+ } else if (
83+ SIMULATION_ACCOUNT_NOT_FOUND_REGEX . test ( e ?. message ) ||
84+ INSUFFICIENT_LAMPORTS_REGEX . test ( e ?. message )
85+ ) {
86+ const gasChain = transferDetails . fromChain ;
87+ try {
88+ const gasToken = getGasToken ( gasChain ) ;
89+ const gasSymbol = getTokenSymbol ( gasToken ) ;
90+ const chainName = chainDisplayName ( gasChain ) ;
91+ const chainSuffix = chainName ? ` on ${ chainName } ` : '' ;
92+ uiErrorMessage = `Insufficient ${ gasSymbol } for fees${ chainSuffix } . Please add more ${ gasSymbol } and try again` ;
93+ } catch {
94+ uiErrorMessage = INSUFFICIENT_FUNDS_FOR_GAS_ERROR ;
8895 }
8996 internalErrorCode = ERR_INSUFFICIENT_GAS ;
9097 }
0 commit comments