@metamask/transaction-controller 18.2.0 → 18.3.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +362 -0
  2. package/dist/TransactionController.d.ts +8 -4
  3. package/dist/TransactionController.d.ts.map +1 -1
  4. package/dist/TransactionController.js +15 -3
  5. package/dist/TransactionController.js.map +1 -1
  6. package/package.json +2 -2
  7. package/dist/EtherscanRemoteTransactionSource.d.ts +0 -15
  8. package/dist/EtherscanRemoteTransactionSource.d.ts.map +0 -1
  9. package/dist/EtherscanRemoteTransactionSource.js +0 -122
  10. package/dist/EtherscanRemoteTransactionSource.js.map +0 -1
  11. package/dist/IncomingTransactionHelper.d.ts +0 -25
  12. package/dist/IncomingTransactionHelper.d.ts.map +0 -1
  13. package/dist/IncomingTransactionHelper.js +0 -198
  14. package/dist/IncomingTransactionHelper.js.map +0 -1
  15. package/dist/etherscan.d.ts +0 -64
  16. package/dist/etherscan.d.ts.map +0 -1
  17. package/dist/etherscan.js +0 -109
  18. package/dist/etherscan.js.map +0 -1
  19. package/dist/external-transactions.d.ts +0 -10
  20. package/dist/external-transactions.d.ts.map +0 -1
  21. package/dist/external-transactions.js +0 -36
  22. package/dist/external-transactions.js.map +0 -1
  23. package/dist/history.d.ts +0 -15
  24. package/dist/history.d.ts.map +0 -1
  25. package/dist/history.js +0 -75
  26. package/dist/history.js.map +0 -1
  27. package/dist/mocks/txsMock.d.ts +0 -64
  28. package/dist/mocks/txsMock.d.ts.map +0 -1
  29. package/dist/mocks/txsMock.js +0 -515
  30. package/dist/mocks/txsMock.js.map +0 -1
  31. package/dist/transaction-type.d.ts +0 -14
  32. package/dist/transaction-type.d.ts.map +0 -1
  33. package/dist/transaction-type.js +0 -114
  34. package/dist/transaction-type.js.map +0 -1
  35. package/dist/utils.d.ts +0 -72
  36. package/dist/utils.d.ts.map +0 -1
  37. package/dist/utils.js +0 -235
  38. package/dist/utils.js.map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AED;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,OAAY,EACZ,SAA6C;IAI7C,MAAM,WAAW,GAAG,wCAA4B,CAAC,OAA2B,CAAC,CAAC;IAE9E,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,6CAA6C,OAAO,EAAE,CAAC,CAAC;KACzE;IAED,MAAM,MAAM,GAAG,WAAW,WAAW,CAAC,SAAS,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;IACxE,IAAI,GAAG,GAAG,GAAG,MAAM,OAAO,CAAC;IAE3B,wCAAwC;IACxC,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 { handleFetch } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { ETHERSCAN_SUPPORTED_NETWORKS } from './constants';\nimport { incomingTransactionsLogger as log } from './logger';\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 message?: string;\n result: string | T[];\n}\n\nexport interface EtherscanTransactionRequest {\n address: string;\n chainId: Hex;\n fromBlock?: number;\n limit?: number;\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.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 chainId,\n fromBlock,\n limit,\n}: EtherscanTransactionRequest): Promise<\n EtherscanTransactionResponse<EtherscanTransactionMeta>\n> {\n return await fetchTransactions('txlist', {\n address,\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.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 chainId,\n fromBlock,\n limit,\n}: EtherscanTransactionRequest): Promise<\n EtherscanTransactionResponse<EtherscanTokenTransactionMeta>\n> {\n return await fetchTransactions('tokentx', {\n address,\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.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 chainId,\n fromBlock,\n limit,\n }: {\n address: 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 offset: limit?.toString(),\n sort: 'desc',\n };\n\n const etherscanTxUrl = getEtherscanApiUrl(chainId, {\n ...urlParams,\n action,\n });\n\n log('Sending Etherscan request', etherscanTxUrl);\n\n const response = (await handleFetch(\n etherscanTxUrl,\n )) as EtherscanTransactionResponse<T>;\n\n return response;\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"]}
@@ -1,10 +0,0 @@
1
- import type { TransactionMeta } from './types';
2
- /**
3
- * Validates the external provided transaction meta.
4
- *
5
- * @param transactionMeta - The transaction meta to validate.
6
- * @param confirmedTxs - The confirmed transactions in controller state.
7
- * @param pendingTxs - The submitted transactions in controller state.
8
- */
9
- export declare function validateConfirmedExternalTransaction(transactionMeta?: TransactionMeta, confirmedTxs?: TransactionMeta[], pendingTxs?: TransactionMeta[]): void;
10
- //# sourceMappingURL=external-transactions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"external-transactions.d.ts","sourceRoot":"","sources":["../src/external-transactions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,oCAAoC,CAClD,eAAe,CAAC,EAAE,eAAe,EACjC,YAAY,CAAC,EAAE,eAAe,EAAE,EAChC,UAAU,CAAC,EAAE,eAAe,EAAE,QAoC/B"}
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateConfirmedExternalTransaction = void 0;
4
- // These utility functions are exclusively used by `confirmExternalTransaction` method in controller
5
- const eth_rpc_errors_1 = require("eth-rpc-errors");
6
- const types_1 = require("./types");
7
- /**
8
- * Validates the external provided transaction meta.
9
- *
10
- * @param transactionMeta - The transaction meta to validate.
11
- * @param confirmedTxs - The confirmed transactions in controller state.
12
- * @param pendingTxs - The submitted transactions in controller state.
13
- */
14
- function validateConfirmedExternalTransaction(transactionMeta, confirmedTxs, pendingTxs) {
15
- if (!transactionMeta || !transactionMeta.txParams) {
16
- throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('"transactionMeta" or "transactionMeta.txParams" is missing');
17
- }
18
- if (transactionMeta.status !== types_1.TransactionStatus.confirmed) {
19
- throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('External transaction status should be "confirmed"');
20
- }
21
- const externalTxNonce = transactionMeta.txParams.nonce;
22
- if (pendingTxs && pendingTxs.length > 0) {
23
- const foundPendingTxByNonce = pendingTxs.find((tx) => { var _a; return ((_a = tx.txParams) === null || _a === void 0 ? void 0 : _a.nonce) === externalTxNonce; });
24
- if (foundPendingTxByNonce) {
25
- throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('External transaction nonce should not be in pending txs');
26
- }
27
- }
28
- if (confirmedTxs && confirmedTxs.length > 0) {
29
- const foundConfirmedTxByNonce = confirmedTxs.find((tx) => { var _a; return ((_a = tx.txParams) === null || _a === void 0 ? void 0 : _a.nonce) === externalTxNonce; });
30
- if (foundConfirmedTxByNonce) {
31
- throw eth_rpc_errors_1.ethErrors.rpc.invalidParams('External transaction nonce should not be in confirmed txs');
32
- }
33
- }
34
- }
35
- exports.validateConfirmedExternalTransaction = validateConfirmedExternalTransaction;
36
- //# sourceMappingURL=external-transactions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"external-transactions.js","sourceRoot":"","sources":["../src/external-transactions.ts"],"names":[],"mappings":";;;AAAA,oGAAoG;AACpG,mDAA2C;AAE3C,mCAA4C;AAG5C;;;;;;GAMG;AACH,SAAgB,oCAAoC,CAClD,eAAiC,EACjC,YAAgC,EAChC,UAA8B;IAE9B,IAAI,CAAC,eAAe,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE;QACjD,MAAM,0BAAS,CAAC,GAAG,CAAC,aAAa,CAC/B,4DAA4D,CAC7D,CAAC;KACH;IAED,IAAI,eAAe,CAAC,MAAM,KAAK,yBAAiB,CAAC,SAAS,EAAE;QAC1D,MAAM,0BAAS,CAAC,GAAG,CAAC,aAAa,CAC/B,mDAAmD,CACpD,CAAC;KACH;IAED,MAAM,eAAe,GAAG,eAAe,CAAC,QAAQ,CAAC,KAAK,CAAC;IACvD,IAAI,UAAU,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACvC,MAAM,qBAAqB,GAAG,UAAU,CAAC,IAAI,CAC3C,CAAC,EAAE,EAAE,EAAE,WAAC,OAAA,CAAA,MAAA,EAAE,CAAC,QAAQ,0CAAE,KAAK,MAAK,eAAe,CAAA,EAAA,CAC/C,CAAC;QACF,IAAI,qBAAqB,EAAE;YACzB,MAAM,0BAAS,CAAC,GAAG,CAAC,aAAa,CAC/B,yDAAyD,CAC1D,CAAC;SACH;KACF;IAED,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3C,MAAM,uBAAuB,GAAG,YAAY,CAAC,IAAI,CAC/C,CAAC,EAAE,EAAE,EAAE,WAAC,OAAA,CAAA,MAAA,EAAE,CAAC,QAAQ,0CAAE,KAAK,MAAK,eAAe,CAAA,EAAA,CAC/C,CAAC;QACF,IAAI,uBAAuB,EAAE;YAC3B,MAAM,0BAAS,CAAC,GAAG,CAAC,aAAa,CAC/B,2DAA2D,CAC5D,CAAC;SACH;KACF;AACH,CAAC;AAvCD,oFAuCC","sourcesContent":["// These utility functions are exclusively used by `confirmExternalTransaction` method in controller\nimport { ethErrors } from 'eth-rpc-errors';\n\nimport { TransactionStatus } from './types';\nimport type { TransactionMeta } from './types';\n\n/**\n * Validates the external provided transaction meta.\n *\n * @param transactionMeta - The transaction meta to validate.\n * @param confirmedTxs - The confirmed transactions in controller state.\n * @param pendingTxs - The submitted transactions in controller state.\n */\nexport function validateConfirmedExternalTransaction(\n transactionMeta?: TransactionMeta,\n confirmedTxs?: TransactionMeta[],\n pendingTxs?: TransactionMeta[],\n) {\n if (!transactionMeta || !transactionMeta.txParams) {\n throw ethErrors.rpc.invalidParams(\n '\"transactionMeta\" or \"transactionMeta.txParams\" is missing',\n );\n }\n\n if (transactionMeta.status !== TransactionStatus.confirmed) {\n throw ethErrors.rpc.invalidParams(\n 'External transaction status should be \"confirmed\"',\n );\n }\n\n const externalTxNonce = transactionMeta.txParams.nonce;\n if (pendingTxs && pendingTxs.length > 0) {\n const foundPendingTxByNonce = pendingTxs.find(\n (tx) => tx.txParams?.nonce === externalTxNonce,\n );\n if (foundPendingTxByNonce) {\n throw ethErrors.rpc.invalidParams(\n 'External transaction nonce should not be in pending txs',\n );\n }\n }\n\n if (confirmedTxs && confirmedTxs.length > 0) {\n const foundConfirmedTxByNonce = confirmedTxs.find(\n (tx) => tx.txParams?.nonce === externalTxNonce,\n );\n if (foundConfirmedTxByNonce) {\n throw ethErrors.rpc.invalidParams(\n 'External transaction nonce should not be in confirmed txs',\n );\n }\n }\n}\n"]}
package/dist/history.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { TransactionMeta } from './types';
2
- /**
3
- * Add initial history snapshot to the provided transactionMeta history.
4
- *
5
- * @param transactionMeta - TransactionMeta to add initial history snapshot to.
6
- */
7
- export declare function addInitialHistorySnapshot(transactionMeta: TransactionMeta): void;
8
- /**
9
- * Compares and adds history entry to the provided transactionMeta history.
10
- *
11
- * @param transactionMeta - TransactionMeta to add history entry to.
12
- * @param note - Note to add to history entry.
13
- */
14
- export declare function updateTransactionHistory(transactionMeta: TransactionMeta, note: string): void;
15
- //# sourceMappingURL=history.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAGV,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,eAAe,EAAE,eAAe,QAGzE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,MAAM,GACX,IAAI,CAWN"}
package/dist/history.js DELETED
@@ -1,75 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.updateTransactionHistory = exports.addInitialHistorySnapshot = void 0;
7
- const fast_json_patch_1 = __importDefault(require("fast-json-patch"));
8
- const lodash_1 = require("lodash");
9
- /**
10
- * Add initial history snapshot to the provided transactionMeta history.
11
- *
12
- * @param transactionMeta - TransactionMeta to add initial history snapshot to.
13
- */
14
- function addInitialHistorySnapshot(transactionMeta) {
15
- const snapshot = snapshotFromTransactionMeta(transactionMeta);
16
- transactionMeta.history = [snapshot];
17
- }
18
- exports.addInitialHistorySnapshot = addInitialHistorySnapshot;
19
- /**
20
- * Compares and adds history entry to the provided transactionMeta history.
21
- *
22
- * @param transactionMeta - TransactionMeta to add history entry to.
23
- * @param note - Note to add to history entry.
24
- */
25
- function updateTransactionHistory(transactionMeta, note) {
26
- var _a;
27
- const currentState = snapshotFromTransactionMeta(transactionMeta);
28
- const previousState = replayHistory(transactionMeta.history);
29
- const historyEntry = generateHistoryEntry(previousState, currentState, note);
30
- if (historyEntry.length) {
31
- (_a = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.history) === null || _a === void 0 ? void 0 : _a.push(historyEntry);
32
- }
33
- }
34
- exports.updateTransactionHistory = updateTransactionHistory;
35
- /**
36
- * Generates a history entry from the previous and new transaction metadata.
37
- *
38
- * @param previousState - The previous transaction metadata.
39
- * @param currentState - The new transaction metadata.
40
- * @param note - A note for the transaction metada update.
41
- * @returns An array of history operation.
42
- */
43
- function generateHistoryEntry(previousState, currentState, note) {
44
- const historyOperationsEntry = fast_json_patch_1.default.compare(previousState, currentState);
45
- // Add a note to the first operation, since it breaks if we append it to the entry
46
- if (historyOperationsEntry[0]) {
47
- if (note) {
48
- historyOperationsEntry[0].note = note;
49
- }
50
- historyOperationsEntry[0].timestamp = Date.now();
51
- }
52
- return historyOperationsEntry;
53
- }
54
- /**
55
- * Recovers previous transactionMeta from passed history array.
56
- *
57
- * @param transactionHistory - The transaction metadata to replay.
58
- * @returns The transaction metadata.
59
- */
60
- function replayHistory(transactionHistory) {
61
- const shortHistory = (0, lodash_1.cloneDeep)(transactionHistory);
62
- return shortHistory.reduce((val, entry) => fast_json_patch_1.default.applyPatch(val, entry).newDocument);
63
- }
64
- /**
65
- * Clone the transaction meta data without the history property.
66
- *
67
- * @param transactionMeta - The transaction metadata to snapshot.
68
- * @returns A deep clone of transaction metadata without history property.
69
- */
70
- function snapshotFromTransactionMeta(transactionMeta) {
71
- const snapshot = Object.assign({}, transactionMeta);
72
- delete snapshot.history;
73
- return (0, lodash_1.cloneDeep)(snapshot);
74
- }
75
- //# sourceMappingURL=history.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"history.js","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAyC;AACzC,mCAAmC;AAQnC;;;;GAIG;AACH,SAAgB,yBAAyB,CAAC,eAAgC;IACxE,MAAM,QAAQ,GAAG,2BAA2B,CAAC,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vB,CAAC;AAED;;;;;GAKG;AACH,SAAS,2BAA2B,CAClC,eAAgC;IAEhC,MAAM,QAAQ,qBAAQ,eAAe,CAAE,CAAC;IACxC,OAAO,QAAQ,CAAC,OAAO,CAAC;IACxB,OAAO,IAAA,kBAAS,EAAC,QAAQ,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import jsonDiffer from 'fast-json-patch';\nimport { cloneDeep } from 'lodash';\n\nimport type {\n TransactionHistory,\n TransactionHistoryEntry,\n TransactionMeta,\n} from './types';\n\n/**\n * Add initial history snapshot to the provided transactionMeta history.\n *\n * @param transactionMeta - TransactionMeta to add initial history snapshot to.\n */\nexport function addInitialHistorySnapshot(transactionMeta: TransactionMeta) {\n const snapshot = snapshotFromTransactionMeta(transactionMeta);\n transactionMeta.history = [snapshot];\n}\n\n/**\n * Compares and adds history entry to the provided transactionMeta history.\n *\n * @param transactionMeta - TransactionMeta to add history entry to.\n * @param note - Note to add to history entry.\n */\nexport function updateTransactionHistory(\n transactionMeta: TransactionMeta,\n note: string,\n): void {\n const currentState = snapshotFromTransactionMeta(transactionMeta);\n const previousState = replayHistory(\n transactionMeta.history as TransactionHistory,\n );\n\n const historyEntry = generateHistoryEntry(previousState, currentState, note);\n\n if (historyEntry.length) {\n transactionMeta?.history?.push(historyEntry);\n }\n}\n\n/**\n * Generates a history entry from the previous and new transaction metadata.\n *\n * @param previousState - The previous transaction metadata.\n * @param currentState - The new transaction metadata.\n * @param note - A note for the transaction metada update.\n * @returns An array of history operation.\n */\nfunction generateHistoryEntry(\n previousState: any,\n currentState: TransactionMeta,\n note: string,\n): TransactionHistoryEntry {\n const historyOperationsEntry = jsonDiffer.compare(\n previousState,\n currentState,\n ) as TransactionHistoryEntry;\n // Add a note to the first operation, since it breaks if we append it to the entry\n if (historyOperationsEntry[0]) {\n if (note) {\n historyOperationsEntry[0].note = note;\n }\n historyOperationsEntry[0].timestamp = Date.now();\n }\n return historyOperationsEntry;\n}\n\n/**\n * Recovers previous transactionMeta from passed history array.\n *\n * @param transactionHistory - The transaction metadata to replay.\n * @returns The transaction metadata.\n */\nfunction replayHistory(\n transactionHistory: TransactionHistory,\n): TransactionMeta {\n const shortHistory = cloneDeep(transactionHistory);\n return shortHistory.reduce(\n (val, entry: any) => jsonDiffer.applyPatch(val, entry).newDocument,\n ) as TransactionMeta;\n}\n\n/**\n * Clone the transaction meta data without the history property.\n *\n * @param transactionMeta - The transaction metadata to snapshot.\n * @returns A deep clone of transaction metadata without history property.\n */\nfunction snapshotFromTransactionMeta(\n transactionMeta: TransactionMeta,\n): TransactionMeta {\n const snapshot = { ...transactionMeta };\n delete snapshot.history;\n return cloneDeep(snapshot);\n}\n"]}
@@ -1,64 +0,0 @@
1
- import { TransactionMeta } from '../TransactionController';
2
- export declare const ethTxsMock: (ethTxHash: string) => ({
3
- blockNumber: string;
4
- confirmations: string;
5
- contractAddress: string;
6
- cumulativeGasUsed: string;
7
- from: string;
8
- gas: string;
9
- gasPrice: string;
10
- gasUsed: string;
11
- hash: string;
12
- input: string;
13
- isError: string;
14
- nonce: string;
15
- timeStamp: string;
16
- to: string;
17
- transactionIndex: string;
18
- txreceipt_status: string;
19
- value: string;
20
- } | {
21
- blockNumber: string;
22
- confirmations: string;
23
- contractAddress: string;
24
- cumulativeGasUsed: string;
25
- from: string;
26
- gas: string;
27
- gasPrice: string;
28
- gasUsed: string;
29
- hash: string;
30
- input: string;
31
- isError: string;
32
- nonce: string;
33
- timeStamp: string;
34
- transactionIndex: string;
35
- txreceipt_status: string;
36
- value: string;
37
- to?: undefined;
38
- })[];
39
- export declare const tokenTxsMock: (tokenTxHash: string) => {
40
- blockNumber: string;
41
- timeStamp: string;
42
- hash: string;
43
- nonce: string;
44
- blockHash: string;
45
- from: string;
46
- contractAddress: string;
47
- to: string;
48
- value: string;
49
- tokenName: string;
50
- tokenSymbol: string;
51
- tokenDecimal: string;
52
- transactionIndex: string;
53
- gas: string;
54
- gasPrice: string;
55
- gasUsed: string;
56
- cumulativeGasUsed: string;
57
- input: string;
58
- confirmations: string;
59
- }[];
60
- export declare const txsInStateMock: (ethTxHash: string, tokenTxHash: string) => TransactionMeta[];
61
- export declare const txsInStateWithOutdatedStatusMock: (ethTxHash: string, tokenTxHash: string) => TransactionMeta[];
62
- export declare const txsInStateWithOutdatedGasDataMock: (ethTxHash: string, tokenTxHash: string) => TransactionMeta[];
63
- export declare const txsInStateWithOutdatedStatusAndGasDataMock: (ethTxHash: string, tokenTxHash: string) => TransactionMeta[];
64
- //# sourceMappingURL=txsMock.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"txsMock.d.ts","sourceRoot":"","sources":["../../src/mocks/txsMock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAqB,MAAM,0BAA0B,CAAC;AAE9E,eAAO,MAAM,UAAU,cAAe,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4E3C,CAAC;AAEF,eAAO,MAAM,YAAY,gBAAiB,MAAM;;;;;;;;;;;;;;;;;;;;GA+R/C,CAAC;AAEF,eAAO,MAAM,cAAc,cACd,MAAM,eACJ,MAAM,KAClB,eAAe,EAqCjB,CAAC;AAEF,eAAO,MAAM,gCAAgC,cAChC,MAAM,eACJ,MAAM,KAClB,eAAe,EAqCjB,CAAC;AAEF,eAAO,MAAM,iCAAiC,cACjC,MAAM,eACJ,MAAM,KAClB,eAAe,EAqCjB,CAAC;AAEF,eAAO,MAAM,0CAA0C,cAC1C,MAAM,eACJ,MAAM,KAClB,eAAe,EAqCjB,CAAC"}