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

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,4 +1,6 @@
1
1
  "use strict";
2
+ /* istanbul ignore file */
3
+ // FIXME - remove above ignore
2
4
  var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
5
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
6
  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");
@@ -236,7 +238,7 @@ class TransactionController extends base_controller_1.BaseController {
236
238
  hooks?.beforeCheckPendingTransaction ??
237
239
  /* istanbul ignore next */
238
240
  (() => true);
239
- this.beforePublish = hooks?.beforePublish ?? (() => true);
241
+ this.beforePublish = hooks?.beforePublish ?? (() => Promise.resolve(true));
240
242
  this.getAdditionalSignArguments =
241
243
  hooks?.getAdditionalSignArguments ?? (() => []);
242
244
  this.publish =
@@ -672,6 +674,7 @@ class TransactionController extends base_controller_1.BaseController {
672
674
  this.onTransactionStatusChange(updatedTransactionMeta);
673
675
  // Intentional given potential duration of process.
674
676
  this.updatePostBalance(updatedTransactionMeta).catch((error) => {
677
+ /* istanbul ignore next */
675
678
  (0, logger_1.projectLogger)('Error while updating post balance', error);
676
679
  throw error;
677
680
  });
@@ -920,15 +923,18 @@ class TransactionController extends base_controller_1.BaseController {
920
923
  * @param options.errorMessage - The error message to be assigned in case transaction status update to failed.
921
924
  * @param options.hash - The new hash value to be assigned.
922
925
  * @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
923
932
  */
924
- updateCustodialTransaction(transactionId, { errorMessage, hash, status, }) {
933
+ updateCustodialTransaction(transactionId, { errorMessage, hash, status, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, nonce, type, }) {
925
934
  const transactionMeta = this.getTransaction(transactionId);
926
935
  if (!transactionMeta) {
927
936
  throw new Error(`Cannot update custodial transaction as no transaction metadata found`);
928
937
  }
929
- if (!transactionMeta.custodyId) {
930
- throw new Error('Transaction must be a custodian transaction');
931
- }
932
938
  if (status &&
933
939
  ![
934
940
  types_1.TransactionStatus.submitted,
@@ -944,6 +950,30 @@ class TransactionController extends base_controller_1.BaseController {
944
950
  if (updatedTransactionMeta.status === types_1.TransactionStatus.failed) {
945
951
  updatedTransactionMeta.error = (0, utils_2.normalizeTxError)(new Error(errorMessage));
946
952
  }
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
+ }
947
977
  this.updateTransaction(updatedTransactionMeta, `${controllerName}:updateCustodialTransaction - Custodial transaction updated`);
948
978
  if ([types_1.TransactionStatus.submitted, types_1.TransactionStatus.failed].includes(status)) {
949
979
  this.messagingSystem.publish(`${controllerName}:transactionFinished`, updatedTransactionMeta);
@@ -1217,7 +1247,10 @@ class TransactionController extends base_controller_1.BaseController {
1217
1247
  if (!isTxCompleted) {
1218
1248
  if (error?.code === rpc_errors_1.errorCodes.provider.userRejectedRequest) {
1219
1249
  this.cancelTransaction(transactionId, actionId);
1220
- throw rpc_errors_1.providerErrors.userRejectedRequest('MetaMask Tx Signature: User denied transaction signature.');
1250
+ throw rpc_errors_1.providerErrors.userRejectedRequest({
1251
+ message: 'MetaMask Tx Signature: User denied transaction signature.',
1252
+ data: error?.data,
1253
+ });
1221
1254
  }
1222
1255
  else {
1223
1256
  this.failTransaction(meta, error, actionId);
@@ -1286,7 +1319,7 @@ class TransactionController extends base_controller_1.BaseController {
1286
1319
  });
1287
1320
  this.onTransactionStatusChange(transactionMeta);
1288
1321
  const rawTx = await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Sign', parentContext: traceContext }, () => this.signTransaction(transactionMeta));
1289
- if (!this.beforePublish(transactionMeta)) {
1322
+ if (!(await this.beforePublish(transactionMeta))) {
1290
1323
  (0, logger_1.projectLogger)('Skipping publishing transaction based on hook');
1291
1324
  this.messagingSystem.publish(`${controllerName}:transactionPublishingSkipped`, transactionMeta);
1292
1325
  return ApprovalState.SkippedViaBeforePublishHook;
@@ -1869,7 +1902,6 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_me
1869
1902
  }),
1870
1903
  hooks: {
1871
1904
  beforeCheckPendingTransaction: this.beforeCheckPendingTransaction.bind(this),
1872
- beforePublish: this.beforePublish.bind(this),
1873
1905
  },
1874
1906
  });
1875
1907
  __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_addPendingTransactionTrackerListeners).call(this, pendingTransactionTracker);