@metamask/transaction-controller 8.0.1 → 9.0.0

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.
@@ -1,4 +1,4 @@
1
- import { NetworkType } from '@metamask/controller-utils';
1
+ import type { Hex } from '@metamask/utils';
2
2
  export interface EtherscanTransactionMetaBase {
3
3
  blockNumber: string;
4
4
  blockHash: string;
@@ -29,38 +29,37 @@ export interface EtherscanTokenTransactionMeta extends EtherscanTransactionMetaB
29
29
  tokenSymbol: string;
30
30
  }
31
31
  export interface EtherscanTransactionResponse<T extends EtherscanTransactionMetaBase> {
32
- status: '0' | '1';
33
32
  result: T[];
34
33
  }
35
34
  export interface EtherscanTransactionRequest {
36
35
  address: string;
37
- networkType: NetworkType;
38
- limit: number;
39
- fromBlock?: string;
40
36
  apiKey?: string;
37
+ chainId: Hex;
38
+ fromBlock?: number;
39
+ limit?: number;
41
40
  }
42
41
  /**
43
42
  * Retrieves transaction data from Etherscan.
44
43
  *
45
44
  * @param request - Configuration required to fetch transactions.
46
45
  * @param request.address - Address to retrieve transactions for.
47
- * @param request.networkType - Current network type used to determine the Etherscan subdomain.
48
- * @param request.limit - Maximum number of transactions to retrieve.
49
46
  * @param request.apiKey - Etherscan API key.
47
+ * @param request.chainId - Current chain ID used to determine subdomain and domain.
50
48
  * @param request.fromBlock - Block number to start fetching transactions from.
49
+ * @param request.limit - Number of transactions to retrieve.
51
50
  * @returns An Etherscan response object containing the request status and an array of token transaction data.
52
51
  */
53
- export declare function fetchEtherscanTransactions({ address, networkType, limit, apiKey, fromBlock, }: EtherscanTransactionRequest): Promise<EtherscanTransactionResponse<EtherscanTransactionMeta>>;
52
+ export declare function fetchEtherscanTransactions({ address, apiKey, chainId, fromBlock, limit, }: EtherscanTransactionRequest): Promise<EtherscanTransactionResponse<EtherscanTransactionMeta>>;
54
53
  /**
55
54
  * Retrieves token transaction data from Etherscan.
56
55
  *
57
56
  * @param request - Configuration required to fetch token transactions.
58
57
  * @param request.address - Address to retrieve token transactions for.
59
- * @param request.networkType - Current network type used to determine the Etherscan subdomain.
60
- * @param request.limit - Maximum number of token transactions to retrieve.
61
58
  * @param request.apiKey - Etherscan API key.
59
+ * @param request.chainId - Current chain ID used to determine subdomain and domain.
62
60
  * @param request.fromBlock - Block number to start fetching token transactions from.
61
+ * @param request.limit - Number of token transactions to retrieve.
63
62
  * @returns An Etherscan response object containing the request status and an array of token transaction data.
64
63
  */
65
- export declare function fetchEtherscanTokenTransactions({ address, networkType, limit, apiKey, fromBlock, }: EtherscanTransactionRequest): Promise<EtherscanTransactionResponse<EtherscanTokenTransactionMeta>>;
64
+ export declare function fetchEtherscanTokenTransactions({ address, apiKey, chainId, fromBlock, limit, }: EtherscanTransactionRequest): Promise<EtherscanTransactionResponse<EtherscanTokenTransactionMeta>>;
66
65
  //# sourceMappingURL=etherscan.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"etherscan.d.ts","sourceRoot":"","sources":["../src/etherscan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,MAAM,4BAA4B,CAAC;AAEtE,MAAM,WAAW,4BAA4B;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,wBAAyB,SAAQ,4BAA4B;IAC5E,YAAY,EAAE,M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OAAO,EACP,MAAM,EACN,OAAO,EACP,SAAS,EACT,KAAK,GACN,EAAE,2BAA2B,GAAG,OAAO,CACtC,4BAA4B,CAAC,6BAA6B,CAAC,CAC5D,CAQA"}
package/dist/etherscan.js CHANGED
@@ -11,25 +11,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.fetchEtherscanTokenTransactions = exports.fetchEtherscanTransactions = void 0;
13
13
  const controller_utils_1 = require("@metamask/controller-utils");
14
+ const constants_1 = require("./constants");
14
15
  /**
15
16
  * Retrieves transaction data from Etherscan.
16
17
  *
17
18
  * @param request - Configuration required to fetch transactions.
18
19
  * @param request.address - Address to retrieve transactions for.
19
- * @param request.networkType - Current network type used to determine the Etherscan subdomain.
20
- * @param request.limit - Maximum number of transactions to retrieve.
21
20
  * @param request.apiKey - Etherscan API key.
21
+ * @param request.chainId - Current chain ID used to determine subdomain and domain.
22
22
  * @param request.fromBlock - Block number to start fetching transactions from.
23
+ * @param request.limit - Number of transactions to retrieve.
23
24
  * @returns An Etherscan response object containing the request status and an array of token transaction data.
24
25
  */
25
- function fetchEtherscanTransactions({ address, networkType, limit, apiKey, fromBlock, }) {
26
+ function fetchEtherscanTransactions({ address, apiKey, chainId, fromBlock, limit, }) {
26
27
  return __awaiter(this, void 0, void 0, function* () {
27
28
  return yield fetchTransactions('txlist', {
28
29
  address,
29
- networkType,
30
- limit,
31
- fromBlock,
32
30
  apiKey,
31
+ chainId,
32
+ fromBlock,
33
+ limit,
33
34
  });
34
35
  });
35
36
  }
@@ -39,20 +40,20 @@ exports.fetchEtherscanTransactions = fetchEtherscanTransactions;
39
40
  *
40
41
  * @param request - Configuration required to fetch token transactions.
41
42
  * @param request.address - Address to retrieve token transactions for.
42
- * @param request.networkType - Current network type used to determine the Etherscan subdomain.
43
- * @param request.limit - Maximum number of token transactions to retrieve.
44
43
  * @param request.apiKey - Etherscan API key.
44
+ * @param request.chainId - Current chain ID used to determine subdomain and domain.
45
45
  * @param request.fromBlock - Block number to start fetching token transactions from.
46
+ * @param request.limit - Number of token transactions to retrieve.
46
47
  * @returns An Etherscan response object containing the request status and an array of token transaction data.
47
48
  */
48
- function fetchEtherscanTokenTransactions({ address, networkType, limit, apiKey, fromBlock, }) {
49
+ function fetchEtherscanTokenTransactions({ address, apiKey, chainId, fromBlock, limit, }) {
49
50
  return __awaiter(this, void 0, void 0, function* () {
50
51
  return yield fetchTransactions('tokentx', {
51
52
  address,
52
- networkType,
53
- limit,
54
- fromBlock,
55
53
  apiKey,
54
+ chainId,
55
+ fromBlock,
56
+ limit,
56
57
  });
57
58
  });
58
59
  }
@@ -63,44 +64,45 @@ exports.fetchEtherscanTokenTransactions = fetchEtherscanTokenTransactions;
63
64
  * @param action - The Etherscan endpoint to use.
64
65
  * @param options - Options bag.
65
66
  * @param options.address - Address to retrieve transactions for.
66
- * @param options.networkType - Current network type used to determine the Etherscan subdomain.
67
- * @param options.limit - Maximum number of transactions to retrieve.
68
67
  * @param options.apiKey - Etherscan API key.
68
+ * @param options.chainId - Current chain ID used to determine subdomain and domain.
69
69
  * @param options.fromBlock - Block number to start fetching transactions from.
70
+ * @param options.limit - Number of transactions to retrieve.
70
71
  * @returns An object containing the request status and an array of transaction data.
71
72
  */
72
- function fetchTransactions(action, { address, networkType, limit, apiKey, fromBlock, }) {
73
+ function fetchTransactions(action, { address, apiKey, chainId, fromBlock, limit, }) {
73
74
  return __awaiter(this, void 0, void 0, function* () {
74
75
  const urlParams = {
75
76
  module: 'account',
76
77
  address,
77
- startBlock: fromBlock,
78
+ startBlock: fromBlock === null || fromBlock === void 0 ? void 0 : fromBlock.toString(),
78
79
  apikey: apiKey,
79
- offset: limit.toString(),
80
+ offset: limit === null || limit === void 0 ? void 0 : limit.toString(),
80
81
  order: 'desc',
81
82
  };
82
- const etherscanTxUrl = getEtherscanApiUrl(networkType, Object.assign(Object.assign({}, urlParams), { action }));
83
+ const etherscanTxUrl = getEtherscanApiUrl(chainId, Object.assign(Object.assign({}, urlParams), { action }));
83
84
  const response = (yield (0, controller_utils_1.handleFetch)(etherscanTxUrl));
84
- if (response.status === '0' || response.result.length <= 0) {
85
- return { status: response.status, result: [] };
85
+ if (response.status === '0' && response.message === 'NOTOK') {
86
+ throw new Error(`Etherscan request failed - ${response.result}`);
86
87
  }
87
- return response;
88
+ return { result: response.result };
88
89
  });
89
90
  }
90
91
  /**
91
92
  * Return a URL that can be used to fetch data from Etherscan.
92
93
  *
93
- * @param networkType - Network type of desired network.
94
+ * @param chainId - Current chain ID used to determine subdomain and domain.
94
95
  * @param urlParams - The parameters used to construct the URL.
95
96
  * @returns URL to access Etherscan data.
96
97
  */
97
- function getEtherscanApiUrl(networkType, urlParams) {
98
- let etherscanSubdomain = 'api';
99
- if (networkType !== controller_utils_1.NetworkType.mainnet) {
100
- etherscanSubdomain = `api-${networkType}`;
98
+ function getEtherscanApiUrl(chainId, urlParams) {
99
+ const networkInfo = constants_1.ETHERSCAN_SUPPORTED_NETWORKS[chainId];
100
+ if (!networkInfo) {
101
+ throw new Error(`Etherscan does not support chain with ID: ${chainId}`);
101
102
  }
102
- const apiUrl = `https://${etherscanSubdomain}.etherscan.io`;
103
+ const apiUrl = `https://${networkInfo.subdomain}.${networkInfo.domain}`;
103
104
  let url = `${apiUrl}/api?`;
105
+ // eslint-disable-next-line guard-for-in
104
106
  for (const paramKey in urlParams) {
105
107
  const value = urlParams[paramKey];
106
108
  if (!value) {
@@ -1 +1 @@
1
- {"version":3,"file":"etherscan.js","sourceRoot":"","sources":["../src/etherscan.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAsE;AAkDtE;;;;;;;;;;GAUG;AACH,SAAsB,0BAA0B,CAAC,EAC/C,OAAO,EACP,WAAW,EACX,KAAK,EACL,MAAM,EACN,SAAS,GACmB;;QAG5B,OAAO,MAAM,iBAAiB,CAAC,QAAQ,EAAE;YACvC,OAAO;YACP,WAAW;YACX,KAAK;YACL,SAAS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MAAM,MAAM,GAAG,WAAW,kBAAkB,eAAe,CAAC;IAC5D,IAAI,GAAG,GAAG,GAAG,MAAM,OAAO,CAAC;IAE3B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;QAChC,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK,EAAE;YACV,SAAS;SACV;QAED,GAAG,IAAI,GAAG,QAAQ,IAAI,KAAK,GAAG,CAAC;KAChC;IAED,GAAG,IAAI,mBAAmB,CAAC;IAE3B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { NetworkType, handleFetch } from '@metamask/controller-utils';\n\nexport interface EtherscanTransactionMetaBase {\n blockNumber: string;\n blockHash: string;\n confirmations: string;\n contractAddress: string;\n cumulativeGasUsed: string;\n from: string;\n gas: string;\n gasPrice: string;\n gasUsed: string;\n hash: string;\n nonce: string;\n timeStamp: string;\n to: string;\n transactionIndex: string;\n value: string;\n}\n\nexport interface EtherscanTransactionMeta extends EtherscanTransactionMetaBase {\n functionName: string;\n input: string;\n isError: string;\n methodId: string;\n txreceipt_status: string;\n}\n\nexport interface EtherscanTokenTransactionMeta\n extends EtherscanTransactionMetaBase {\n tokenDecimal: string;\n tokenName: string;\n tokenSymbol: string;\n}\n\nexport interface EtherscanTransactionResponse<\n T extends EtherscanTransactionMetaBase,\n> {\n status: '0' | '1';\n result: T[];\n}\n\nexport interface EtherscanTransactionRequest {\n address: string;\n networkType: NetworkType;\n limit: number;\n fromBlock?: string;\n apiKey?: string;\n}\n\n/**\n * Retrieves transaction data from Etherscan.\n *\n * @param request - Configuration required to fetch transactions.\n * @param request.address - Address to retrieve transactions for.\n * @param request.networkType - Current network type used to determine the Etherscan subdomain.\n * @param request.limit - Maximum number of transactions to retrieve.\n * @param request.apiKey - Etherscan API key.\n * @param request.fromBlock - Block number to start fetching transactions from.\n * @returns An Etherscan response object containing the request status and an array of token transaction data.\n */\nexport async function fetchEtherscanTransactions({\n address,\n networkType,\n limit,\n apiKey,\n fromBlock,\n}: EtherscanTransactionRequest): Promise<\n EtherscanTransactionResponse<EtherscanTransactionMeta>\n> {\n return await fetchTransactions('txlist', {\n address,\n networkType,\n limit,\n fromBlock,\n apiKey,\n });\n}\n\n/**\n * Retrieves token transaction data from Etherscan.\n *\n * @param request - Configuration required to fetch token transactions.\n * @param request.address - Address to retrieve token transactions for.\n * @param request.networkType - Current network type used to determine the Etherscan subdomain.\n * @param request.limit - Maximum number of token transactions to retrieve.\n * @param request.apiKey - Etherscan API key.\n * @param request.fromBlock - Block number to start fetching token transactions from.\n * @returns An Etherscan response object containing the request status and an array of token transaction data.\n */\nexport async function fetchEtherscanTokenTransactions({\n address,\n networkType,\n limit,\n apiKey,\n fromBlock,\n}: EtherscanTransactionRequest): Promise<\n EtherscanTransactionResponse<EtherscanTokenTransactionMeta>\n> {\n return await fetchTransactions('tokentx', {\n address,\n networkType,\n limit,\n fromBlock,\n apiKey,\n });\n}\n\n/**\n * Retrieves transaction data from Etherscan from a specific endpoint.\n *\n * @param action - The Etherscan endpoint to use.\n * @param options - Options bag.\n * @param options.address - Address to retrieve transactions for.\n * @param options.networkType - Current network type used to determine the Etherscan subdomain.\n * @param options.limit - Maximum number of transactions to retrieve.\n * @param options.apiKey - Etherscan API key.\n * @param options.fromBlock - Block number to start fetching transactions from.\n * @returns An object containing the request status and an array of transaction data.\n */\nasync function fetchTransactions<T extends EtherscanTransactionMetaBase>(\n action: string,\n {\n address,\n networkType,\n limit,\n apiKey,\n fromBlock,\n }: {\n address: string;\n networkType: NetworkType;\n limit: number;\n fromBlock?: string;\n apiKey?: string;\n },\n): Promise<EtherscanTransactionResponse<T>> {\n const urlParams = {\n module: 'account',\n address,\n startBlock: fromBlock,\n apikey: apiKey,\n offset: limit.toString(),\n order: 'desc',\n };\n\n const etherscanTxUrl = getEtherscanApiUrl(networkType, {\n ...urlParams,\n action,\n });\n\n const response = (await handleFetch(\n etherscanTxUrl,\n )) as EtherscanTransactionResponse<T>;\n\n if (response.status === '0' || response.result.length <= 0) {\n return { status: response.status, result: [] };\n }\n\n return response;\n}\n\n/**\n * Return a URL that can be used to fetch data from Etherscan.\n *\n * @param networkType - Network type of desired network.\n * @param urlParams - The parameters used to construct the URL.\n * @returns URL to access Etherscan data.\n */\nfunction getEtherscanApiUrl(\n networkType: string,\n urlParams: Record<string, string | undefined>,\n): string {\n let etherscanSubdomain = 'api';\n\n if (networkType !== NetworkType.mainnet) {\n etherscanSubdomain = `api-${networkType}`;\n }\n\n const apiUrl = `https://${etherscanSubdomain}.etherscan.io`;\n let url = `${apiUrl}/api?`;\n\n for (const paramKey in urlParams) {\n const value = urlParams[paramKey];\n\n if (!value) {\n continue;\n }\n\n url += `${paramKey}=${value}&`;\n }\n\n url += 'tag=latest&page=1';\n\n return url;\n}\n"]}
1
+ {"version":3,"file":"etherscan.js","sourceRoot":"","sources":["../src/etherscan.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAAyD;AAGzD,2CAA2D;AAuD3D;;;;;;;;;;GAUG;AACH,SAAsB,0BAA0B,CAAC,EAC/C,OAAO,EACP,MAAM,EACN,OAAO,EACP,SAAS,EACT,KAAK,GACuB;;QAG5B,OAAO,MAAM,iBAAiB,CAAC,QAAQ,EAAE;YACvC,OAAO;YACP,MAAM;YACN,OAAO;YACP,SAAS;YACT,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CAAA;AAhBD,gEAgBC;AAED;;;;;;;;;;GAUG;AACH,SAAsB,+BAA+B,CAAC,EACpD,OAAO,EACP,MAAM,EACN,OAAO,EACP,SAAS,EACT,KAAK,GACuB;;QAG5B,OAAO,MAAM,iBAAiB,CAAC,SAAS,EAAE;YACxC,OAAO;YACP,MAAM;YACN,OAAO;YACP,SAAS;YACT,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CAAA;AAhBD,0EAgBC;AAED;;;;;;;;;;;GAWG;AACH,SAAe,iBAAiB,CAC9B,MAAc,EACd,EACE,OAAO,EACP,MAAM,EACN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G,QAAQ,IAAI,KAAK,GAAG,CAAC;KAChC;IAED,GAAG,IAAI,mBAAmB,CAAC;IAE3B,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { handleFetch } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { ETHERSCAN_SUPPORTED_NETWORKS } from './constants';\n\nexport interface EtherscanTransactionMetaBase {\n blockNumber: string;\n blockHash: string;\n confirmations: string;\n contractAddress: string;\n cumulativeGasUsed: string;\n from: string;\n gas: string;\n gasPrice: string;\n gasUsed: string;\n hash: string;\n nonce: string;\n timeStamp: string;\n to: string;\n transactionIndex: string;\n value: string;\n}\n\nexport interface EtherscanTransactionMeta extends EtherscanTransactionMetaBase {\n functionName: string;\n input: string;\n isError: string;\n methodId: string;\n txreceipt_status: string;\n}\n\nexport interface EtherscanTokenTransactionMeta\n extends EtherscanTransactionMetaBase {\n tokenDecimal: string;\n tokenName: string;\n tokenSymbol: string;\n}\n\nexport interface EtherscanTransactionResponse<\n T extends EtherscanTransactionMetaBase,\n> {\n result: T[];\n}\n\nexport interface EtherscanTransactionRequest {\n address: string;\n apiKey?: string;\n chainId: Hex;\n fromBlock?: number;\n limit?: number;\n}\n\ninterface RawEtherscanResponse<T extends EtherscanTransactionMetaBase> {\n status: '0' | '1';\n message: string;\n result: string | T[];\n}\n\n/**\n * Retrieves transaction data from Etherscan.\n *\n * @param request - Configuration required to fetch transactions.\n * @param request.address - Address to retrieve transactions for.\n * @param request.apiKey - Etherscan API key.\n * @param request.chainId - Current chain ID used to determine subdomain and domain.\n * @param request.fromBlock - Block number to start fetching transactions from.\n * @param request.limit - Number of transactions to retrieve.\n * @returns An Etherscan response object containing the request status and an array of token transaction data.\n */\nexport async function fetchEtherscanTransactions({\n address,\n apiKey,\n chainId,\n fromBlock,\n limit,\n}: EtherscanTransactionRequest): Promise<\n EtherscanTransactionResponse<EtherscanTransactionMeta>\n> {\n return await fetchTransactions('txlist', {\n address,\n apiKey,\n chainId,\n fromBlock,\n limit,\n });\n}\n\n/**\n * Retrieves token transaction data from Etherscan.\n *\n * @param request - Configuration required to fetch token transactions.\n * @param request.address - Address to retrieve token transactions for.\n * @param request.apiKey - Etherscan API key.\n * @param request.chainId - Current chain ID used to determine subdomain and domain.\n * @param request.fromBlock - Block number to start fetching token transactions from.\n * @param request.limit - Number of token transactions to retrieve.\n * @returns An Etherscan response object containing the request status and an array of token transaction data.\n */\nexport async function fetchEtherscanTokenTransactions({\n address,\n apiKey,\n chainId,\n fromBlock,\n limit,\n}: EtherscanTransactionRequest): Promise<\n EtherscanTransactionResponse<EtherscanTokenTransactionMeta>\n> {\n return await fetchTransactions('tokentx', {\n address,\n apiKey,\n chainId,\n fromBlock,\n limit,\n });\n}\n\n/**\n * Retrieves transaction data from Etherscan from a specific endpoint.\n *\n * @param action - The Etherscan endpoint to use.\n * @param options - Options bag.\n * @param options.address - Address to retrieve transactions for.\n * @param options.apiKey - Etherscan API key.\n * @param options.chainId - Current chain ID used to determine subdomain and domain.\n * @param options.fromBlock - Block number to start fetching transactions from.\n * @param options.limit - Number of transactions to retrieve.\n * @returns An object containing the request status and an array of transaction data.\n */\nasync function fetchTransactions<T extends EtherscanTransactionMetaBase>(\n action: string,\n {\n address,\n apiKey,\n chainId,\n fromBlock,\n limit,\n }: {\n address: string;\n apiKey?: string;\n chainId: Hex;\n fromBlock?: number;\n limit?: number;\n },\n): Promise<EtherscanTransactionResponse<T>> {\n const urlParams = {\n module: 'account',\n address,\n startBlock: fromBlock?.toString(),\n apikey: apiKey,\n offset: limit?.toString(),\n order: 'desc',\n };\n\n const etherscanTxUrl = getEtherscanApiUrl(chainId, {\n ...urlParams,\n action,\n });\n\n const response = (await handleFetch(\n etherscanTxUrl,\n )) as RawEtherscanResponse<T>;\n\n if (response.status === '0' && response.message === 'NOTOK') {\n throw new Error(`Etherscan request failed - ${response.result}`);\n }\n\n return { result: response.result as T[] };\n}\n\n/**\n * Return a URL that can be used to fetch data from Etherscan.\n *\n * @param chainId - Current chain ID used to determine subdomain and domain.\n * @param urlParams - The parameters used to construct the URL.\n * @returns URL to access Etherscan data.\n */\nfunction getEtherscanApiUrl(\n chainId: Hex,\n urlParams: Record<string, string | undefined>,\n): string {\n type SupportedChainId = keyof typeof ETHERSCAN_SUPPORTED_NETWORKS;\n\n const networkInfo = ETHERSCAN_SUPPORTED_NETWORKS[chainId as SupportedChainId];\n\n if (!networkInfo) {\n throw new Error(`Etherscan does not support chain with ID: ${chainId}`);\n }\n\n const apiUrl = `https://${networkInfo.subdomain}.${networkInfo.domain}`;\n let url = `${apiUrl}/api?`;\n\n // eslint-disable-next-line guard-for-in\n for (const paramKey in urlParams) {\n const value = urlParams[paramKey];\n\n if (!value) {\n continue;\n }\n\n url += `${paramKey}=${value}&`;\n }\n\n url += 'tag=latest&page=1';\n\n return url;\n}\n"]}
package/dist/types.d.ts CHANGED
@@ -1,21 +1,6 @@
1
- import type { NetworkType } from '@metamask/controller-utils';
2
1
  import type { Hex } from '@metamask/utils';
3
2
  /**
4
- * @type TransactionMeta
5
- *
6
- * TransactionMeta representation
7
- * @property error - Synthesized error information for failed transactions
8
- * @property id - Generated UUID associated with this transaction
9
- * @property networkID - Network code as per EIP-155 for this transaction
10
- * @property origin - Origin this transaction was sent from
11
- * @property deviceConfirmedOn - string to indicate what device the transaction was confirmed
12
- * @property rawTransaction - Hex representation of the underlying transaction
13
- * @property status - String status of this transaction
14
- * @property time - Timestamp associated with this transaction
15
- * @property toSmartContract - Whether transaction recipient is a smart contract
16
- * @property transaction - Underlying Transaction object
17
- * @property transactionHash - Hash of a successful transaction
18
- * @property blockNumber - Number of the block where the transaction has been included
3
+ * Representation of transaction metadata.
19
4
  */
20
5
  export declare type TransactionMeta = ({
21
6
  status: Exclude<TransactionStatus, TransactionStatus.failed>;
@@ -23,24 +8,81 @@ export declare type TransactionMeta = ({
23
8
  status: TransactionStatus.failed;
24
9
  error: Error;
25
10
  } & TransactionMetaBase);
11
+ /**
12
+ * Information about a single transaction such as status and block number.
13
+ */
26
14
  declare type TransactionMetaBase = {
27
- isTransfer?: boolean;
28
- transferInformation?: {
29
- symbol: string;
30
- contractAddress: string;
31
- decimals: number;
32
- };
15
+ /**
16
+ * Base fee of the block as a hex value, introduced in EIP-1559.
17
+ */
18
+ baseFeePerGas?: Hex;
19
+ /**
20
+ * Number of the block where the transaction has been included.
21
+ */
22
+ blockNumber?: string;
23
+ /**
24
+ * Network code as per EIP-155 for this transaction.
25
+ */
26
+ chainId?: Hex;
27
+ /**
28
+ * Gas values provided by the dApp.
29
+ */
30
+ dappSuggestedGasFees?: DappSuggestedGasFees;
31
+ /**
32
+ * String to indicate what device the transaction was confirmed on.
33
+ */
34
+ deviceConfirmedOn?: WalletDevice;
35
+ /**
36
+ * Generated UUID associated with this transaction.
37
+ */
33
38
  id: string;
39
+ /**
40
+ * Whether the transaction is a transfer.
41
+ */
42
+ isTransfer?: boolean;
43
+ /**
44
+ * Network code as per EIP-155 for this transaction.
45
+ */
34
46
  networkID?: string;
35
- chainId?: Hex;
47
+ /**
48
+ * Origin this transaction was sent from.
49
+ */
36
50
  origin?: string;
51
+ /**
52
+ * Hex representation of the underlying transaction.
53
+ */
37
54
  rawTransaction?: string;
55
+ /**
56
+ * Timestamp associated with this transaction.
57
+ */
38
58
  time: number;
59
+ /**
60
+ * Whether transaction recipient is a smart contract.
61
+ */
39
62
  toSmartContract?: boolean;
63
+ /**
64
+ * Underlying Transaction object.
65
+ */
40
66
  transaction: Transaction;
67
+ /**
68
+ * Hash of a successful transaction.
69
+ */
41
70
  transactionHash?: string;
42
- blockNumber?: string;
43
- deviceConfirmedOn?: WalletDevice;
71
+ /**
72
+ * Additional transfer information.
73
+ */
74
+ transferInformation?: {
75
+ contractAddress: string;
76
+ decimals: number;
77
+ symbol: string;
78
+ };
79
+ /**
80
+ * Transaction receipt.
81
+ */
82
+ txReceipt?: TransactionReceipt;
83
+ /**
84
+ * Whether the transaction is verified on the blockchain.
85
+ */
44
86
  verifiedOnBlockchain?: boolean;
45
87
  };
46
88
  /**
@@ -67,33 +109,111 @@ export declare enum WalletDevice {
67
109
  OTHER = "other_device"
68
110
  }
69
111
  /**
70
- * @type Transaction
71
- *
72
- * Transaction representation
73
- * @property chainId - Network ID as per EIP-155
74
- * @property data - Data to pass with this transaction
75
- * @property from - Address to send this transaction from
76
- * @property gas - Gas to send with this transaction
77
- * @property gasPrice - Price of gas with this transaction
78
- * @property gasUsed - Gas used in the transaction
79
- * @property nonce - Unique number to prevent replay attacks
80
- * @property to - Address to send this transaction to
81
- * @property value - Value associated with this transaction
112
+ * Standard data concerning a transaction to be processed by the blockchain.
82
113
  */
83
114
  export interface Transaction {
115
+ /**
116
+ * Network ID as per EIP-155.
117
+ */
84
118
  chainId?: Hex;
119
+ /**
120
+ * Data to pass with this transaction.
121
+ */
85
122
  data?: string;
123
+ /**
124
+ * Error message for gas estimation failure.
125
+ */
126
+ estimateGasError?: string;
127
+ /**
128
+ * Estimated base fee for this transaction.
129
+ */
130
+ estimatedBaseFee?: string;
131
+ /**
132
+ * Address to send this transaction from.
133
+ */
86
134
  from: string;
135
+ /**
136
+ * Gas to send with this transaction.
137
+ */
87
138
  gas?: string;
139
+ /**
140
+ * Price of gas with this transaction.
141
+ */
88
142
  gasPrice?: string;
143
+ /**
144
+ * Gas used in the transaction.
145
+ */
89
146
  gasUsed?: string;
147
+ /**
148
+ * Maximum fee per gas for this transaction.
149
+ */
150
+ maxFeePerGas?: string;
151
+ /**
152
+ * Maximum priority fee per gas for this transaction.
153
+ */
154
+ maxPriorityFeePerGas?: string;
155
+ /**
156
+ * Unique number to prevent replay attacks.
157
+ */
90
158
  nonce?: string;
159
+ /**
160
+ * Address to send this transaction to.
161
+ */
91
162
  to?: string;
163
+ /**
164
+ * Value associated with this transaction.
165
+ */
92
166
  value?: string;
93
- maxFeePerGas?: string;
94
- maxPriorityFeePerGas?: string;
95
- estimatedBaseFee?: string;
96
- estimateGasError?: string;
167
+ }
168
+ /**
169
+ * Standard data concerning a transaction processed by the blockchain.
170
+ */
171
+ export interface TransactionReceipt {
172
+ /**
173
+ * The block hash of the block that this transaction was included in.
174
+ */
175
+ blockHash?: string;
176
+ /**
177
+ * The block number of the block that this transaction was included in.
178
+ */
179
+ blockNumber?: string;
180
+ /**
181
+ * Effective gas price the transaction was charged at.
182
+ */
183
+ effectiveGasPrice?: string;
184
+ /**
185
+ * Gas used in the transaction.
186
+ */
187
+ gasUsed?: string;
188
+ /**
189
+ * Total used gas in hex.
190
+ */
191
+ l1Fee?: string;
192
+ /**
193
+ * All the logs emitted by this transaction.
194
+ */
195
+ logs?: Log[];
196
+ /**
197
+ * The status of the transaction.
198
+ */
199
+ status?: string;
200
+ /**
201
+ * The index of this transaction in the list of transactions included in the block this transaction was mined in.
202
+ */
203
+ transactionIndex?: number;
204
+ }
205
+ /**
206
+ * Represents an event that has been included in a transaction using the EVM `LOG` opcode.
207
+ */
208
+ export interface Log {
209
+ /**
210
+ * Address of the contract that generated log.
211
+ */
212
+ address?: string;
213
+ /**
214
+ * List of topics for log.
215
+ */
216
+ topics?: string;
97
217
  }
98
218
  /**
99
219
  * The configuration required to fetch transaction data from a RemoteTransactionSource.
@@ -118,22 +238,28 @@ export interface RemoteTransactionSourceRequest {
118
238
  /**
119
239
  * Block number to start fetching transactions from.
120
240
  */
121
- fromBlock?: string;
241
+ fromBlock?: number;
122
242
  /**
123
243
  * Maximum number of transactions to retrieve.
124
244
  */
125
- limit: number;
126
- /**
127
- * The type of the current network.
128
- */
129
- networkType: NetworkType;
245
+ limit?: number;
130
246
  }
131
247
  /**
132
248
  * An object capable of fetching transaction data from a remote source.
133
249
  * Used by the IncomingTransactionHelper to retrieve remote transaction data.
134
250
  */
135
251
  export interface RemoteTransactionSource {
252
+ isSupportedNetwork: (chainId: Hex, networkId: string) => boolean;
136
253
  fetchTransactions: (request: RemoteTransactionSourceRequest) => Promise<TransactionMeta[]>;
137
254
  }
255
+ /**
256
+ * Gas values initially suggested by the dApp.
257
+ */
258
+ export interface DappSuggestedGasFees {
259
+ gas?: string;
260
+ gasPrice?: string;
261
+ maxFeePerGas?: string;
262
+ maxPriorityFeePerGas?: string;
263
+ }
138
264
  export {};
139
265
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;;;;;;;;;;;;GAgBG;AACH,oBAAY,eAAe,GACvB,CAAC;IACC,MAAM,EAAE,OAAO,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,MAAM,CAAC,CAAC;CAC9D,GAAG,mBAAmB,CAAC,GACxB,CAAC;IAAE,MAAM,EAAE,iBAAiB,CAAC,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG,mBAAmB,CAAC,CAAC;AAE/E,aAAK,mBAAmB,GAAG;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mBAAmB,CAAC,EAAE;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,WAAW,EAAE,WAAW,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,YAAY,CAAC;IACjC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF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,MAAM,CAAC;CAC/B"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA+CA;;;;GAIG;AACH,IAAY,iBASX;AATD,WAAY,iBAAiB;IAC3B,0CAAqB,CAAA;IACrB,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;IACvB,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;IACjB,4CAAuB,CAAA;IACvB,8CAAyB,CAAA;AAC3B,CAAC,EATW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAS5B;AAED;;GAEG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,6CAA6B,CAAA;IAC7B,mDAAmC,CAAA;IACnC,sCAAsB,CAAA;AACxB,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB","sourcesContent":["import type { NetworkType } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\n/**\n * @type TransactionMeta\n *\n * TransactionMeta representation\n * @property error - Synthesized error information for failed transactions\n * @property id - Generated UUID associated with this transaction\n * @property networkID - Network code as per EIP-155 for this transaction\n * @property origin - Origin this transaction was sent from\n * @property deviceConfirmedOn - string to indicate what device the transaction was confirmed\n * @property rawTransaction - Hex representation of the underlying transaction\n * @property status - String status of this transaction\n * @property time - Timestamp associated with this transaction\n * @property toSmartContract - Whether transaction recipient is a smart contract\n * @property transaction - Underlying Transaction object\n * @property transactionHash - Hash of a successful transaction\n * @property blockNumber - Number of the block where the transaction has been included\n */\nexport type TransactionMeta =\n | ({\n status: Exclude<TransactionStatus, TransactionStatus.failed>;\n } & TransactionMetaBase)\n | ({ status: TransactionStatus.failed; error: Error } & TransactionMetaBase);\n\ntype TransactionMetaBase = {\n isTransfer?: boolean;\n transferInformation?: {\n symbol: string;\n contractAddress: string;\n decimals: number;\n };\n id: string;\n networkID?: string;\n chainId?: Hex;\n origin?: string;\n rawTransaction?: string;\n time: number;\n toSmartContract?: boolean;\n transaction: Transaction;\n transactionHash?: string;\n blockNumber?: string;\n deviceConfirmedOn?: WalletDevice;\n verifiedOnBlockchain?: boolean;\n};\n\n/**\n * The status of the transaction. Each status represents the state of the transaction internally\n * in the wallet. Some of these correspond with the state of the transaction on the network, but\n * some are wallet-specific.\n */\nexport enum TransactionStatus {\n approved = 'approved',\n cancelled = 'cancelled',\n confirmed = 'confirmed',\n failed = 'failed',\n rejected = 'rejected',\n signed = 'signed',\n submitted = 'submitted',\n unapproved = 'unapproved',\n}\n\n/**\n * Options for wallet device.\n */\nexport enum WalletDevice {\n MM_MOBILE = 'metamask_mobile',\n MM_EXTENSION = 'metamask_extension',\n OTHER = 'other_device',\n}\n\n/**\n * @type Transaction\n *\n * Transaction representation\n * @property chainId - Network ID as per EIP-155\n * @property data - Data to pass with this transaction\n * @property from - Address to send this transaction from\n * @property gas - Gas to send with this transaction\n * @property gasPrice - Price of gas with this transaction\n * @property gasUsed - Gas used in the transaction\n * @property nonce - Unique number to prevent replay attacks\n * @property to - Address to send this transaction to\n * @property value - Value associated with this transaction\n */\nexport interface Transaction {\n chainId?: Hex;\n data?: string;\n from: string;\n gas?: string;\n gasPrice?: string;\n gasUsed?: string;\n nonce?: string;\n to?: string;\n value?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n estimatedBaseFee?: string;\n estimateGasError?: string;\n}\n\n/**\n * The configuration required to fetch transaction data from a RemoteTransactionSource.\n */\nexport interface RemoteTransactionSourceRequest {\n /**\n * The address of the account to fetch transactions for.\n */\n address: string;\n\n /**\n * API key if required by the remote source.\n */\n apiKey?: string;\n\n /**\n * The chainId of the current network.\n */\n currentChainId: Hex;\n\n /**\n * The networkId of the current network.\n */\n currentNetworkId: string;\n\n /**\n * Block number to start fetching transactions from.\n */\n fromBlock?: string;\n\n /**\n * Maximum number of transactions to retrieve.\n */\n limit: number;\n\n /**\n * The type of the current network.\n */\n networkType: NetworkType;\n}\n\n/**\n * An object capable of fetching transaction data from a remote source.\n * Used by the IncomingTransactionHelper to retrieve remote transaction data.\n */\nexport interface RemoteTransactionSource {\n fetchTransactions: (\n request: RemoteTransactionSourceRequest,\n ) => Promise<TransactionMeta[]>;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAyGA;;;;GAIG;AACH,IAAY,iBASX;AATD,WAAY,iBAAiB;IAC3B,0CAAqB,CAAA;IACrB,4CAAuB,CAAA;IACvB,4CAAuB,CAAA;IACvB,sCAAiB,CAAA;IACjB,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;IACjB,4CAAuB,CAAA;IACvB,8CAAyB,CAAA;AAC3B,CAAC,EATW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAS5B;AAED;;GAEG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,6CAA6B,CAAA;IAC7B,mDAAmC,CAAA;IACnC,sCAAsB,CAAA;AACxB,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB","sourcesContent":["import type { Hex } from '@metamask/utils';\n\n/**\n * Representation of transaction metadata.\n */\nexport type TransactionMeta =\n | ({\n status: Exclude<TransactionStatus, TransactionStatus.failed>;\n } & TransactionMetaBase)\n | ({ status: TransactionStatus.failed; error: Error } & TransactionMetaBase);\n\n/**\n * Information about a single transaction such as status and block number.\n */\ntype TransactionMetaBase = {\n /**\n * Base fee of the block as a hex value, introduced in EIP-1559.\n */\n baseFeePerGas?: Hex;\n\n /**\n * Number of the block where the transaction has been included.\n */\n blockNumber?: string;\n\n /**\n * Network code as per EIP-155 for this transaction.\n */\n chainId?: Hex;\n\n /**\n * Gas values provided by the dApp.\n */\n dappSuggestedGasFees?: DappSuggestedGasFees;\n\n /**\n * String to indicate what device the transaction was confirmed on.\n */\n deviceConfirmedOn?: WalletDevice;\n\n /**\n * Generated UUID associated with this transaction.\n */\n id: string;\n\n /**\n * Whether the transaction is a transfer.\n */\n isTransfer?: boolean;\n\n /**\n * Network code as per EIP-155 for this transaction.\n */\n networkID?: string;\n\n /**\n * Origin this transaction was sent from.\n */\n origin?: string;\n\n /**\n * Hex representation of the underlying transaction.\n */\n rawTransaction?: string;\n\n /**\n * Timestamp associated with this transaction.\n */\n time: number;\n\n /**\n * Whether transaction recipient is a smart contract.\n */\n toSmartContract?: boolean;\n\n /**\n * Underlying Transaction object.\n */\n transaction: Transaction;\n\n /**\n * Hash of a successful transaction.\n */\n transactionHash?: string;\n\n /**\n * Additional transfer information.\n */\n transferInformation?: {\n contractAddress: string;\n decimals: number;\n symbol: string;\n };\n\n /**\n * Transaction receipt.\n */\n txReceipt?: TransactionReceipt;\n\n /**\n * Whether the transaction is verified on the blockchain.\n */\n verifiedOnBlockchain?: boolean;\n};\n\n/**\n * The status of the transaction. Each status represents the state of the transaction internally\n * in the wallet. Some of these correspond with the state of the transaction on the network, but\n * some are wallet-specific.\n */\nexport enum TransactionStatus {\n approved = 'approved',\n cancelled = 'cancelled',\n confirmed = 'confirmed',\n failed = 'failed',\n rejected = 'rejected',\n signed = 'signed',\n submitted = 'submitted',\n unapproved = 'unapproved',\n}\n\n/**\n * Options for wallet device.\n */\nexport enum WalletDevice {\n MM_MOBILE = 'metamask_mobile',\n MM_EXTENSION = 'metamask_extension',\n OTHER = 'other_device',\n}\n\n/**\n * Standard data concerning a transaction to be processed by the blockchain.\n */\nexport interface Transaction {\n /**\n * Network ID as per EIP-155.\n */\n chainId?: Hex;\n\n /**\n * Data to pass with this transaction.\n */\n data?: string;\n\n /**\n * Error message for gas estimation failure.\n */\n estimateGasError?: string;\n\n /**\n * Estimated base fee for this transaction.\n */\n estimatedBaseFee?: string;\n\n /**\n * Address to send this transaction from.\n */\n from: string;\n\n /**\n * Gas to send with this transaction.\n */\n gas?: string;\n\n /**\n * Price of gas with this transaction.\n */\n gasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Maximum fee per gas for this transaction.\n */\n maxFeePerGas?: string;\n\n /**\n * Maximum priority fee per gas for this transaction.\n */\n maxPriorityFeePerGas?: string;\n\n /**\n * Unique number to prevent replay attacks.\n */\n nonce?: string;\n\n /**\n * Address to send this transaction to.\n */\n to?: string;\n\n /**\n * Value associated with this transaction.\n */\n value?: string;\n}\n\n/**\n * Standard data concerning a transaction processed by the blockchain.\n */\nexport interface TransactionReceipt {\n /**\n * The block hash of the block that this transaction was included in.\n */\n blockHash?: string;\n\n /**\n * The block number of the block that this transaction was included in.\n */\n blockNumber?: string;\n\n /**\n * Effective gas price the transaction was charged at.\n */\n effectiveGasPrice?: string;\n\n /**\n * Gas used in the transaction.\n */\n gasUsed?: string;\n\n /**\n * Total used gas in hex.\n */\n l1Fee?: string;\n\n /**\n * All the logs emitted by this transaction.\n */\n logs?: Log[];\n\n /**\n * The status of the transaction.\n */\n status?: string;\n\n /**\n * The index of this transaction in the list of transactions included in the block this transaction was mined in.\n */\n transactionIndex?: number;\n}\n\n/**\n * Represents an event that has been included in a transaction using the EVM `LOG` opcode.\n */\nexport interface Log {\n /**\n * Address of the contract that generated log.\n */\n address?: string;\n /**\n * List of topics for log.\n */\n topics?: string;\n}\n\n/**\n * The configuration required to fetch transaction data from a RemoteTransactionSource.\n */\nexport interface RemoteTransactionSourceRequest {\n /**\n * The address of the account to fetch transactions for.\n */\n address: string;\n\n /**\n * API key if required by the remote source.\n */\n apiKey?: string;\n\n /**\n * The chainId of the current network.\n */\n currentChainId: Hex;\n\n /**\n * The networkId of the current network.\n */\n currentNetworkId: string;\n\n /**\n * Block number to start fetching transactions from.\n */\n fromBlock?: number;\n\n /**\n * Maximum number of transactions to retrieve.\n */\n limit?: number;\n}\n\n/**\n * An object capable of fetching transaction data from a remote source.\n * Used by the IncomingTransactionHelper to retrieve remote transaction data.\n */\nexport interface RemoteTransactionSource {\n isSupportedNetwork: (chainId: Hex, networkId: string) => boolean;\n\n fetchTransactions: (\n request: RemoteTransactionSourceRequest,\n ) => Promise<TransactionMeta[]>;\n}\n\n/**\n * Gas values initially suggested by the dApp.\n */\nexport interface DappSuggestedGasFees {\n gas?: string;\n gasPrice?: string;\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n}\n"]}
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Hex } from '@metamask/utils';
1
2
  import type { Transaction as NonceTrackerTransaction } from 'nonce-tracker/dist/NonceTracker';
2
3
  import type { GasPriceValue, FeeMarketEIP1559Values } from './TransactionController';
3
4
  import type { Transaction, TransactionMeta, TransactionStatus } from './types';
@@ -47,4 +48,14 @@ export declare function validateMinimumIncrease(proposed: string, min: string):
47
48
  * @returns Array of transactions formatted for the nonce tracker.
48
49
  */
49
50
  export declare function getAndFormatTransactionsForNonceTracker(fromAddress: string, transactionStatus: TransactionStatus, transactions: TransactionMeta[]): NonceTrackerTransaction[];
51
+ /**
52
+ * Checks whether a given transaction matches the specified network or chain ID.
53
+ * This function is used to determine if a transaction is relevant to the current network or chain.
54
+ *
55
+ * @param transaction - The transaction metadata to check.
56
+ * @param chainId - The chain ID of the current network.
57
+ * @param networkId - The network ID of the current network.
58
+ * @returns A boolean value indicating whether the transaction matches the current network or chain ID.
59
+ */
60
+ export declare function transactionMatchesNetwork(transaction: TransactionMeta, chainId: Hex, networkId: string | null): boolean;
50
61
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,IAAI,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE9F,OAAO,KAAK,EACV,aAAa,EACb,sBAAsB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE/E,eAAO,MAAM,kBAAkB,qCAAqC,CAAC;AAiBrE;;;;;GAKG;AACH,wBAAg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B,CAAC,WAAW,EAAE,WAAW,QAmD3D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,gBAAiB,WAAW,KAAG,OAO/D,CAAC;AAEF,eAAO,MAAM,iBAAiB,cACjB,aAAa,GAAG,sBAAsB,SAUlD,CAAC;AAEF,eAAO,MAAM,wBAAwB,yGAIsC,CAAC;AAE5E,eAAO,MAAM,eAAe,gGAG0B,CAAC;AAEvD,eAAO,MAAM,oBAAoB,UAAW,MAAM,QAAQ,MAAM,KAAG,MACF,CAAC;AAElE,eAAO,MAAM,6BAA6B,UACjC,MAAM,GAAG,SAAS,QACnB,MAAM,KACX,MAEF,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAQpE;AAED;;;;;;;GAOG;AACH,wBAAgB,uCAAuC,CACrD,WAAW,EAAE,MAAM,EACnB,iBAAiB,EAAE,iBAAiB,EACpC,YAAY,EAAE,eAAe,EAAE,GAC9B,uBAAuB,EAAE,CAsB3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,eAAe,EAC5B,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,MAAM,GAAG,IAAI,WASzB"}
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAndFormatTransactionsForNonceTracker = exports.validateMinimumIncrease = exports.getIncreasedPriceFromExisting = exports.getIncreasedPriceHex = exports.isGasPriceValue = exports.isFeeMarketEIP1559Values = exports.validateGasValues = exports.isEIP1559Transaction = exports.validateTransaction = exports.normalizeTransaction = exports.ESTIMATE_GAS_ERROR = void 0;
3
+ exports.transactionMatchesNetwork = exports.getAndFormatTransactionsForNonceTracker = exports.validateMinimumIncrease = exports.getIncreasedPriceFromExisting = exports.getIncreasedPriceHex = exports.isGasPriceValue = exports.isFeeMarketEIP1559Values = exports.validateGasValues = exports.isEIP1559Transaction = exports.validateTransaction = exports.normalizeTransaction = exports.ESTIMATE_GAS_ERROR = void 0;
4
4
  const controller_utils_1 = require("@metamask/controller-utils");
5
5
  const ethereumjs_util_1 = require("ethereumjs-util");
6
6
  exports.ESTIMATE_GAS_ERROR = 'eth_estimateGas rpc method error';
@@ -156,4 +156,23 @@ function getAndFormatTransactionsForNonceTracker(fromAddress, transactionStatus,
156
156
  });
157
157
  }
158
158
  exports.getAndFormatTransactionsForNonceTracker = getAndFormatTransactionsForNonceTracker;
159
+ /**
160
+ * Checks whether a given transaction matches the specified network or chain ID.
161
+ * This function is used to determine if a transaction is relevant to the current network or chain.
162
+ *
163
+ * @param transaction - The transaction metadata to check.
164
+ * @param chainId - The chain ID of the current network.
165
+ * @param networkId - The network ID of the current network.
166
+ * @returns A boolean value indicating whether the transaction matches the current network or chain ID.
167
+ */
168
+ function transactionMatchesNetwork(transaction, chainId, networkId) {
169
+ if (transaction.chainId) {
170
+ return transaction.chainId === chainId;
171
+ }
172
+ if (transaction.networkID) {
173
+ return transaction.networkID === networkId;
174
+ }
175
+ return false;
176
+ }
177
+ exports.transactionMatchesNetwork = transactionMatchesNetwork;
159
178
  //# sourceMappingURL=utils.js.map