@metamask-previews/transaction-controller 46.0.0-preview-1cc9329c → 46.0.0-preview-dbdf1da

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");
@@ -238,7 +236,7 @@ class TransactionController extends base_controller_1.BaseController {
238
236
  hooks?.beforeCheckPendingTransaction ??
239
237
  /* istanbul ignore next */
240
238
  (() => true);
241
- this.beforePublish = hooks?.beforePublish ?? (() => Promise.resolve(true));
239
+ this.beforePublish = hooks?.beforePublish ?? (() => true);
242
240
  this.getAdditionalSignArguments =
243
241
  hooks?.getAdditionalSignArguments ?? (() => []);
244
242
  this.publish =
@@ -674,7 +672,6 @@ class TransactionController extends base_controller_1.BaseController {
674
672
  this.onTransactionStatusChange(updatedTransactionMeta);
675
673
  // Intentional given potential duration of process.
676
674
  this.updatePostBalance(updatedTransactionMeta).catch((error) => {
677
- /* istanbul ignore next */
678
675
  (0, logger_1.projectLogger)('Error while updating post balance', error);
679
676
  throw error;
680
677
  });
@@ -923,18 +920,15 @@ class TransactionController extends base_controller_1.BaseController {
923
920
  * @param options.errorMessage - The error message to be assigned in case transaction status update to failed.
924
921
  * @param options.hash - The new hash value to be assigned.
925
922
  * @param options.status - The new status value to be assigned.
926
- * @param options.gasLimit - The new gas limit value to be assigned
927
- * @param options.gasPrice - The new gas price value to be assigned
928
- * @param options.maxFeePerGas - The new max fee per gas value to be assigned
929
- * @param options.maxPriorityFeePerGas - The new max priority fee per gas value to be assigned
930
- * @param options.nonce - The new nonce value to be assigned
931
- * @param options.type - The tranasction type (hardfork) to be assigned
932
923
  */
933
- updateCustodialTransaction(transactionId, { errorMessage, hash, status, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce, type, }) {
924
+ updateCustodialTransaction(transactionId, { errorMessage, hash, status, }) {
934
925
  const transactionMeta = this.getTransaction(transactionId);
935
926
  if (!transactionMeta) {
936
927
  throw new Error(`Cannot update custodial transaction as no transaction metadata found`);
937
928
  }
929
+ if (!transactionMeta.custodyId) {
930
+ throw new Error('Transaction must be a custodian transaction');
931
+ }
938
932
  if (status &&
939
933
  ![
940
934
  types_1.TransactionStatus.submitted,
@@ -950,30 +944,6 @@ class TransactionController extends base_controller_1.BaseController {
950
944
  if (updatedTransactionMeta.status === types_1.TransactionStatus.failed) {
951
945
  updatedTransactionMeta.error = (0, utils_2.normalizeTxError)(new Error(errorMessage));
952
946
  }
953
- if (gasLimit) {
954
- updatedTransactionMeta.txParams.gasLimit = gasLimit;
955
- }
956
- if (gasPrice) {
957
- updatedTransactionMeta.txParams.gasPrice = gasPrice;
958
- }
959
- if (maxFeePerGas) {
960
- updatedTransactionMeta.txParams.maxFeePerGas = maxFeePerGas;
961
- }
962
- if (maxPriorityFeePerGas) {
963
- updatedTransactionMeta.txParams.maxPriorityFeePerGas =
964
- maxPriorityFeePerGas;
965
- }
966
- if (type) {
967
- updatedTransactionMeta.txParams.type = type;
968
- // If the type was reverted to legacy, we need to remove the maxFeePerGas and maxPriorityFeePerGas values
969
- if (type === types_1.TransactionEnvelopeType.legacy) {
970
- updatedTransactionMeta.txParams.maxFeePerGas = undefined;
971
- updatedTransactionMeta.txParams.maxPriorityFeePerGas = undefined;
972
- }
973
- }
974
- if (nonce) {
975
- updatedTransactionMeta.txParams.nonce = nonce;
976
- }
977
947
  this.updateTransaction(updatedTransactionMeta, `${controllerName}:updateCustodialTransaction - Custodial transaction updated`);
978
948
  if ([types_1.TransactionStatus.submitted, types_1.TransactionStatus.failed].includes(status)) {
979
949
  this.messagingSystem.publish(`${controllerName}:transactionFinished`, updatedTransactionMeta);
@@ -1319,7 +1289,7 @@ class TransactionController extends base_controller_1.BaseController {
1319
1289
  });
1320
1290
  this.onTransactionStatusChange(transactionMeta);
1321
1291
  const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta));
1322
- if (!(await this.beforePublish(transactionMeta))) {
1292
+ if (!this.beforePublish(transactionMeta)) {
1323
1293
  (0, logger_1.projectLogger)('Skipping publishing transaction based on hook');
1324
1294
  this.messagingSystem.publish(`${controllerName}:transactionPublishingSkipped`, transactionMeta);
1325
1295
  return ApprovalState.SkippedViaBeforePublishHook;
@@ -1902,6 +1872,7 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1902
1872
  }),
1903
1873
  hooks: {
1904
1874
  beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
1875
+ beforePublish: this.beforePublish.bind(this),
1905
1876
  },
1906
1877
  });
1907
1878
  __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_addPendingTransactionTrackerListeners).call(this, pendingTransactionTracker);