@metamask/transaction-controller 35.0.1 → 35.1.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.
- package/CHANGELOG.md +16 -1
- package/dist/TransactionController.js +3 -3
- package/dist/TransactionController.mjs +2 -2
- package/dist/{chunk-J2OIT7FN.mjs → chunk-5JWPMHSZ.mjs} +2 -2
- package/dist/{chunk-PHSSZPCU.js → chunk-QKS2F7VG.js} +5 -5
- package/dist/chunk-SMC5Q6ZH.mjs +120 -0
- package/dist/chunk-SMC5Q6ZH.mjs.map +1 -0
- package/dist/chunk-TIE3CPF7.js +120 -0
- package/dist/chunk-TIE3CPF7.js.map +1 -0
- package/dist/index.js +8 -3
- package/dist/index.mjs +7 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/history.d.ts +9 -0
- package/dist/types/utils/history.d.ts.map +1 -1
- package/dist/utils/history.js +6 -2
- package/dist/utils/history.mjs +5 -1
- package/package.json +1 -1
- package/dist/chunk-QP75SWIQ.js +0 -53
- package/dist/chunk-QP75SWIQ.js.map +0 -1
- package/dist/chunk-XGRAHX6T.mjs +0 -53
- package/dist/chunk-XGRAHX6T.mjs.map +0 -1
- /package/dist/{chunk-J2OIT7FN.mjs.map → chunk-5JWPMHSZ.mjs.map} +0 -0
- /package/dist/{chunk-PHSSZPCU.js.map → chunk-QKS2F7VG.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [35.1.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `DISPLAYED_TRANSACTION_HISTORY_PATHS` constant, representing the transaction history paths that may be used for display ([#4555](https://github.com/MetaMask/core/pull/4555))
|
|
15
|
+
- This was exported so that it might be used to ensure display logic and internal history logic remains in-sync.
|
|
16
|
+
- Any paths listed here will have their timestamps preserved. Unlisted paths may be compressed by the controller to minimize history size, losing the timestamp.
|
|
17
|
+
- Add `MAX_TRANSACTION_HISTORY_LENGTH` constant, representing the expected maximum size of the `history` property for a given transaction ([#4555](https://github.com/MetaMask/core/pull/4555))
|
|
18
|
+
- Note that this is not strictly enforced, the length may exceed this number of all entries are "displayed" entries, but we expect this to be extremely improbable in practice.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Prevent transaction history from growing endlessly in size ([#4555](https://github.com/MetaMask/core/pull/4555))
|
|
23
|
+
|
|
10
24
|
## [35.0.1]
|
|
11
25
|
|
|
12
26
|
### Changed
|
|
@@ -934,7 +948,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
934
948
|
|
|
935
949
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
936
950
|
|
|
937
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.0
|
|
951
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.1.0...HEAD
|
|
952
|
+
[35.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.0.1...@metamask/transaction-controller@35.1.0
|
|
938
953
|
[35.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.0.0...@metamask/transaction-controller@35.0.1
|
|
939
954
|
[35.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@34.0.0...@metamask/transaction-controller@35.0.0
|
|
940
955
|
[34.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@33.0.1...@metamask/transaction-controller@34.0.0
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkQKS2F7VGjs = require('./chunk-QKS2F7VG.js');
|
|
8
8
|
require('./chunk-PRUNMTRD.js');
|
|
9
9
|
require('./chunk-NNCUD3QF.js');
|
|
10
10
|
require('./chunk-KT6UAKBB.js');
|
|
@@ -13,7 +13,7 @@ require('./chunk-RXIUMVA5.js');
|
|
|
13
13
|
require('./chunk-ULD4JC3Q.js');
|
|
14
14
|
require('./chunk-7LXE4KHV.js');
|
|
15
15
|
require('./chunk-V72C4MCR.js');
|
|
16
|
-
require('./chunk-
|
|
16
|
+
require('./chunk-TIE3CPF7.js');
|
|
17
17
|
require('./chunk-NYKRCWBG.js');
|
|
18
18
|
require('./chunk-WR5F34OW.js');
|
|
19
19
|
require('./chunk-YVCX6Z75.js');
|
|
@@ -41,5 +41,5 @@ require('./chunk-Z4BLTVTB.js');
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
exports.ApprovalState =
|
|
44
|
+
exports.ApprovalState = _chunkQKS2F7VGjs.ApprovalState; exports.CANCEL_RATE = _chunkQKS2F7VGjs.CANCEL_RATE; exports.HARDFORK = _chunkQKS2F7VGjs.HARDFORK; exports.SPEED_UP_RATE = _chunkQKS2F7VGjs.SPEED_UP_RATE; exports.TransactionController = _chunkQKS2F7VGjs.TransactionController;
|
|
45
45
|
//# sourceMappingURL=TransactionController.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
HARDFORK,
|
|
5
5
|
SPEED_UP_RATE,
|
|
6
6
|
TransactionController
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-5JWPMHSZ.mjs";
|
|
8
8
|
import "./chunk-6DDVVUJC.mjs";
|
|
9
9
|
import "./chunk-3AVRGHUO.mjs";
|
|
10
10
|
import "./chunk-K4KOSAGM.mjs";
|
|
@@ -13,7 +13,7 @@ import "./chunk-5ZEJT5SN.mjs";
|
|
|
13
13
|
import "./chunk-6B5BEO3R.mjs";
|
|
14
14
|
import "./chunk-FRKQ3Z2L.mjs";
|
|
15
15
|
import "./chunk-5G6OHAXI.mjs";
|
|
16
|
-
import "./chunk-
|
|
16
|
+
import "./chunk-SMC5Q6ZH.mjs";
|
|
17
17
|
import "./chunk-VEVVBHP3.mjs";
|
|
18
18
|
import "./chunk-Z4GV3YQQ.mjs";
|
|
19
19
|
import "./chunk-FG74Z3F5.mjs";
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
import {
|
|
27
27
|
addInitialHistorySnapshot,
|
|
28
28
|
updateTransactionHistory
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-SMC5Q6ZH.mjs";
|
|
30
30
|
import {
|
|
31
31
|
OptimismLayer1GasFeeFlow
|
|
32
32
|
} from "./chunk-VEVVBHP3.mjs";
|
|
@@ -2563,4 +2563,4 @@ export {
|
|
|
2563
2563
|
ApprovalState,
|
|
2564
2564
|
TransactionController
|
|
2565
2565
|
};
|
|
2566
|
-
//# sourceMappingURL=chunk-
|
|
2566
|
+
//# sourceMappingURL=chunk-5JWPMHSZ.mjs.map
|
|
@@ -26,7 +26,7 @@ var _chunkV72C4MCRjs = require('./chunk-V72C4MCR.js');
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
var
|
|
29
|
+
var _chunkTIE3CPF7js = require('./chunk-TIE3CPF7.js');
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
var _chunkNYKRCWBGjs = require('./chunk-NYKRCWBG.js');
|
|
@@ -514,7 +514,7 @@ var TransactionController = class extends _basecontroller.BaseController {
|
|
|
514
514
|
addedTransactionMeta.sendFlowHistory = sendFlowHistory ?? [];
|
|
515
515
|
}
|
|
516
516
|
if (!this.isHistoryDisabled) {
|
|
517
|
-
addedTransactionMeta =
|
|
517
|
+
addedTransactionMeta = _chunkTIE3CPF7js.addInitialHistorySnapshot.call(void 0, addedTransactionMeta);
|
|
518
518
|
}
|
|
519
519
|
addedTransactionMeta = _chunkQH2H4W3Njs.updateSwapsTransaction.call(void 0,
|
|
520
520
|
addedTransactionMeta,
|
|
@@ -1998,7 +1998,7 @@ var TransactionController = class extends _basecontroller.BaseController {
|
|
|
1998
1998
|
confirmedTxs,
|
|
1999
1999
|
pendingTxs
|
|
2000
2000
|
);
|
|
2001
|
-
const newTransactionMeta = (transactionMeta.history ?? []).length === 0 && !this.isHistoryDisabled ?
|
|
2001
|
+
const newTransactionMeta = (transactionMeta.history ?? []).length === 0 && !this.isHistoryDisabled ? _chunkTIE3CPF7js.addInitialHistorySnapshot.call(void 0, transactionMeta) : transactionMeta;
|
|
2002
2002
|
this.update((state) => {
|
|
2003
2003
|
state.transactions = this.trimTransactionsForState([
|
|
2004
2004
|
...state.transactions,
|
|
@@ -2406,7 +2406,7 @@ updateTransactionInternal_fn = function({
|
|
|
2406
2406
|
updatedTransactionParams = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _checkIfTransactionParamsUpdated, checkIfTransactionParamsUpdated_fn).call(this, transactionMeta2);
|
|
2407
2407
|
const shouldSkipHistory = this.isHistoryDisabled || skipHistory;
|
|
2408
2408
|
if (!shouldSkipHistory) {
|
|
2409
|
-
transactionMeta2 =
|
|
2409
|
+
transactionMeta2 = _chunkTIE3CPF7js.updateTransactionHistory.call(void 0,
|
|
2410
2410
|
transactionMeta2,
|
|
2411
2411
|
note ?? "Transaction updated"
|
|
2412
2412
|
);
|
|
@@ -2563,4 +2563,4 @@ getSelectedAccount_fn = function() {
|
|
|
2563
2563
|
|
|
2564
2564
|
|
|
2565
2565
|
exports.HARDFORK = HARDFORK; exports.CANCEL_RATE = CANCEL_RATE; exports.SPEED_UP_RATE = SPEED_UP_RATE; exports.ApprovalState = ApprovalState; exports.TransactionController = TransactionController;
|
|
2566
|
-
//# sourceMappingURL=chunk-
|
|
2566
|
+
//# sourceMappingURL=chunk-QKS2F7VG.js.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// src/utils/history.ts
|
|
2
|
+
import jsonDiffer from "fast-json-patch";
|
|
3
|
+
import { cloneDeep, merge } from "lodash";
|
|
4
|
+
var MAX_TRANSACTION_HISTORY_LENGTH = 100;
|
|
5
|
+
var DISPLAYED_TRANSACTION_HISTORY_PATHS = [
|
|
6
|
+
"/status",
|
|
7
|
+
"/txParams/gasPrice",
|
|
8
|
+
"/txParams/gas",
|
|
9
|
+
"/estimatedBaseFee",
|
|
10
|
+
"/blockTimestamp"
|
|
11
|
+
];
|
|
12
|
+
function addInitialHistorySnapshot(transactionMeta) {
|
|
13
|
+
const snapshot = snapshotFromTransactionMeta(transactionMeta);
|
|
14
|
+
return merge({}, transactionMeta, { history: [snapshot] });
|
|
15
|
+
}
|
|
16
|
+
function updateTransactionHistory(transactionMeta, note) {
|
|
17
|
+
if (!transactionMeta.history) {
|
|
18
|
+
return transactionMeta;
|
|
19
|
+
}
|
|
20
|
+
const currentState = snapshotFromTransactionMeta(transactionMeta);
|
|
21
|
+
const previousState = replayHistory(transactionMeta.history);
|
|
22
|
+
const newHistoryEntry = generateHistoryEntry(
|
|
23
|
+
previousState,
|
|
24
|
+
currentState,
|
|
25
|
+
note
|
|
26
|
+
);
|
|
27
|
+
if (newHistoryEntry.length === 0) {
|
|
28
|
+
return transactionMeta;
|
|
29
|
+
}
|
|
30
|
+
let updatedHistory = [
|
|
31
|
+
...transactionMeta.history,
|
|
32
|
+
newHistoryEntry
|
|
33
|
+
];
|
|
34
|
+
if (updatedHistory.length > MAX_TRANSACTION_HISTORY_LENGTH) {
|
|
35
|
+
updatedHistory = compressTransactionHistory(updatedHistory);
|
|
36
|
+
}
|
|
37
|
+
return merge({}, transactionMeta, {
|
|
38
|
+
history: updatedHistory
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function compressTransactionHistory(transactionHistory) {
|
|
42
|
+
const initialEntry = transactionHistory[0];
|
|
43
|
+
const historyEntries = transactionHistory.slice(
|
|
44
|
+
1
|
|
45
|
+
);
|
|
46
|
+
const firstNonDisplayedEntryIndex = historyEntries.findIndex(
|
|
47
|
+
(historyEntry) => {
|
|
48
|
+
return !historyEntry.some(
|
|
49
|
+
({ path }) => DISPLAYED_TRANSACTION_HISTORY_PATHS.includes(path)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
if (firstNonDisplayedEntryIndex === -1) {
|
|
54
|
+
return transactionHistory;
|
|
55
|
+
}
|
|
56
|
+
const mergeTargetEntryIndex = (
|
|
57
|
+
// Merge with previous entry if there is no next entry.
|
|
58
|
+
// We default to merging with next because the next entry might also be non-displayed, so it
|
|
59
|
+
// might be removed in a future trim, saving more space.
|
|
60
|
+
firstNonDisplayedEntryIndex === historyEntries.length - 1 ? firstNonDisplayedEntryIndex - 1 : firstNonDisplayedEntryIndex + 1
|
|
61
|
+
);
|
|
62
|
+
const firstIndexToMerge = Math.min(
|
|
63
|
+
firstNonDisplayedEntryIndex,
|
|
64
|
+
mergeTargetEntryIndex
|
|
65
|
+
);
|
|
66
|
+
const firstEntryToMerge = historyEntries[firstIndexToMerge];
|
|
67
|
+
const secondEntryToMerge = historyEntries[firstIndexToMerge + 1];
|
|
68
|
+
const beforeMergeState = replayHistory([
|
|
69
|
+
initialEntry,
|
|
70
|
+
...historyEntries.slice(0, firstIndexToMerge)
|
|
71
|
+
]);
|
|
72
|
+
const afterMergeState = replayHistory([
|
|
73
|
+
beforeMergeState,
|
|
74
|
+
firstEntryToMerge,
|
|
75
|
+
secondEntryToMerge
|
|
76
|
+
]);
|
|
77
|
+
const mergedHistoryEntry = generateHistoryEntry(
|
|
78
|
+
beforeMergeState,
|
|
79
|
+
afterMergeState,
|
|
80
|
+
`${String(firstEntryToMerge[0].note)}, ${String(
|
|
81
|
+
secondEntryToMerge[0].note
|
|
82
|
+
)}`
|
|
83
|
+
);
|
|
84
|
+
historyEntries.splice(firstIndexToMerge, 2, mergedHistoryEntry);
|
|
85
|
+
return [initialEntry, ...historyEntries];
|
|
86
|
+
}
|
|
87
|
+
function generateHistoryEntry(previousState, currentState, note) {
|
|
88
|
+
const historyOperationsEntry = jsonDiffer.compare(
|
|
89
|
+
previousState,
|
|
90
|
+
currentState
|
|
91
|
+
);
|
|
92
|
+
if (historyOperationsEntry[0]) {
|
|
93
|
+
if (note) {
|
|
94
|
+
historyOperationsEntry[0].note = note;
|
|
95
|
+
}
|
|
96
|
+
historyOperationsEntry[0].timestamp = Date.now();
|
|
97
|
+
}
|
|
98
|
+
return historyOperationsEntry;
|
|
99
|
+
}
|
|
100
|
+
function replayHistory(transactionHistory) {
|
|
101
|
+
const shortHistory = cloneDeep(transactionHistory);
|
|
102
|
+
return shortHistory.reduce(
|
|
103
|
+
// TODO: Replace `any` with type
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
+
(val, entry) => jsonDiffer.applyPatch(val, entry).newDocument
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
function snapshotFromTransactionMeta(transactionMeta) {
|
|
109
|
+
const snapshot = { ...transactionMeta };
|
|
110
|
+
delete snapshot.history;
|
|
111
|
+
return cloneDeep(snapshot);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export {
|
|
115
|
+
MAX_TRANSACTION_HISTORY_LENGTH,
|
|
116
|
+
DISPLAYED_TRANSACTION_HISTORY_PATHS,
|
|
117
|
+
addInitialHistorySnapshot,
|
|
118
|
+
updateTransactionHistory
|
|
119
|
+
};
|
|
120
|
+
//# sourceMappingURL=chunk-SMC5Q6ZH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/history.ts"],"sourcesContent":["import jsonDiffer from 'fast-json-patch';\nimport { cloneDeep, merge } from 'lodash';\n\nimport type {\n TransactionHistory,\n TransactionHistoryEntry,\n TransactionMeta,\n} from '../types';\n\n/**\n * The maximum allowed length of the `transaction.history` property.\n */\nexport const MAX_TRANSACTION_HISTORY_LENGTH = 100;\n\n/**\n * A list of trarnsaction history paths that may be used for display. These entries will not be\n * compressed.\n */\nexport const DISPLAYED_TRANSACTION_HISTORY_PATHS = [\n '/status',\n '/txParams/gasPrice',\n '/txParams/gas',\n '/estimatedBaseFee',\n '/blockTimestamp',\n];\n\n/**\n * Build a new version of the provided transaction with an initial history\n * entry, which is just a snapshot of the transaction.\n *\n * @param transactionMeta - TransactionMeta to add initial history snapshot to.\n * @returns A copy of `transactionMeta` with a new `history` property.\n */\nexport function addInitialHistorySnapshot(\n transactionMeta: TransactionMeta,\n): TransactionMeta {\n const snapshot = snapshotFromTransactionMeta(transactionMeta);\n return merge({}, transactionMeta, { history: [snapshot] });\n}\n\n/**\n * Builds a new version of the transaction with a new history entry if\n * it has a `history` property, or just returns the transaction.\n *\n * @param transactionMeta - TransactionMeta to add history entry to.\n * @param note - Note to add to history entry.\n * @returns A copy of `transactionMeta` with a new `history` entry if it has an\n * existing non-empty `history` array.\n */\nexport function updateTransactionHistory(\n transactionMeta: TransactionMeta,\n note: string,\n): TransactionMeta {\n if (!transactionMeta.history) {\n return transactionMeta;\n }\n\n const currentState = snapshotFromTransactionMeta(transactionMeta);\n const previousState = replayHistory(transactionMeta.history);\n const newHistoryEntry = generateHistoryEntry(\n previousState,\n currentState,\n note,\n );\n\n if (newHistoryEntry.length === 0) {\n return transactionMeta;\n }\n\n // Casts required here because this list has two separate types of entries:\n // TransactionMeta and TransactionHistoryEntry. The only TransactionMeta is the first\n // entry, but TypeScript loses that type information when `slice` is called for some reason.\n let updatedHistory = [\n ...transactionMeta.history,\n newHistoryEntry,\n ] as TransactionHistory;\n\n if (updatedHistory.length > MAX_TRANSACTION_HISTORY_LENGTH) {\n updatedHistory = compressTransactionHistory(updatedHistory);\n }\n\n return merge({}, transactionMeta, {\n history: updatedHistory,\n });\n}\n\n/**\n * Compress the transaction history, if it is possible to do so without compressing entries used\n * for display. History entries are merged together to make room for a single new entry.\n *\n * @param transactionHistory - The transaction history to compress.\n * @returns A compressed transaction history.\n */\nfunction compressTransactionHistory(\n transactionHistory: TransactionHistory,\n): TransactionHistory {\n const initialEntry = transactionHistory[0];\n // Casts required here because this list has two separate types of entries:\n // TransactionMeta and TransactionHistoryEntry. The only TransactionMeta is the first\n // entry, but TypeScript loses that type information when `slice` is called for some reason.\n const historyEntries = transactionHistory.slice(\n 1,\n ) as TransactionHistoryEntry[];\n\n const firstNonDisplayedEntryIndex = historyEntries.findIndex(\n (historyEntry) => {\n return !historyEntry.some(({ path }) =>\n DISPLAYED_TRANSACTION_HISTORY_PATHS.includes(path),\n );\n },\n );\n\n // If no non-displayed entry is found, let history exceed max size.\n // TODO: Move data used for display to another property, so that we can more reliably limit\n // history size or remove it altogether.\n if (firstNonDisplayedEntryIndex === -1) {\n return transactionHistory;\n }\n\n // If a non-displayed entry is found that we can remove, merge it with another entry.\n // The entry we're merging with might be a \"displayed\" entry, but that's OK, merging more changes\n // in does not break our display logic.\n const mergeTargetEntryIndex =\n // Merge with previous entry if there is no next entry.\n // We default to merging with next because the next entry might also be non-displayed, so it\n // might be removed in a future trim, saving more space.\n firstNonDisplayedEntryIndex === historyEntries.length - 1\n ? firstNonDisplayedEntryIndex - 1\n : firstNonDisplayedEntryIndex + 1;\n const firstIndexToMerge = Math.min(\n firstNonDisplayedEntryIndex,\n mergeTargetEntryIndex,\n );\n const firstEntryToMerge = historyEntries[firstIndexToMerge];\n const secondEntryToMerge = historyEntries[firstIndexToMerge + 1];\n\n const beforeMergeState = replayHistory([\n initialEntry,\n ...historyEntries.slice(0, firstIndexToMerge),\n ]);\n const afterMergeState = replayHistory([\n beforeMergeState,\n firstEntryToMerge,\n secondEntryToMerge,\n ]);\n const mergedHistoryEntry = generateHistoryEntry(\n beforeMergeState,\n afterMergeState,\n `${String(firstEntryToMerge[0].note)}, ${String(\n secondEntryToMerge[0].note,\n )}`,\n );\n\n historyEntries.splice(firstIndexToMerge, 2, mergedHistoryEntry);\n return [initialEntry, ...historyEntries];\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 // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/utils/history.ts
|
|
2
|
+
var _fastjsonpatch = require('fast-json-patch'); var _fastjsonpatch2 = _interopRequireDefault(_fastjsonpatch);
|
|
3
|
+
var _lodash = require('lodash');
|
|
4
|
+
var MAX_TRANSACTION_HISTORY_LENGTH = 100;
|
|
5
|
+
var DISPLAYED_TRANSACTION_HISTORY_PATHS = [
|
|
6
|
+
"/status",
|
|
7
|
+
"/txParams/gasPrice",
|
|
8
|
+
"/txParams/gas",
|
|
9
|
+
"/estimatedBaseFee",
|
|
10
|
+
"/blockTimestamp"
|
|
11
|
+
];
|
|
12
|
+
function addInitialHistorySnapshot(transactionMeta) {
|
|
13
|
+
const snapshot = snapshotFromTransactionMeta(transactionMeta);
|
|
14
|
+
return _lodash.merge.call(void 0, {}, transactionMeta, { history: [snapshot] });
|
|
15
|
+
}
|
|
16
|
+
function updateTransactionHistory(transactionMeta, note) {
|
|
17
|
+
if (!transactionMeta.history) {
|
|
18
|
+
return transactionMeta;
|
|
19
|
+
}
|
|
20
|
+
const currentState = snapshotFromTransactionMeta(transactionMeta);
|
|
21
|
+
const previousState = replayHistory(transactionMeta.history);
|
|
22
|
+
const newHistoryEntry = generateHistoryEntry(
|
|
23
|
+
previousState,
|
|
24
|
+
currentState,
|
|
25
|
+
note
|
|
26
|
+
);
|
|
27
|
+
if (newHistoryEntry.length === 0) {
|
|
28
|
+
return transactionMeta;
|
|
29
|
+
}
|
|
30
|
+
let updatedHistory = [
|
|
31
|
+
...transactionMeta.history,
|
|
32
|
+
newHistoryEntry
|
|
33
|
+
];
|
|
34
|
+
if (updatedHistory.length > MAX_TRANSACTION_HISTORY_LENGTH) {
|
|
35
|
+
updatedHistory = compressTransactionHistory(updatedHistory);
|
|
36
|
+
}
|
|
37
|
+
return _lodash.merge.call(void 0, {}, transactionMeta, {
|
|
38
|
+
history: updatedHistory
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function compressTransactionHistory(transactionHistory) {
|
|
42
|
+
const initialEntry = transactionHistory[0];
|
|
43
|
+
const historyEntries = transactionHistory.slice(
|
|
44
|
+
1
|
|
45
|
+
);
|
|
46
|
+
const firstNonDisplayedEntryIndex = historyEntries.findIndex(
|
|
47
|
+
(historyEntry) => {
|
|
48
|
+
return !historyEntry.some(
|
|
49
|
+
({ path }) => DISPLAYED_TRANSACTION_HISTORY_PATHS.includes(path)
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
if (firstNonDisplayedEntryIndex === -1) {
|
|
54
|
+
return transactionHistory;
|
|
55
|
+
}
|
|
56
|
+
const mergeTargetEntryIndex = (
|
|
57
|
+
// Merge with previous entry if there is no next entry.
|
|
58
|
+
// We default to merging with next because the next entry might also be non-displayed, so it
|
|
59
|
+
// might be removed in a future trim, saving more space.
|
|
60
|
+
firstNonDisplayedEntryIndex === historyEntries.length - 1 ? firstNonDisplayedEntryIndex - 1 : firstNonDisplayedEntryIndex + 1
|
|
61
|
+
);
|
|
62
|
+
const firstIndexToMerge = Math.min(
|
|
63
|
+
firstNonDisplayedEntryIndex,
|
|
64
|
+
mergeTargetEntryIndex
|
|
65
|
+
);
|
|
66
|
+
const firstEntryToMerge = historyEntries[firstIndexToMerge];
|
|
67
|
+
const secondEntryToMerge = historyEntries[firstIndexToMerge + 1];
|
|
68
|
+
const beforeMergeState = replayHistory([
|
|
69
|
+
initialEntry,
|
|
70
|
+
...historyEntries.slice(0, firstIndexToMerge)
|
|
71
|
+
]);
|
|
72
|
+
const afterMergeState = replayHistory([
|
|
73
|
+
beforeMergeState,
|
|
74
|
+
firstEntryToMerge,
|
|
75
|
+
secondEntryToMerge
|
|
76
|
+
]);
|
|
77
|
+
const mergedHistoryEntry = generateHistoryEntry(
|
|
78
|
+
beforeMergeState,
|
|
79
|
+
afterMergeState,
|
|
80
|
+
`${String(firstEntryToMerge[0].note)}, ${String(
|
|
81
|
+
secondEntryToMerge[0].note
|
|
82
|
+
)}`
|
|
83
|
+
);
|
|
84
|
+
historyEntries.splice(firstIndexToMerge, 2, mergedHistoryEntry);
|
|
85
|
+
return [initialEntry, ...historyEntries];
|
|
86
|
+
}
|
|
87
|
+
function generateHistoryEntry(previousState, currentState, note) {
|
|
88
|
+
const historyOperationsEntry = _fastjsonpatch2.default.compare(
|
|
89
|
+
previousState,
|
|
90
|
+
currentState
|
|
91
|
+
);
|
|
92
|
+
if (historyOperationsEntry[0]) {
|
|
93
|
+
if (note) {
|
|
94
|
+
historyOperationsEntry[0].note = note;
|
|
95
|
+
}
|
|
96
|
+
historyOperationsEntry[0].timestamp = Date.now();
|
|
97
|
+
}
|
|
98
|
+
return historyOperationsEntry;
|
|
99
|
+
}
|
|
100
|
+
function replayHistory(transactionHistory) {
|
|
101
|
+
const shortHistory = _lodash.cloneDeep.call(void 0, transactionHistory);
|
|
102
|
+
return shortHistory.reduce(
|
|
103
|
+
// TODO: Replace `any` with type
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
+
(val, entry) => _fastjsonpatch2.default.applyPatch(val, entry).newDocument
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
function snapshotFromTransactionMeta(transactionMeta) {
|
|
109
|
+
const snapshot = { ...transactionMeta };
|
|
110
|
+
delete snapshot.history;
|
|
111
|
+
return _lodash.cloneDeep.call(void 0, snapshot);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
exports.MAX_TRANSACTION_HISTORY_LENGTH = MAX_TRANSACTION_HISTORY_LENGTH; exports.DISPLAYED_TRANSACTION_HISTORY_PATHS = DISPLAYED_TRANSACTION_HISTORY_PATHS; exports.addInitialHistorySnapshot = addInitialHistorySnapshot; exports.updateTransactionHistory = updateTransactionHistory;
|
|
120
|
+
//# sourceMappingURL=chunk-TIE3CPF7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/history.ts"],"names":[],"mappings":"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","sourcesContent":["import jsonDiffer from 'fast-json-patch';\nimport { cloneDeep, merge } from 'lodash';\n\nimport type {\n TransactionHistory,\n TransactionHistoryEntry,\n TransactionMeta,\n} from '../types';\n\n/**\n * The maximum allowed length of the `transaction.history` property.\n */\nexport const MAX_TRANSACTION_HISTORY_LENGTH = 100;\n\n/**\n * A list of trarnsaction history paths that may be used for display. These entries will not be\n * compressed.\n */\nexport const DISPLAYED_TRANSACTION_HISTORY_PATHS = [\n '/status',\n '/txParams/gasPrice',\n '/txParams/gas',\n '/estimatedBaseFee',\n '/blockTimestamp',\n];\n\n/**\n * Build a new version of the provided transaction with an initial history\n * entry, which is just a snapshot of the transaction.\n *\n * @param transactionMeta - TransactionMeta to add initial history snapshot to.\n * @returns A copy of `transactionMeta` with a new `history` property.\n */\nexport function addInitialHistorySnapshot(\n transactionMeta: TransactionMeta,\n): TransactionMeta {\n const snapshot = snapshotFromTransactionMeta(transactionMeta);\n return merge({}, transactionMeta, { history: [snapshot] });\n}\n\n/**\n * Builds a new version of the transaction with a new history entry if\n * it has a `history` property, or just returns the transaction.\n *\n * @param transactionMeta - TransactionMeta to add history entry to.\n * @param note - Note to add to history entry.\n * @returns A copy of `transactionMeta` with a new `history` entry if it has an\n * existing non-empty `history` array.\n */\nexport function updateTransactionHistory(\n transactionMeta: TransactionMeta,\n note: string,\n): TransactionMeta {\n if (!transactionMeta.history) {\n return transactionMeta;\n }\n\n const currentState = snapshotFromTransactionMeta(transactionMeta);\n const previousState = replayHistory(transactionMeta.history);\n const newHistoryEntry = generateHistoryEntry(\n previousState,\n currentState,\n note,\n );\n\n if (newHistoryEntry.length === 0) {\n return transactionMeta;\n }\n\n // Casts required here because this list has two separate types of entries:\n // TransactionMeta and TransactionHistoryEntry. The only TransactionMeta is the first\n // entry, but TypeScript loses that type information when `slice` is called for some reason.\n let updatedHistory = [\n ...transactionMeta.history,\n newHistoryEntry,\n ] as TransactionHistory;\n\n if (updatedHistory.length > MAX_TRANSACTION_HISTORY_LENGTH) {\n updatedHistory = compressTransactionHistory(updatedHistory);\n }\n\n return merge({}, transactionMeta, {\n history: updatedHistory,\n });\n}\n\n/**\n * Compress the transaction history, if it is possible to do so without compressing entries used\n * for display. History entries are merged together to make room for a single new entry.\n *\n * @param transactionHistory - The transaction history to compress.\n * @returns A compressed transaction history.\n */\nfunction compressTransactionHistory(\n transactionHistory: TransactionHistory,\n): TransactionHistory {\n const initialEntry = transactionHistory[0];\n // Casts required here because this list has two separate types of entries:\n // TransactionMeta and TransactionHistoryEntry. The only TransactionMeta is the first\n // entry, but TypeScript loses that type information when `slice` is called for some reason.\n const historyEntries = transactionHistory.slice(\n 1,\n ) as TransactionHistoryEntry[];\n\n const firstNonDisplayedEntryIndex = historyEntries.findIndex(\n (historyEntry) => {\n return !historyEntry.some(({ path }) =>\n DISPLAYED_TRANSACTION_HISTORY_PATHS.includes(path),\n );\n },\n );\n\n // If no non-displayed entry is found, let history exceed max size.\n // TODO: Move data used for display to another property, so that we can more reliably limit\n // history size or remove it altogether.\n if (firstNonDisplayedEntryIndex === -1) {\n return transactionHistory;\n }\n\n // If a non-displayed entry is found that we can remove, merge it with another entry.\n // The entry we're merging with might be a \"displayed\" entry, but that's OK, merging more changes\n // in does not break our display logic.\n const mergeTargetEntryIndex =\n // Merge with previous entry if there is no next entry.\n // We default to merging with next because the next entry might also be non-displayed, so it\n // might be removed in a future trim, saving more space.\n firstNonDisplayedEntryIndex === historyEntries.length - 1\n ? firstNonDisplayedEntryIndex - 1\n : firstNonDisplayedEntryIndex + 1;\n const firstIndexToMerge = Math.min(\n firstNonDisplayedEntryIndex,\n mergeTargetEntryIndex,\n );\n const firstEntryToMerge = historyEntries[firstIndexToMerge];\n const secondEntryToMerge = historyEntries[firstIndexToMerge + 1];\n\n const beforeMergeState = replayHistory([\n initialEntry,\n ...historyEntries.slice(0, firstIndexToMerge),\n ]);\n const afterMergeState = replayHistory([\n beforeMergeState,\n firstEntryToMerge,\n secondEntryToMerge,\n ]);\n const mergedHistoryEntry = generateHistoryEntry(\n beforeMergeState,\n afterMergeState,\n `${String(firstEntryToMerge[0].note)}, ${String(\n secondEntryToMerge[0].note,\n )}`,\n );\n\n historyEntries.splice(firstIndexToMerge, 2, mergedHistoryEntry);\n return [initialEntry, ...historyEntries];\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 // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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 // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\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"]}
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkQKS2F7VGjs = require('./chunk-QKS2F7VG.js');
|
|
6
6
|
require('./chunk-PRUNMTRD.js');
|
|
7
7
|
require('./chunk-NNCUD3QF.js');
|
|
8
8
|
require('./chunk-KT6UAKBB.js');
|
|
@@ -13,7 +13,10 @@ require('./chunk-RXIUMVA5.js');
|
|
|
13
13
|
require('./chunk-ULD4JC3Q.js');
|
|
14
14
|
require('./chunk-7LXE4KHV.js');
|
|
15
15
|
require('./chunk-V72C4MCR.js');
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
var _chunkTIE3CPF7js = require('./chunk-TIE3CPF7.js');
|
|
17
20
|
require('./chunk-NYKRCWBG.js');
|
|
18
21
|
require('./chunk-WR5F34OW.js');
|
|
19
22
|
require('./chunk-YVCX6Z75.js');
|
|
@@ -67,5 +70,7 @@ require('./chunk-Z4BLTVTB.js');
|
|
|
67
70
|
|
|
68
71
|
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
exports.CANCEL_RATE = _chunkQKS2F7VGjs.CANCEL_RATE; exports.DISPLAYED_TRANSACTION_HISTORY_PATHS = _chunkTIE3CPF7js.DISPLAYED_TRANSACTION_HISTORY_PATHS; exports.GasFeeEstimateLevel = _chunkAYTU4HU5js.GasFeeEstimateLevel; exports.GasFeeEstimateType = _chunkAYTU4HU5js.GasFeeEstimateType; exports.HARDFORK = _chunkQKS2F7VGjs.HARDFORK; exports.MAX_TRANSACTION_HISTORY_LENGTH = _chunkTIE3CPF7js.MAX_TRANSACTION_HISTORY_LENGTH; exports.SimulationErrorCode = _chunkAYTU4HU5js.SimulationErrorCode; exports.SimulationTokenStandard = _chunkAYTU4HU5js.SimulationTokenStandard; exports.TransactionController = _chunkQKS2F7VGjs.TransactionController; exports.TransactionEnvelopeType = _chunkAYTU4HU5js.TransactionEnvelopeType; exports.TransactionStatus = _chunkAYTU4HU5js.TransactionStatus; exports.TransactionType = _chunkAYTU4HU5js.TransactionType; exports.UserFeeLevel = _chunkAYTU4HU5js.UserFeeLevel; exports.WalletDevice = _chunkAYTU4HU5js.WalletDevice; exports.determineTransactionType = _chunkSD6CWFDFjs.determineTransactionType; exports.isEIP1559Transaction = _chunkOZ6UB42Cjs.isEIP1559Transaction; exports.mergeGasFeeEstimates = _chunk76FONEDAjs.mergeGasFeeEstimates; exports.normalizeTransactionParams = _chunkOZ6UB42Cjs.normalizeTransactionParams;
|
|
71
76
|
//# sourceMappingURL=index.js.map
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
CANCEL_RATE,
|
|
3
3
|
HARDFORK,
|
|
4
4
|
TransactionController
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-5JWPMHSZ.mjs";
|
|
6
6
|
import "./chunk-6DDVVUJC.mjs";
|
|
7
7
|
import "./chunk-3AVRGHUO.mjs";
|
|
8
8
|
import "./chunk-K4KOSAGM.mjs";
|
|
@@ -13,7 +13,10 @@ import "./chunk-5ZEJT5SN.mjs";
|
|
|
13
13
|
import "./chunk-6B5BEO3R.mjs";
|
|
14
14
|
import "./chunk-FRKQ3Z2L.mjs";
|
|
15
15
|
import "./chunk-5G6OHAXI.mjs";
|
|
16
|
-
import
|
|
16
|
+
import {
|
|
17
|
+
DISPLAYED_TRANSACTION_HISTORY_PATHS,
|
|
18
|
+
MAX_TRANSACTION_HISTORY_LENGTH
|
|
19
|
+
} from "./chunk-SMC5Q6ZH.mjs";
|
|
17
20
|
import "./chunk-VEVVBHP3.mjs";
|
|
18
21
|
import "./chunk-Z4GV3YQQ.mjs";
|
|
19
22
|
import "./chunk-FG74Z3F5.mjs";
|
|
@@ -52,9 +55,11 @@ import {
|
|
|
52
55
|
import "./chunk-XUI43LEZ.mjs";
|
|
53
56
|
export {
|
|
54
57
|
CANCEL_RATE,
|
|
58
|
+
DISPLAYED_TRANSACTION_HISTORY_PATHS,
|
|
55
59
|
GasFeeEstimateLevel,
|
|
56
60
|
GasFeeEstimateType,
|
|
57
61
|
HARDFORK,
|
|
62
|
+
MAX_TRANSACTION_HISTORY_LENGTH,
|
|
58
63
|
SimulationErrorCode,
|
|
59
64
|
SimulationTokenStandard,
|
|
60
65
|
TransactionController,
|