@metamask/transaction-controller 37.0.0 → 37.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 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
+ ## [37.1.0]
11
+
12
+ ### Added
13
+
14
+ - Populate `submitHistory` in state when submitting transactions to network ([#4706](https://github.com/MetaMask/core/pull/4706))
15
+ - Export `CHAIN_IDS`, `ETHERSCAN_SUPPORTED_NETWORKS` and `SPEED_UP_RATE` constants ([#4706](https://github.com/MetaMask/core/pull/4706))
16
+
17
+ ### Changed
18
+
19
+ - Make `getPermittedAccounts` constructor callback optional ([#4706](https://github.com/MetaMask/core/pull/4706))
20
+ - Bump accounts related packages ([#4713](https://github.com/MetaMask/core/pull/4713)), ([#4728](https://github.com/MetaMask/core/pull/4728))
21
+ - Those packages are now built slightly differently and are part of the [accounts monorepo](https://github.com/MetaMask/accounts).
22
+ - Bump `@metamask/keyring-api` from `^8.1.0` to `^8.1.4`
23
+
10
24
  ## [37.0.0]
11
25
 
12
26
  ### Changed
@@ -1023,7 +1037,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1023
1037
 
1024
1038
  All changes listed after this point were applied to this package following the monorepo conversion.
1025
1039
 
1026
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@37.0.0...HEAD
1040
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@37.1.0...HEAD
1041
+ [37.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@37.0.0...@metamask/transaction-controller@37.1.0
1027
1042
  [37.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@36.1.0...@metamask/transaction-controller@37.0.0
1028
1043
  [36.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@36.0.0...@metamask/transaction-controller@36.1.0
1029
1044
  [36.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@35.2.0...@metamask/transaction-controller@36.0.0
@@ -13,7 +13,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _TransactionController_instances, _TransactionController_internalEvents, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_trace, _TransactionController_transactionHistoryLimit, _TransactionController_isSimulationEnabled, _TransactionController_testGasFeeFlows, _TransactionController_multichainTrackingHelper, _TransactionController_retryTransaction, _TransactionController_createNonceTracker, _TransactionController_createIncomingTransactionHelper, _TransactionController_createPendingTransactionTracker, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopAllTracking, _TransactionController_removeIncomingTransactionHelperListeners, _TransactionController_addIncomingTransactionHelperListeners, _TransactionController_removePendingTransactionTrackerListeners, _TransactionController_addPendingTransactionTrackerListeners, _TransactionController_getNonceTrackerPendingTransactions, _TransactionController_getGasFeeFlows, _TransactionController_getLayer1GasFeeFlows, _TransactionController_updateTransactionInternal, _TransactionController_checkIfTransactionParamsUpdated, _TransactionController_onTransactionParamsUpdated, _TransactionController_updateSimulationData, _TransactionController_onGasFeePollerTransactionUpdate, _TransactionController_getNetworkClientId, _TransactionController_getGlobalNetworkClientId, _TransactionController_getGlobalChainId, _TransactionController_isCustomNetwork, _TransactionController_getSelectedAccount;
16
+ var _TransactionController_instances, _TransactionController_internalEvents, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_trace, _TransactionController_transactionHistoryLimit, _TransactionController_isSimulationEnabled, _TransactionController_testGasFeeFlows, _TransactionController_multichainTrackingHelper, _TransactionController_retryTransaction, _TransactionController_createNonceTracker, _TransactionController_createIncomingTransactionHelper, _TransactionController_createPendingTransactionTracker, _TransactionController_checkForPendingTransactionAndStartPolling, _TransactionController_stopAllTracking, _TransactionController_removeIncomingTransactionHelperListeners, _TransactionController_addIncomingTransactionHelperListeners, _TransactionController_removePendingTransactionTrackerListeners, _TransactionController_addPendingTransactionTrackerListeners, _TransactionController_getNonceTrackerPendingTransactions, _TransactionController_getGasFeeFlows, _TransactionController_getLayer1GasFeeFlows, _TransactionController_updateTransactionInternal, _TransactionController_checkIfTransactionParamsUpdated, _TransactionController_onTransactionParamsUpdated, _TransactionController_updateSimulationData, _TransactionController_onGasFeePollerTransactionUpdate, _TransactionController_getNetworkClientId, _TransactionController_getGlobalNetworkClientId, _TransactionController_getGlobalChainId, _TransactionController_isCustomNetwork, _TransactionController_getSelectedAccount, _TransactionController_updateSubmitHistory;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.TransactionController = exports.ApprovalState = exports.SPEED_UP_RATE = exports.CANCEL_RATE = exports.HARDFORK = void 0;
19
19
  const common_1 = require("@ethereumjs/common");
@@ -73,8 +73,13 @@ const metadata = {
73
73
  persist: true,
74
74
  anonymous: false,
75
75
  },
76
+ submitHistory: {
77
+ persist: true,
78
+ anonymous: false,
79
+ },
76
80
  };
77
81
  exports.HARDFORK = common_1.Hardfork.London;
82
+ const SUBMIT_HISTORY_LIMIT = 100;
78
83
  /**
79
84
  * Multiplier used to determine a transaction's increased gas fee during cancellation
80
85
  */
@@ -106,6 +111,7 @@ function getDefaultTransactionControllerState() {
106
111
  methodData: {},
107
112
  transactions: [],
108
113
  lastFetchedBlockNumbers: {},
114
+ submitHistory: [],
109
115
  };
110
116
  }
111
117
  /**
@@ -375,7 +381,7 @@ class TransactionController extends base_controller_1.BaseController {
375
381
  const networkClientId = requestNetworkClientId ?? __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getGlobalNetworkClientId).call(this);
376
382
  const isEIP1559Compatible = await this.getEIP1559Compatibility(networkClientId);
377
383
  (0, validation_1.validateTxParams)(txParams, isEIP1559Compatible);
378
- if (origin) {
384
+ if (origin && this.getPermittedAccounts) {
379
385
  await (0, validation_1.validateTransactionOrigin)(await this.getPermittedAccounts(origin), __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getSelectedAccount).call(this).address, txParams.from, origin);
380
386
  }
381
387
  const dappSuggestedGasFees = this.generateDappSuggestedGasFees(txParams, origin);
@@ -1300,7 +1306,10 @@ class TransactionController extends base_controller_1.BaseController {
1300
1306
  await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Publish', parentContext: traceContext }, async () => {
1301
1307
  ({ transactionHash: hash } = await this.publish(transactionMeta, rawTx));
1302
1308
  if (hash === undefined) {
1303
- hash = await this.publishTransaction(ethQuery, rawTx);
1309
+ hash = await this.publishTransaction(ethQuery, {
1310
+ ...transactionMeta,
1311
+ rawTx,
1312
+ });
1304
1313
  }
1305
1314
  });
1306
1315
  (0, logger_1.projectLogger)('Publish successful', hash);
@@ -1334,8 +1343,14 @@ class TransactionController extends base_controller_1.BaseController {
1334
1343
  cleanupTasks.forEach((task) => task());
1335
1344
  }
1336
1345
  }
1337
- async publishTransaction(ethQuery, rawTransaction) {
1338
- return await (0, controller_utils_1.query)(ethQuery, 'sendRawTransaction', [rawTransaction]);
1346
+ async publishTransaction(ethQuery, transactionMeta, { skipSubmitHistory } = {}) {
1347
+ const transactionHash = await (0, controller_utils_1.query)(ethQuery, 'sendRawTransaction', [
1348
+ transactionMeta.rawTx,
1349
+ ]);
1350
+ if (skipSubmitHistory !== true) {
1351
+ __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_updateSubmitHistory).call(this, transactionMeta, transactionHash);
1352
+ }
1353
+ return transactionHash;
1339
1354
  }
1340
1355
  /**
1341
1356
  * Cancels a transaction based on its ID by setting its status to "rejected"
@@ -1742,10 +1757,9 @@ class TransactionController extends base_controller_1.BaseController {
1742
1757
  (0, logger_1.projectLogger)('Error while updating post transaction balance', error);
1743
1758
  }
1744
1759
  }
1745
- async publishTransactionForRetry(ethQuery, rawTx, transactionMeta) {
1760
+ async publishTransactionForRetry(ethQuery, transactionMeta) {
1746
1761
  try {
1747
- const hash = await this.publishTransaction(ethQuery, rawTx);
1748
- return hash;
1762
+ return await this.publishTransaction(ethQuery, transactionMeta);
1749
1763
  }
1750
1764
  catch (error) {
1751
1765
  if (this.isTransactionAlreadyConfirmedError(error)) {
@@ -1809,12 +1823,10 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
1809
1823
  networkClientId: transactionMeta.networkClientId,
1810
1824
  chainId: transactionMeta.chainId,
1811
1825
  });
1812
- const hash = await this.publishTransactionForRetry(ethQuery, rawTx, transactionMeta);
1813
1826
  const newTransactionMeta = {
1814
1827
  ...transactionMetaWithRsv,
1815
1828
  actionId,
1816
1829
  estimatedBaseFee,
1817
- hash,
1818
1830
  id: (0, uuid_1.v1)(),
1819
1831
  originalGasEstimate: transactionMeta.txParams.gas,
1820
1832
  originalType: transactionMeta.type,
@@ -1823,6 +1835,11 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
1823
1835
  txParams: newTxParams,
1824
1836
  type: transactionType,
1825
1837
  };
1838
+ const hash = await this.publishTransactionForRetry(ethQuery, {
1839
+ ...newTransactionMeta,
1840
+ origin: label,
1841
+ });
1842
+ newTransactionMeta.hash = hash;
1826
1843
  this.addMetadata(newTransactionMeta);
1827
1844
  // speedUpTransaction has no approval request, so we assume the user has already approved the transaction
1828
1845
  this.messagingSystem.publish(`${controllerName}:transactionApproved`, {
@@ -1849,6 +1866,7 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
1849
1866
  blockTracker,
1850
1867
  getCurrentAccount: () => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getSelectedAccount).call(this),
1851
1868
  getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
1869
+ getLocalTransactions: () => this.state.transactions,
1852
1870
  getChainId: chainId ? () => chainId : this.getChainId.bind(this),
1853
1871
  isEnabled: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").isEnabled,
1854
1872
  queryEntireHistory: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").queryEntireHistory,
@@ -1870,7 +1888,9 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
1870
1888
  getGlobalLock: () => __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").acquireNonceLockForChainIdKey({
1871
1889
  chainId: getChainId(),
1872
1890
  }),
1873
- publishTransaction: this.publishTransaction.bind(this),
1891
+ publishTransaction: (_ethQuery, transactionMeta) => this.publishTransaction(_ethQuery, transactionMeta, {
1892
+ skipSubmitHistory: true,
1893
+ }),
1874
1894
  hooks: {
1875
1895
  beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
1876
1896
  beforePublish: this.beforePublish.bind(this),
@@ -2022,5 +2042,30 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
2022
2042
  return (this.messagingSystem.call(`NetworkController:getNetworkClientById`, networkClientId).configuration.type === network_controller_1.NetworkClientType.Custom);
2023
2043
  }, _TransactionController_getSelectedAccount = function _TransactionController_getSelectedAccount() {
2024
2044
  return this.messagingSystem.call('AccountsController:getSelectedAccount');
2045
+ }, _TransactionController_updateSubmitHistory = function _TransactionController_updateSubmitHistory(transactionMeta, hash) {
2046
+ const { chainId, networkClientId, origin, rawTx, txParams } = transactionMeta;
2047
+ const { networkConfigurationsByChainId } = this.getNetworkState();
2048
+ const networkConfiguration = networkConfigurationsByChainId[chainId];
2049
+ const endpoint = networkConfiguration?.rpcEndpoints.find((currentEndpoint) => currentEndpoint.networkClientId === networkClientId);
2050
+ const networkUrl = endpoint?.url;
2051
+ const networkType = endpoint?.name ?? networkClientId;
2052
+ const submitHistoryEntry = {
2053
+ chainId,
2054
+ hash,
2055
+ networkType,
2056
+ networkUrl,
2057
+ origin,
2058
+ rawTransaction: rawTx,
2059
+ time: Date.now(),
2060
+ transaction: txParams,
2061
+ };
2062
+ (0, logger_1.projectLogger)('Updating submit history', submitHistoryEntry);
2063
+ this.update((state) => {
2064
+ const { submitHistory } = state;
2065
+ if (submitHistory.length === SUBMIT_HISTORY_LIMIT) {
2066
+ submitHistory.pop();
2067
+ }
2068
+ submitHistory.unshift(submitHistoryEntry);
2069
+ });
2025
2070
  };
2026
2071
  //# sourceMappingURL=TransactionController.cjs.map