@@ -15,12 +15,15 @@ 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' ,
@@ -50,7 +53,8 @@ export function interpretTransferError(
5053 uiErrorMessage = 'Transfer timed out, please try again' ;
5154 internalErrorCode = ERR_TIMEOUT ;
5255 } else if ( InsufficientFundsForGasError . MESSAGE_REGEX . test ( e ?. message ) ) {
53- uiErrorMessage = 'Insufficient funds' ;
56+ uiErrorMessage =
57+ 'Insufficient funds for network fees, please add more funds and try again' ;
5458 internalErrorCode = ERR_INSUFFICIENT_GAS ;
5559 } else if ( USER_REJECTED_REGEX . test ( e ?. message ) ) {
5660 uiErrorMessage = 'Transfer rejected in wallet, please try again' ;
@@ -74,17 +78,20 @@ export function interpretTransferError(
7478 : '' ;
7579 uiErrorMessage = `Amount exceeds Circle limit${ limitString } . Please reduce transfer amount.` ;
7680 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`;
81+ } else if (
82+ SIMULATION_ACCOUNT_NOT_FOUND_REGEX . test ( e ?. message ) ||
83+ INSUFFICIENT_LAMPORTS_REGEX . test ( e ?. message )
84+ ) {
85+ const gasChain = transferDetails . fromChain ;
86+ try {
87+ const gasToken = getGasToken ( gasChain ) ;
88+ const gasSymbol = getTokenSymbol ( gasToken ) ;
89+ const chainName = chainDisplayName ( gasChain ) ;
90+ const chainSuffix = chainName ? ` on ${ chainName } ` : '' ;
91+ uiErrorMessage = `Insufficient ${ gasSymbol } for fees${ chainSuffix } , please add more ${ gasSymbol } and try again` ;
92+ } catch {
93+ uiErrorMessage =
94+ 'Insufficient funds for network fees, please add more funds and try again' ;
8895 }
8996 internalErrorCode = ERR_INSUFFICIENT_GAS ;
9097 }
0 commit comments