@@ -6,14 +6,32 @@ import { capitalizeFirstLetter } from 'utils/string'
6
6
const matchPatterns = ( patterns : string [ ] , error : string ) =>
7
7
patterns . some ( pattern => error . toLowerCase ( ) . includes ( pattern . toLowerCase ( ) ) )
8
8
9
+ export const knownPatterns = {
10
+ insufficient_erc20_balance : 'Insufficient ERC20 balance to pay gas fee' ,
11
+ router_expired : 'An error occurred. Refresh the page and try again.' ,
12
+ already_pending : 'Pending request(s), please approve it in your wallet.' ,
13
+ mintotalamountout : 'An error occurred. Try refreshing the price rate or increase max slippage.' ,
14
+ from_address_mismatch : 'The requested account and/or method has not been authorized by the user.' ,
15
+ insufficient_funds : 'Your current balance falls short of covering the required gas fee.' ,
16
+ swap_failed :
17
+ 'An error occurred. Refresh the page and try again. If the issue still persists, it might be an issue with your RPC node settings in Metamask.' ,
18
+ underlying_network_changed : 'Your chain is mismatched, please make sure your wallet is switch to the expected chain.' ,
19
+ user_rejected : 'User rejected the transaction.' ,
20
+ insufficient : 'An error occurred. Please try increasing max slippage.' ,
21
+ permit : 'An error occurred. Invalid Permit Signature.' ,
22
+ burn_amount_exceeds_balance :
23
+ 'Insufficient fee rewards amount, try to remove your liquidity without claiming fees for now and you can try to claim it later.' ,
24
+ object_object : 'Something went wrong. Please try again.' ,
25
+ }
26
+
9
27
function parseKnownPattern ( text : string ) : string | undefined {
10
28
const error = text ?. toLowerCase ?.( ) || ''
11
29
12
- if ( matchPatterns ( [ 'insufficient erc20 balance' ] , error ) ) return t `Insufficient ERC20 balance to pay gas fee`
30
+ if ( matchPatterns ( [ 'insufficient erc20 balance' ] , error ) ) return knownPatterns . insufficient_erc20_balance
13
31
14
- if ( ! error || error . includes ( 'router: expired' ) ) return t `An error occurred. Refresh the page and try again.`
32
+ if ( ! error || error . includes ( 'router: expired' ) ) return knownPatterns . router_expired
15
33
16
- if ( matchPatterns ( [ 'already pending' ] , error ) ) return t `Pending request(s), please approve it in your wallet.`
34
+ if ( matchPatterns ( [ 'already pending' ] , error ) ) return knownPatterns . already_pending
17
35
18
36
if (
19
37
matchPatterns (
@@ -28,41 +46,38 @@ function parseKnownPattern(text: string): string | undefined {
28
46
error ,
29
47
)
30
48
)
31
- return t `An error occurred. Try refreshing the price rate or increase max slippage.`
49
+ return knownPatterns . mintotalamountout
32
50
33
51
if (
34
52
matchPatterns (
35
53
[ 'The requested account and/or method has not been authorized by the user' , 'From address mismatch' ] ,
36
54
error ,
37
55
)
38
56
)
39
- return t `The requested account and/or method has not been authorized by the user.`
57
+ return knownPatterns . from_address_mismatch
40
58
41
59
if (
42
60
matchPatterns (
43
61
[ 'insufficient funds for intrinsic transaction cost' , 'OutOfFund' , 'insufficient balance for transfer' ] ,
44
62
error ,
45
63
)
46
64
)
47
- return t `Your current balance falls short of covering the required gas fee.`
65
+ return knownPatterns . insufficient_funds
48
66
49
- if ( matchPatterns ( [ 'header not found' , 'swap failed' ] , error ) )
50
- return t `An error occurred. Refresh the page and try again. If the issue still persists, it might be an issue with your RPC node settings in Metamask.`
67
+ if ( matchPatterns ( [ 'header not found' , 'swap failed' ] , error ) ) return knownPatterns . swap_failed
51
68
52
- if ( matchPatterns ( [ 'underlying network changed' ] , error ) )
53
- return t `Your chain is mismatched, please make sure your wallet is switch to the expected chain.`
69
+ if ( matchPatterns ( [ 'underlying network changed' ] , error ) ) return knownPatterns . underlying_network_changed
54
70
55
- if ( didUserReject ( error ) ) return t `User rejected the transaction.`
71
+ if ( didUserReject ( error ) ) return knownPatterns . user_rejected
56
72
57
73
// classic/elastic remove liquidity error
58
- if ( matchPatterns ( [ 'insufficient' ] , error ) ) return t `An error occurred. Please try increasing max slippage.`
74
+ if ( matchPatterns ( [ 'insufficient' ] , error ) ) return knownPatterns . insufficient
59
75
60
- if ( matchPatterns ( [ 'permit' ] , error ) ) return t `An error occurred. Invalid Permit Signature.`
76
+ if ( matchPatterns ( [ 'permit' ] , error ) ) return knownPatterns . permit
61
77
62
- if ( matchPatterns ( [ 'burn amount exceeds balance' ] , error ) )
63
- return t `Insufficient fee rewards amount, try to remove your liquidity without claiming fees for now and you can try to claim it later.`
78
+ if ( matchPatterns ( [ 'burn amount exceeds balance' ] , error ) ) return knownPatterns . burn_amount_exceeds_balance
64
79
65
- if ( error === '[object Object]' ) return t `Something went wrong. Please try again.`
80
+ if ( error === '[object Object]' ) return knownPatterns . object_object
66
81
67
82
return undefined
68
83
}
0 commit comments