@metamask-previews/transaction-controller 45.0.0-preview-224dff25 → 45.0.0-preview-1adbaffc

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,6 +1,4 @@
1
1
  "use strict";
2
- /* istanbul ignore file */
3
- // FIXME - remove above ignore
4
2
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
5
3
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
6
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
@@ -239,7 +237,7 @@ class TransactionController extends base_controller_1.BaseController {
239
237
  hooks?.beforeCheckPendingTransaction ??
240
238
  /* istanbul ignore next */
241
239
  (() => true);
242
- this.beforePublish = hooks?.beforePublish ?? (() => Promise.resolve(true));
240
+ this.beforePublish = hooks?.beforePublish ?? (() => true);
243
241
  this.getAdditionalSignArguments =
244
242
  hooks?.getAdditionalSignArguments ?? (() => []);
245
243
  this.publish =
@@ -627,7 +625,6 @@ class TransactionController extends base_controller_1.BaseController {
627
625
  this.onTransactionStatusChange(updatedTransactionMeta);
628
626
  // Intentional given potential duration of process.
629
627
  this.updatePostBalance(updatedTransactionMeta).catch((error) => {
630
- /* istanbul ignore next */
631
628
  (0, logger_1.projectLogger)('Error while updating post balance', error);
632
629
  throw error;
633
630
  });
@@ -858,17 +855,15 @@ class TransactionController extends base_controller_1.BaseController {
858
855
  * @param options.errorMessage - The error message to be assigned in case transaction status update to failed.
859
856
  * @param options.hash - The new hash value to be assigned.
860
857
  * @param options.status - The new status value to be assigned.
861
- * @param options.gasLimit - The new gas limit value to be assigned
862
- * @param options.gasPrice - The new gas price value to be assigned
863
- * @param options.maxFeePerGas - The new max fee per gas value to be assigned
864
- * @param options.maxPriorityFeePerGas - The new max priority fee per gas value to be assigned
865
- * @param options.nonce - The new nonce value to be assigned
866
858
  */
867
- updateCustodialTransaction(transactionId, { errorMessage, hash, status, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce, }) {
859
+ updateCustodialTransaction(transactionId, { errorMessage, hash, status, }) {
868
860
  const transactionMeta = this.getTransaction(transactionId);
869
861
  if (!transactionMeta) {
870
862
  throw new Error(`Cannot update custodial transaction as no transaction metadata found`);
871
863
  }
864
+ if (!transactionMeta.custodyId) {
865
+ throw new Error('Transaction must be a custodian transaction');
866
+ }
872
867
  if (status &&
873
868
  ![
874
869
  types_1.TransactionStatus.submitted,
@@ -884,22 +879,6 @@ class TransactionController extends base_controller_1.BaseController {
884
879
  if (updatedTransactionMeta.status === types_1.TransactionStatus.failed) {
885
880
  updatedTransactionMeta.error = (0, utils_2.normalizeTxError)(new Error(errorMessage));
886
881
  }
887
- if (gasLimit) {
888
- updatedTransactionMeta.txParams.gasLimit = gasLimit;
889
- }
890
- if (gasPrice) {
891
- updatedTransactionMeta.txParams.gasPrice = gasPrice;
892
- }
893
- if (maxFeePerGas) {
894
- updatedTransactionMeta.txParams.maxFeePerGas = maxFeePerGas;
895
- }
896
- if (maxPriorityFeePerGas) {
897
- updatedTransactionMeta.txParams.maxPriorityFeePerGas =
898
- maxPriorityFeePerGas;
899
- }
900
- if (nonce) {
901
- updatedTransactionMeta.txParams.nonce = nonce;
902
- }
903
882
  this.updateTransaction(updatedTransactionMeta, `${controllerName}:updateCustodialTransaction - Custodial transaction updated`);
904
883
  if ([types_1.TransactionStatus.submitted, types_1.TransactionStatus.failed].includes(status)) {
905
884
  this.messagingSystem.publish(`${controllerName}:transactionFinished`, updatedTransactionMeta);
@@ -1064,7 +1043,6 @@ class TransactionController extends base_controller_1.BaseController {
1064
1043
  /**
1065
1044
  * Stop the signing process for a specific transaction.
1066
1045
  * Throws an error causing the transaction status to be set to failed.
1067
- *
1068
1046
  * @param transactionId - The ID of the transaction to stop signing.
1069
1047
  */
1070
1048
  abortTransactionSigning(transactionId) {
@@ -1245,7 +1223,7 @@ class TransactionController extends base_controller_1.BaseController {
1245
1223
  });
1246
1224
  this.onTransactionStatusChange(transactionMeta);
1247
1225
  const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta, transactionMeta.txParams));
1248
- if (!(await this.beforePublish(transactionMeta))) {
1226
+ if (!this.beforePublish(transactionMeta)) {
1249
1227
  (0, logger_1.projectLogger)('Skipping publishing transaction based on hook');
1250
1228
  this.messagingSystem.publish(`${controllerName}:transactionPublishingSkipped`, transactionMeta);
1251
1229
  return ApprovalState.SkippedViaBeforePublishHook;
@@ -1337,6 +1315,7 @@ class TransactionController extends base_controller_1.BaseController {
1337
1315
  this.messagingSystem.publish(`${controllerName}:transactionFinished`, updatedTransactionMeta);
1338
1316
  __classPrivateFieldGet(this, _TransactionController_internalEvents, "f").emit(
1339
1317
  // TODO: Either fix this lint violation or explain why it's necessary to ignore.
1318
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1340
1319
  `${transactionMeta.id}:finished`, updatedTransactionMeta);
1341
1320
  this.messagingSystem.publish(`${controllerName}:transactionRejected`, {
1342
1321
  transactionMeta: updatedTransactionMeta,
@@ -1366,6 +1345,7 @@ class TransactionController extends base_controller_1.BaseController {
1366
1345
  const { chainId, status, txParams, time } = tx;
1367
1346
  if (txParams) {
1368
1347
  // TODO: Either fix this lint violation or explain why it's necessary to ignore.
1348
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1369
1349
  const key = `${String(txParams.nonce)}-${(0, controller_utils_1.convertHexToDecimal)(chainId)}-${new Date(time).toDateString()}`;
1370
1350
  if (nonceNetworkSet.has(key)) {
1371
1351
  return true;
@@ -1845,6 +1825,7 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1845
1825
  }),
1846
1826
  hooks: {
1847
1827
  beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
1828
+ beforePublish: this.beforePublish.bind(this),
1848
1829
  },
1849
1830
  });
1850
1831
  __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_addPendingTransactionTrackerListeners).call(this, pendingTransactionTracker);