@injectivelabs/exceptions 1.15.0 → 1.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/cjs/exceptions/base.d.ts +76 -0
  2. package/dist/cjs/exceptions/base.js +175 -0
  3. package/dist/cjs/exceptions/exceptions/BitGetException.d.ts +7 -0
  4. package/dist/cjs/exceptions/exceptions/BitGetException.js +23 -0
  5. package/dist/cjs/exceptions/exceptions/CosmosWalletException.d.ts +7 -0
  6. package/dist/cjs/exceptions/exceptions/CosmosWalletException.js +16 -0
  7. package/dist/cjs/exceptions/exceptions/GeneralException.d.ts +5 -0
  8. package/dist/cjs/exceptions/exceptions/GeneralException.js +11 -0
  9. package/dist/cjs/exceptions/exceptions/GrpcUnaryRequestException.d.ts +7 -0
  10. package/dist/cjs/exceptions/exceptions/GrpcUnaryRequestException.js +21 -0
  11. package/dist/cjs/exceptions/exceptions/HttpRequestException.d.ts +10 -0
  12. package/dist/cjs/exceptions/exceptions/HttpRequestException.js +21 -0
  13. package/dist/cjs/exceptions/exceptions/LedgerCosmosException.d.ts +7 -0
  14. package/dist/cjs/exceptions/exceptions/LedgerCosmosException.js +40 -0
  15. package/dist/cjs/exceptions/exceptions/LedgerException.d.ts +7 -0
  16. package/dist/cjs/exceptions/exceptions/LedgerException.js +40 -0
  17. package/dist/cjs/exceptions/exceptions/MetamaskException.d.ts +7 -0
  18. package/dist/cjs/exceptions/exceptions/MetamaskException.js +23 -0
  19. package/dist/cjs/exceptions/exceptions/OkxWalletException.d.ts +7 -0
  20. package/dist/cjs/exceptions/exceptions/OkxWalletException.js +23 -0
  21. package/dist/cjs/exceptions/exceptions/TransactionException.d.ts +7 -0
  22. package/dist/cjs/exceptions/exceptions/TransactionException.js +26 -0
  23. package/dist/cjs/exceptions/exceptions/TrezorException.d.ts +7 -0
  24. package/dist/cjs/exceptions/exceptions/TrezorException.js +16 -0
  25. package/dist/cjs/exceptions/exceptions/TrustWalletException.d.ts +7 -0
  26. package/dist/cjs/exceptions/exceptions/TrustWalletException.js +25 -0
  27. package/dist/cjs/exceptions/exceptions/WalletException.d.ts +5 -0
  28. package/dist/cjs/exceptions/exceptions/WalletException.js +11 -0
  29. package/dist/cjs/exceptions/exceptions/Web3Exception.d.ts +7 -0
  30. package/dist/cjs/exceptions/exceptions/Web3Exception.js +16 -0
  31. package/dist/cjs/exceptions/exceptions/index.d.ts +15 -0
  32. package/dist/cjs/exceptions/exceptions/index.js +31 -0
  33. package/dist/cjs/exceptions/index.d.ts +2 -0
  34. package/dist/cjs/exceptions/index.js +18 -0
  35. package/dist/cjs/exceptions/messages.d.ts +12 -0
  36. package/dist/cjs/exceptions/messages.js +1600 -0
  37. package/dist/cjs/exceptions/types/codes.d.ts +424 -0
  38. package/dist/cjs/exceptions/types/codes.js +791 -0
  39. package/dist/cjs/exceptions/types/context.d.ts +85 -0
  40. package/dist/cjs/exceptions/types/context.js +23 -0
  41. package/dist/cjs/exceptions/types/index.d.ts +3 -0
  42. package/dist/cjs/exceptions/types/index.js +19 -0
  43. package/dist/cjs/exceptions/types/modules.d.ts +59 -0
  44. package/dist/cjs/exceptions/types/modules.js +66 -0
  45. package/dist/cjs/exceptions/utils/grpc.d.ts +3 -0
  46. package/dist/cjs/exceptions/utils/grpc.js +40 -0
  47. package/dist/cjs/exceptions/utils/helpers.d.ts +1 -0
  48. package/dist/cjs/exceptions/utils/helpers.js +24 -0
  49. package/dist/cjs/exceptions/utils/maps.d.ts +13 -0
  50. package/dist/cjs/exceptions/utils/maps.js +132 -0
  51. package/dist/cjs/index.d.ts +3 -0
  52. package/dist/cjs/index.js +19 -0
  53. package/dist/cjs/package.json +3 -0
  54. package/dist/cjs/types.d.ts +2 -0
  55. package/dist/cjs/types.js +2 -0
  56. package/dist/cjs/utils.d.ts +8 -0
  57. package/dist/cjs/utils.js +47 -0
  58. package/dist/esm/exceptions/base.d.ts +76 -0
  59. package/dist/esm/exceptions/base.js +171 -0
  60. package/dist/esm/exceptions/exceptions/BitGetException.d.ts +7 -0
  61. package/dist/esm/exceptions/exceptions/BitGetException.js +19 -0
  62. package/dist/esm/exceptions/exceptions/CosmosWalletException.d.ts +7 -0
  63. package/dist/esm/exceptions/exceptions/CosmosWalletException.js +12 -0
  64. package/dist/esm/exceptions/exceptions/GeneralException.d.ts +5 -0
  65. package/dist/esm/exceptions/exceptions/GeneralException.js +7 -0
  66. package/dist/esm/exceptions/exceptions/GrpcUnaryRequestException.d.ts +7 -0
  67. package/dist/esm/exceptions/exceptions/GrpcUnaryRequestException.js +17 -0
  68. package/dist/esm/exceptions/exceptions/HttpRequestException.d.ts +10 -0
  69. package/dist/esm/exceptions/exceptions/HttpRequestException.js +17 -0
  70. package/dist/esm/exceptions/exceptions/LedgerCosmosException.d.ts +7 -0
  71. package/dist/esm/exceptions/exceptions/LedgerCosmosException.js +36 -0
  72. package/dist/esm/exceptions/exceptions/LedgerException.d.ts +7 -0
  73. package/dist/esm/exceptions/exceptions/LedgerException.js +36 -0
  74. package/dist/esm/exceptions/exceptions/MetamaskException.d.ts +7 -0
  75. package/dist/esm/exceptions/exceptions/MetamaskException.js +19 -0
  76. package/dist/esm/exceptions/exceptions/OkxWalletException.d.ts +7 -0
  77. package/dist/esm/exceptions/exceptions/OkxWalletException.js +19 -0
  78. package/dist/esm/exceptions/exceptions/TransactionException.d.ts +7 -0
  79. package/dist/esm/exceptions/exceptions/TransactionException.js +22 -0
  80. package/dist/esm/exceptions/exceptions/TrezorException.d.ts +7 -0
  81. package/dist/esm/exceptions/exceptions/TrezorException.js +12 -0
  82. package/dist/esm/exceptions/exceptions/TrustWalletException.d.ts +7 -0
  83. package/dist/esm/exceptions/exceptions/TrustWalletException.js +21 -0
  84. package/dist/esm/exceptions/exceptions/WalletException.d.ts +5 -0
  85. package/dist/esm/exceptions/exceptions/WalletException.js +7 -0
  86. package/dist/esm/exceptions/exceptions/Web3Exception.d.ts +7 -0
  87. package/dist/esm/exceptions/exceptions/Web3Exception.js +12 -0
  88. package/dist/esm/exceptions/exceptions/index.d.ts +15 -0
  89. package/dist/esm/exceptions/exceptions/index.js +15 -0
  90. package/dist/esm/exceptions/index.d.ts +2 -0
  91. package/dist/esm/exceptions/index.js +2 -0
  92. package/dist/esm/exceptions/messages.d.ts +12 -0
  93. package/dist/esm/exceptions/messages.js +1597 -0
  94. package/dist/esm/exceptions/types/codes.d.ts +424 -0
  95. package/dist/esm/exceptions/types/codes.js +787 -0
  96. package/dist/esm/exceptions/types/context.d.ts +85 -0
  97. package/dist/esm/exceptions/types/context.js +20 -0
  98. package/dist/esm/exceptions/types/index.d.ts +3 -0
  99. package/dist/esm/exceptions/types/index.js +3 -0
  100. package/dist/esm/exceptions/types/modules.d.ts +59 -0
  101. package/dist/esm/exceptions/types/modules.js +63 -0
  102. package/dist/esm/exceptions/utils/grpc.d.ts +3 -0
  103. package/dist/esm/exceptions/utils/grpc.js +3 -0
  104. package/dist/esm/exceptions/utils/helpers.d.ts +1 -0
  105. package/dist/esm/exceptions/utils/helpers.js +20 -0
  106. package/dist/esm/exceptions/utils/maps.d.ts +13 -0
  107. package/dist/esm/exceptions/utils/maps.js +125 -0
  108. package/dist/esm/index.d.ts +3 -0
  109. package/dist/esm/index.js +3 -0
  110. package/dist/esm/package.json +3 -0
  111. package/dist/esm/types.d.ts +2 -0
  112. package/dist/esm/types.js +1 -0
  113. package/dist/esm/utils.d.ts +8 -0
  114. package/dist/esm/utils.js +42 -0
  115. package/package.json +2 -2
@@ -0,0 +1,85 @@
1
+ import { ErrorCode, ErrorContextCode } from './codes.js';
2
+ export declare enum HttpRequestMethod {
3
+ Get = "GET",
4
+ Post = "POST",
5
+ Options = "OPTIONS"
6
+ }
7
+ export declare enum ErrorType {
8
+ Unspecified = "unspecified",
9
+ ChainError = "chain-error",
10
+ ExecutionError = "execution-error",
11
+ NotFoundError = "not-found-error",
12
+ ValidationError = "validation-error",
13
+ WalletError = "wallet-error",
14
+ WalletNotInstalledError = "wallet-not-installed-error",
15
+ GrpcUnaryRequest = "grpc-unary-request",
16
+ HttpRequest = "http-request",
17
+ Web3 = "web3",
18
+ Web3Gateway = "web3-gateway"
19
+ }
20
+ export interface ErrorContext {
21
+ code?: ErrorCode;
22
+ type?: ErrorType;
23
+ /**
24
+ * Additional context needed for the exception
25
+ */
26
+ context?: string;
27
+ /**
28
+ * Where is the exception thrown
29
+ */
30
+ contextModule?: string;
31
+ /**
32
+ * Needed when we get a code error from a Http/Grpc Request
33
+ * and we need to specify the error code for the particular message
34
+ * for example why the transaction has failed
35
+ * */
36
+ contextCode?: ErrorContextCode;
37
+ }
38
+ export interface Exception {
39
+ /**
40
+ * The type of the Error
41
+ */
42
+ type: ErrorType;
43
+ /**
44
+ * Error specific code (HttpStatus, GrpcStatus, etc)
45
+ */
46
+ code: ErrorCode;
47
+ /**
48
+ * The name of the error (the name of the instance of the Exception)
49
+ */
50
+ name: string;
51
+ /**
52
+ * Providing more context as to where the exception was thrown
53
+ * (ex: on-chain module, etc)
54
+ */
55
+ contextModule?: string;
56
+ /**
57
+ * Providing more context as to why the exception was thrown
58
+ * (ex: on-chain error code, etc)
59
+ */
60
+ contextCode?: ErrorContextCode;
61
+ /**
62
+ * Parsed message of the exception
63
+ */
64
+ message: string;
65
+ /**
66
+ * The original stack of the error
67
+ */
68
+ stack?: string;
69
+ /**
70
+ * The original message of the error
71
+ */
72
+ originalMessage: string;
73
+ parse?(): void;
74
+ parseError(error: Error): void;
75
+ parseContext(context?: ErrorContext): void;
76
+ setType(type: ErrorType): void;
77
+ setCode(code: ErrorCode): void;
78
+ setStack(stack: string): void;
79
+ setName(name: string): void;
80
+ setMessage(message: string): void;
81
+ setContextModule(contextModule: string): void;
82
+ toOriginalError(): Error;
83
+ toError(): Error;
84
+ toString(): string;
85
+ }
@@ -0,0 +1,20 @@
1
+ export var HttpRequestMethod;
2
+ (function (HttpRequestMethod) {
3
+ HttpRequestMethod["Get"] = "GET";
4
+ HttpRequestMethod["Post"] = "POST";
5
+ HttpRequestMethod["Options"] = "OPTIONS";
6
+ })(HttpRequestMethod || (HttpRequestMethod = {}));
7
+ export var ErrorType;
8
+ (function (ErrorType) {
9
+ ErrorType["Unspecified"] = "unspecified";
10
+ ErrorType["ChainError"] = "chain-error";
11
+ ErrorType["ExecutionError"] = "execution-error";
12
+ ErrorType["NotFoundError"] = "not-found-error";
13
+ ErrorType["ValidationError"] = "validation-error";
14
+ ErrorType["WalletError"] = "wallet-error";
15
+ ErrorType["WalletNotInstalledError"] = "wallet-not-installed-error";
16
+ ErrorType["GrpcUnaryRequest"] = "grpc-unary-request";
17
+ ErrorType["HttpRequest"] = "http-request";
18
+ ErrorType["Web3"] = "web3";
19
+ ErrorType["Web3Gateway"] = "web3-gateway";
20
+ })(ErrorType || (ErrorType = {}));
@@ -0,0 +1,3 @@
1
+ export * from './modules.js';
2
+ export * from './codes.js';
3
+ export * from './context.js';
@@ -0,0 +1,3 @@
1
+ export * from './modules.js';
2
+ export * from './codes.js';
3
+ export * from './context.js';
@@ -0,0 +1,59 @@
1
+ export declare enum ContractErrorModule {
2
+ Erc20Contract = "erc20-contract",
3
+ Peggy = "peggy-contract",
4
+ PeggyOld = "peggy-old-contract"
5
+ }
6
+ export declare enum ChainErrorModule {
7
+ Auction = "chain-auction",
8
+ Auth = "chain-auth",
9
+ Authz = "chain-authz",
10
+ Bank = "chain-bank",
11
+ Distribution = "chain-distribution",
12
+ Exchange = "chain-exchange",
13
+ Gov = "chain-gov",
14
+ Ibc = "chain-ibc",
15
+ InsuranceFund = "chain-insurance",
16
+ Mint = "chain-mint",
17
+ Oracle = "chain-oracle",
18
+ Peggy = "chain-peggy",
19
+ Staking = "chain-staking",
20
+ Wasm = "chain-wasm",
21
+ WasmX = "chain-wasmx",
22
+ Tendermint = "chain-tendermint",
23
+ Permissions = "chain-permissions"
24
+ }
25
+ export declare enum IndexerErrorModule {
26
+ Account = "indexer-account",
27
+ Auction = "indexer-auction",
28
+ Archiver = "indexer-archiver",
29
+ Derivatives = "indexer-derivatives",
30
+ Explorer = "indexer-explorer",
31
+ InsuranceFund = "indexer-insurance-fund",
32
+ Meta = "indexer-meta",
33
+ Mito = "indexer-mito",
34
+ Dmm = "dmm",
35
+ OLP = "olp",
36
+ Referral = "referral",
37
+ Oracle = "indexer-oracle",
38
+ Portfolio = "indexer-portfolio",
39
+ Spot = "indexer-spot",
40
+ Transaction = "indexer-transaction",
41
+ Trading = "indexer-trading",
42
+ ChronosDerivative = "indexer-chronos-derivative",
43
+ ChronosSpot = "indexer-chronos-spot",
44
+ ChronosMarkets = "indexer-chronos-markets",
45
+ Campaign = "indexer-campaign",
46
+ Web3Gw = "web3-gateway",
47
+ Abacus = "abacus"
48
+ }
49
+ export declare enum WalletErrorActionModule {
50
+ SignTransaction = "sign-transaction",
51
+ SignEthereumTransaction = "sign-ethereum-transaction",
52
+ SendTransaction = "send-transaction",
53
+ SendEthereumTransaction = "send-ethereum-transaction",
54
+ SignArbitrary = "sign-arbitrary",
55
+ GetAccounts = "get-accounts",
56
+ GetNetworkId = "get-network-id",
57
+ GetChainId = "get-chain-id",
58
+ GetEthereumTransactionReceipt = "get-ethereum-transaction-receipt"
59
+ }
@@ -0,0 +1,63 @@
1
+ export var ContractErrorModule;
2
+ (function (ContractErrorModule) {
3
+ ContractErrorModule["Erc20Contract"] = "erc20-contract";
4
+ ContractErrorModule["Peggy"] = "peggy-contract";
5
+ ContractErrorModule["PeggyOld"] = "peggy-old-contract";
6
+ })(ContractErrorModule || (ContractErrorModule = {}));
7
+ export var ChainErrorModule;
8
+ (function (ChainErrorModule) {
9
+ ChainErrorModule["Auction"] = "chain-auction";
10
+ ChainErrorModule["Auth"] = "chain-auth";
11
+ ChainErrorModule["Authz"] = "chain-authz";
12
+ ChainErrorModule["Bank"] = "chain-bank";
13
+ ChainErrorModule["Distribution"] = "chain-distribution";
14
+ ChainErrorModule["Exchange"] = "chain-exchange";
15
+ ChainErrorModule["Gov"] = "chain-gov";
16
+ ChainErrorModule["Ibc"] = "chain-ibc";
17
+ ChainErrorModule["InsuranceFund"] = "chain-insurance";
18
+ ChainErrorModule["Mint"] = "chain-mint";
19
+ ChainErrorModule["Oracle"] = "chain-oracle";
20
+ ChainErrorModule["Peggy"] = "chain-peggy";
21
+ ChainErrorModule["Staking"] = "chain-staking";
22
+ ChainErrorModule["Wasm"] = "chain-wasm";
23
+ ChainErrorModule["WasmX"] = "chain-wasmx";
24
+ ChainErrorModule["Tendermint"] = "chain-tendermint";
25
+ ChainErrorModule["Permissions"] = "chain-permissions";
26
+ })(ChainErrorModule || (ChainErrorModule = {}));
27
+ export var IndexerErrorModule;
28
+ (function (IndexerErrorModule) {
29
+ IndexerErrorModule["Account"] = "indexer-account";
30
+ IndexerErrorModule["Auction"] = "indexer-auction";
31
+ IndexerErrorModule["Archiver"] = "indexer-archiver";
32
+ IndexerErrorModule["Derivatives"] = "indexer-derivatives";
33
+ IndexerErrorModule["Explorer"] = "indexer-explorer";
34
+ IndexerErrorModule["InsuranceFund"] = "indexer-insurance-fund";
35
+ IndexerErrorModule["Meta"] = "indexer-meta";
36
+ IndexerErrorModule["Mito"] = "indexer-mito";
37
+ IndexerErrorModule["Dmm"] = "dmm";
38
+ IndexerErrorModule["OLP"] = "olp";
39
+ IndexerErrorModule["Referral"] = "referral";
40
+ IndexerErrorModule["Oracle"] = "indexer-oracle";
41
+ IndexerErrorModule["Portfolio"] = "indexer-portfolio";
42
+ IndexerErrorModule["Spot"] = "indexer-spot";
43
+ IndexerErrorModule["Transaction"] = "indexer-transaction";
44
+ IndexerErrorModule["Trading"] = "indexer-trading";
45
+ IndexerErrorModule["ChronosDerivative"] = "indexer-chronos-derivative";
46
+ IndexerErrorModule["ChronosSpot"] = "indexer-chronos-spot";
47
+ IndexerErrorModule["ChronosMarkets"] = "indexer-chronos-markets";
48
+ IndexerErrorModule["Campaign"] = "indexer-campaign";
49
+ IndexerErrorModule["Web3Gw"] = "web3-gateway";
50
+ IndexerErrorModule["Abacus"] = "abacus";
51
+ })(IndexerErrorModule || (IndexerErrorModule = {}));
52
+ export var WalletErrorActionModule;
53
+ (function (WalletErrorActionModule) {
54
+ WalletErrorActionModule["SignTransaction"] = "sign-transaction";
55
+ WalletErrorActionModule["SignEthereumTransaction"] = "sign-ethereum-transaction";
56
+ WalletErrorActionModule["SendTransaction"] = "send-transaction";
57
+ WalletErrorActionModule["SendEthereumTransaction"] = "send-ethereum-transaction";
58
+ WalletErrorActionModule["SignArbitrary"] = "sign-arbitrary";
59
+ WalletErrorActionModule["GetAccounts"] = "get-accounts";
60
+ WalletErrorActionModule["GetNetworkId"] = "get-network-id";
61
+ WalletErrorActionModule["GetChainId"] = "get-chain-id";
62
+ WalletErrorActionModule["GetEthereumTransactionReceipt"] = "get-ethereum-transaction-receipt";
63
+ })(WalletErrorActionModule || (WalletErrorActionModule = {}));
@@ -0,0 +1,3 @@
1
+ import * as grpcPkg from '@injectivelabs/grpc-web';
2
+ declare const grpc: typeof grpcPkg.grpc;
3
+ export { grpc, grpcPkg };
@@ -0,0 +1,3 @@
1
+ import * as grpcPkg from '@injectivelabs/grpc-web';
2
+ const grpc = grpcPkg.grpc ?? grpcPkg.default.grpc ?? grpcPkg;
3
+ export { grpc, grpcPkg };
@@ -0,0 +1 @@
1
+ export declare const isCommonLockedError: (error: string) => boolean;
@@ -0,0 +1,20 @@
1
+ export const isCommonLockedError = (error) => {
2
+ const commonMessages = [
3
+ 'Ledger device: Incorrect length',
4
+ 'Ledger device: INS_NOT_SUPPORTED',
5
+ 'Ledger device: CLA_NOT_SUPPORTED',
6
+ 'Unknown',
7
+ 'Ledger device',
8
+ 'CLA_NOT_SUPPORTED',
9
+ 'CLA',
10
+ 'Locked',
11
+ 'Failed to open the device',
12
+ 'Failed to open the device',
13
+ 'Ledger Device is busy',
14
+ 'Ledger device',
15
+ 'UNKNOWN_ERROR',
16
+ ];
17
+ return (commonMessages.some((m) => m.includes(error)) ||
18
+ commonMessages.some((m) => error.toLowerCase().includes(m)) ||
19
+ commonMessages.some((m) => m.toLowerCase().includes(error.toLowerCase())));
20
+ };
@@ -0,0 +1,13 @@
1
+ import { ErrorContext, ErrorContextCode, TransactionChainErrorModule } from '../types/index.js';
2
+ export declare const parseErrorMessage: (message: string) => string;
3
+ export declare const mapFailedTransactionMessageFromString: (message: string) => {
4
+ message: string;
5
+ code: ErrorContextCode;
6
+ module?: TransactionChainErrorModule;
7
+ };
8
+ export declare const mapFailedTransactionMessage: (message: string, context?: ErrorContext) => {
9
+ message: string;
10
+ code: ErrorContextCode;
11
+ contextModule?: string;
12
+ };
13
+ export declare const mapMetamaskMessage: (message: string) => string;
@@ -0,0 +1,125 @@
1
+ import { chainErrorMessagesMap, chainModuleCodeErrorMessagesMap, } from '../messages.js';
2
+ import { UnspecifiedErrorCode, } from '../types/index.js';
3
+ export const parseErrorMessage = (message) => {
4
+ const firstParse = message.split('message index: 0:');
5
+ if (firstParse.length === 1) {
6
+ const [firstParseString] = firstParse;
7
+ const secondParse = firstParseString.split(': invalid request');
8
+ const [secondParseString] = secondParse;
9
+ return secondParseString.trim().trimEnd();
10
+ }
11
+ const [, firstParseString] = firstParse;
12
+ const [actualMessage] = firstParseString.split(': invalid request');
13
+ return actualMessage.trim().trimEnd();
14
+ };
15
+ export const mapFailedTransactionMessageFromString = (message) => {
16
+ const parsedMessage = parseErrorMessage(message);
17
+ const messageInMapKey = Object.keys(chainErrorMessagesMap).find((key) => parsedMessage.toLowerCase().includes(key.toLowerCase()));
18
+ if (!messageInMapKey) {
19
+ return {
20
+ message: parsedMessage,
21
+ code: UnspecifiedErrorCode,
22
+ module: undefined,
23
+ };
24
+ }
25
+ return chainErrorMessagesMap[messageInMapKey];
26
+ };
27
+ export const mapFailedTransactionMessage = (message, context) => {
28
+ const getWasmErrorFromMessage = (message) => {
29
+ if (!message.includes('execute wasm contract failed')) {
30
+ return;
31
+ }
32
+ const ReasonPattern = /(.*?)execute wasm contract failed(.*?)/g;
33
+ const reason = ReasonPattern.exec(message);
34
+ if (!reason) {
35
+ return;
36
+ }
37
+ if (reason.length < 2) {
38
+ return;
39
+ }
40
+ return reason[1].replace('failed to execute message; message index: 0: ', '');
41
+ };
42
+ const getABCICode = (message) => {
43
+ const ABCICodePattern = /{key:"ABCICode"[ \t]+value:"(.*?)"}/g;
44
+ const ABCICode = ABCICodePattern.exec(message);
45
+ if (!ABCICode || ABCICode.length < 2) {
46
+ return;
47
+ }
48
+ return Number(ABCICode[1]);
49
+ };
50
+ const getContextModule = (message) => {
51
+ const codespacePattern = /{key:"Codespace"[ \t]+value:"(.*?)"}/g;
52
+ const codespace = codespacePattern.exec(message);
53
+ if (!codespace || codespace.length < 2) {
54
+ return;
55
+ }
56
+ return codespace[1];
57
+ };
58
+ const getReason = (message) => {
59
+ const ReasonPattern = /\[reason:"(.*?)"/g;
60
+ const codespace = ReasonPattern.exec(message);
61
+ if (!codespace || codespace.length < 2) {
62
+ if (message.includes('execute wasm contract failed')) {
63
+ return getWasmErrorFromMessage(message);
64
+ }
65
+ return;
66
+ }
67
+ const reason = codespace[1];
68
+ if (reason === 'execute wasm contract failed') {
69
+ const SubReasonPattern = /(.*?)Generic error:(.*?): execute wasm/g;
70
+ const subReason = SubReasonPattern.exec(message);
71
+ if (!subReason) {
72
+ return reason;
73
+ }
74
+ return subReason[2] || reason;
75
+ }
76
+ return reason;
77
+ };
78
+ const ABCICode = context && context.code ? context.code : getABCICode(message);
79
+ const contextModule = context?.contextModule || getContextModule(message);
80
+ const reason = getReason(message);
81
+ if (!ABCICode || !contextModule) {
82
+ const failedTxMap = mapFailedTransactionMessageFromString(message);
83
+ return {
84
+ ...failedTxMap,
85
+ contextModule: failedTxMap.module || contextModule,
86
+ message: reason || failedTxMap.message,
87
+ };
88
+ }
89
+ const codespaceErrorMessages = chainModuleCodeErrorMessagesMap[contextModule];
90
+ if (!codespaceErrorMessages) {
91
+ return {
92
+ message: reason || message,
93
+ code: ABCICode,
94
+ contextModule,
95
+ };
96
+ }
97
+ return {
98
+ message: codespaceErrorMessages[ABCICode] || reason || message,
99
+ code: ABCICode,
100
+ contextModule,
101
+ };
102
+ };
103
+ export const mapMetamaskMessage = (message) => {
104
+ const parsedMessage = message.trim().toLowerCase();
105
+ if (parsedMessage.includes('User denied message signature'.toLowerCase())) {
106
+ return 'The request has been rejected';
107
+ }
108
+ if (parsedMessage.toLowerCase().includes('user denied'.toLowerCase())) {
109
+ return 'The request has been rejected';
110
+ }
111
+ if (parsedMessage.toLowerCase().includes('provided chain'.toLowerCase())) {
112
+ return 'Your Metamask selected network is incorrect';
113
+ }
114
+ if (parsedMessage
115
+ .toLowerCase()
116
+ .includes('missing or invalid parameters'.toLowerCase())) {
117
+ return 'Please make sure you are using Metamask';
118
+ }
119
+ if (parsedMessage
120
+ .toLowerCase()
121
+ .includes('Keyring Controller signTypedMessage'.toLowerCase())) {
122
+ return 'Please ensure your Ledger is connected, unlocked and your Ethereum app is open.';
123
+ }
124
+ return message.replaceAll('Keyring Controller signTypedMessage:', '');
125
+ };
@@ -0,0 +1,3 @@
1
+ export * from './exceptions/index.js';
2
+ export * from './utils.js';
3
+ export * from './types.js';
@@ -0,0 +1,3 @@
1
+ export * from './exceptions/index.js';
2
+ export * from './utils.js';
3
+ export * from './types.js';
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,2 @@
1
+ import { Web3Exception, WalletException, TrezorException, BitGetException, LedgerException, GeneralException, MetamaskException, OkxWalletException, HttpRequestException, LedgerCosmosException, TrustWalletException, CosmosWalletException, TransactionException, GrpcUnaryRequestException } from './exceptions/exceptions/index.js';
2
+ export type ThrownException = GrpcUnaryRequestException | HttpRequestException | Web3Exception | GeneralException | LedgerException | MetamaskException | TrustWalletException | OkxWalletException | TrezorException | CosmosWalletException | TransactionException | WalletException | LedgerCosmosException | BitGetException;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { Exception } from './exceptions/types/index.js';
2
+ import { ThrownException } from './types.js';
3
+ export declare const THROWN_EXCEPTIONS: string[];
4
+ export declare const isThrownException: (exception: Error | Exception | ThrownException) => boolean;
5
+ export declare const formatNotificationDescription: (description: string) => {
6
+ description: string;
7
+ tooltip: string;
8
+ };
@@ -0,0 +1,42 @@
1
+ export const THROWN_EXCEPTIONS = [
2
+ 'GrpcUnaryRequestException',
3
+ 'HttpRequestException',
4
+ 'Web3Exception',
5
+ 'GeneralException',
6
+ 'LedgerException',
7
+ 'LedgerCosmosException',
8
+ 'MetamaskException',
9
+ 'TrezorException',
10
+ 'CosmosWalletException',
11
+ 'TransactionException',
12
+ 'WalletException',
13
+ 'TrustWalletException',
14
+ 'OkxWalletException',
15
+ 'BitGetException',
16
+ ];
17
+ export const isThrownException = (exception) => {
18
+ if (THROWN_EXCEPTIONS.includes(exception.constructor.name)) {
19
+ return true;
20
+ }
21
+ if (THROWN_EXCEPTIONS.includes(exception.name)) {
22
+ return true;
23
+ }
24
+ if ('errorClass' in exception &&
25
+ THROWN_EXCEPTIONS.includes(exception.errorClass)) {
26
+ return true;
27
+ }
28
+ return false;
29
+ };
30
+ export const formatNotificationDescription = (description) => {
31
+ const DESCRIPTION_CHARACTER_LIMIT = 50;
32
+ if (description.length <= DESCRIPTION_CHARACTER_LIMIT) {
33
+ return {
34
+ description,
35
+ tooltip: '',
36
+ };
37
+ }
38
+ return {
39
+ description: description.slice(0, DESCRIPTION_CHARACTER_LIMIT) + ' ...',
40
+ tooltip: description,
41
+ };
42
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@injectivelabs/exceptions",
3
3
  "description": "List of exceptions that can be reused throughout Injective's projects.",
4
- "version": "1.15.0",
4
+ "version": "1.15.2",
5
5
  "sideEffects": false,
6
6
  "license": "Apache-2.0",
7
7
  "type": "module",
@@ -61,5 +61,5 @@
61
61
  "devDependencies": {
62
62
  "shx": "^0.3.4"
63
63
  },
64
- "gitHead": "acae5b41a4c8a0ac4f137cce434b9db81800a1c5"
64
+ "gitHead": "adf15fdda3172783b16fddba631c8054160fe772"
65
65
  }