@metamask/transaction-controller 8.0.1 → 9.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.
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { Hardfork, Common } from '@ethereumjs/common';
2
+ import { Hardfork } from '@ethereumjs/common';
3
3
  import type { TypedTransaction } from '@ethereumjs/tx';
4
4
  import type { AddApprovalRequest } from '@metamask/approval-controller';
5
5
  import type { BaseConfig, BaseState, RestrictedControllerMessenger } from '@metamask/base-controller';
@@ -69,6 +69,9 @@ export interface TransactionState extends BaseState {
69
69
  methodData: {
70
70
  [key: string]: MethodData;
71
71
  };
72
+ lastFetchedBlockNumbers: {
73
+ [key: string]: number;
74
+ };
72
75
  }
73
76
  /**
74
77
  * Multiplier used to determine a transaction's increased gas fee during cancellation
@@ -121,20 +124,33 @@ export declare class TransactionController extends BaseController<TransactionCon
121
124
  * Creates a TransactionController instance.
122
125
  *
123
126
  * @param options - The controller options.
127
+ * @param options.blockTracker - The block tracker used to poll for new blocks data.
124
128
  * @param options.getNetworkState - Gets the state of the network controller.
129
+ * @param options.getSelectedAddress - Gets the address of the currently selected account.
130
+ * @param options.incomingTransactions - Configuration options for incoming transaction support.
131
+ * @param options.incomingTransactions.apiKey - An optional API key to use when fetching remote transaction data.
132
+ * @param options.incomingTransactions.includeTokenTransfers - Whether or not to include ERC20 token transfers.
133
+ * @param options.incomingTransactions.isEnabled - Whether or not incoming transaction retrieval is enabled.
134
+ * @param options.incomingTransactions.updateTransactions - Whether or not to update local transactions using remote transaction data.
135
+ * @param options.messenger - The controller messenger.
125
136
  * @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
126
137
  * @param options.provider - The provider used to create the underlying EthQuery instance.
127
- * @param options.blockTracker - The block tracker used to poll for new blocks data.
128
- * @param options.messenger - The controller messenger.
129
138
  * @param config - Initial options used to configure this controller.
130
139
  * @param state - Initial state to set on this controller.
131
140
  */
132
- constructor({ getNetworkState, onNetworkStateChange, provider, blockTracker, messenger, }: {
141
+ constructor({ blockTracker, getNetworkState, getSelectedAddress, incomingTransactions, messenger, onNetworkStateChange, provider, }: {
142
+ blockTracker: BlockTracker;
133
143
  getNetworkState: () => NetworkState;
144
+ getSelectedAddress: () => string;
145
+ incomingTransactions: {
146
+ apiKey?: string;
147
+ includeTokenTransfers?: boolean;
148
+ isEnabled?: () => boolean;
149
+ updateTransactions?: boolean;
150
+ };
151
+ messenger: TransactionControllerMessenger;
134
152
  onNetworkStateChange: (listener: (state: NetworkState) => void) => void;
135
153
  provider: Provider;
136
- blockTracker: BlockTracker;
137
- messenger: TransactionControllerMessenger;
138
154
  }, config?: Partial<TransactionConfig>, state?: Partial<TransactionState>);
139
155
  /**
140
156
  * Starts a new polling interval.
@@ -155,22 +171,24 @@ export declare class TransactionController extends BaseController<TransactionCon
155
171
  * if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
156
172
  *
157
173
  * @param transaction - The transaction object to add.
158
- * @param origin - The domain origin to append to the generated TransactionMeta.
159
- * @param deviceConfirmedOn - An enum to indicate what device the transaction was confirmed to append to the generated TransactionMeta.
174
+ * @param opts - Additional options to control how the transaction is added.
175
+ * @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
176
+ * @param opts.origin - The origin of the transaction request, such as a dApp hostname.
177
+ * @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
160
178
  * @returns Object containing a promise resolving to the transaction hash if approved.
161
179
  */
162
- addTransaction(transaction: Transaction, origin?: string, deviceConfirmedOn?: WalletDevice): Promise<Result>;
163
- prepareUnsignedEthTx(txParams: Record<string, unknown>): TypedTransaction;
180
+ addTransaction(transaction: Transaction, { deviceConfirmedOn, origin, requireApproval, }?: {
181
+ deviceConfirmedOn?: WalletDevice;
182
+ origin?: string;
183
+ requireApproval?: boolean | undefined;
184
+ }): Promise<Result>;
185
+ startIncomingTransactionPolling(): void;
186
+ stopIncomingTransactionPolling(): void;
187
+ updateIncomingTransactions(): Promise<void>;
164
188
  /**
165
- * `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for
166
- * specifying which chain, network, hardfork and EIPs to support for
167
- * a transaction. By referencing this configuration, and analyzing the fields
168
- * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
169
- * transaction type to use.
170
- *
171
- * @returns {Common} common configuration object
189
+ * Creates approvals for all unapproved transactions persisted.
172
190
  */
173
- getCommonConfiguration(): Common;
191
+ initApprovals(): void;
174
192
  /**
175
193
  * Attempts to cancel a transaction based on its ID by setting its status to "rejected"
176
194
  * and emitting a `<tx.id>:finished` hub event.
@@ -217,18 +235,12 @@ export declare class TransactionController extends BaseController<TransactionCon
217
235
  *
218
236
  * @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the
219
237
  * current network. If `true`, all transactions are wiped.
238
+ * @param address - If specified, only transactions originating from this address will be
239
+ * wiped on current network.
220
240
  */
221
- wipeTransactions(ignoreNetwork?: boolean): void;
222
- /**
223
- * Get transactions from Etherscan for the given address. By default all transactions are
224
- * returned, but the `fromBlock` option can be given to filter just for transactions from a
225
- * specific block onward.
226
- *
227
- * @param address - The address to fetch the transactions for.
228
- * @param opt - Object containing optional data, fromBlock and Etherscan API key.
229
- * @returns The block number of the latest incoming transaction.
230
- */
231
- fetchAll(address: string, opt?: FetchAllOptions): Promise<string | void>;
241
+ wipeTransactions(ignoreNetwork?: boolean, address?: string): void;
242
+ startIncomingTransactionProcessing(): void;
243
+ stopIncomingTransactionProcessing(): void;
232
244
  private processApproval;
233
245
  /**
234
246
  * Approves a transaction and updates it's status in state. If this is not a
@@ -296,6 +308,21 @@ export declare class TransactionController extends BaseController<TransactionCon
296
308
  private getTransaction;
297
309
  private getApprovalId;
298
310
  private isTransactionCompleted;
311
+ private getChainAndNetworkId;
312
+ private prepareUnsignedEthTx;
313
+ /**
314
+ * `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for
315
+ * specifying which chain, network, hardfork and EIPs to support for
316
+ * a transaction. By referencing this configuration, and analyzing the fields
317
+ * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
318
+ * transaction type to use.
319
+ *
320
+ * @returns common configuration object
321
+ */
322
+ private getCommonConfiguration;
323
+ private onIncomingTransactions;
324
+ private onUpdatedLastFetchedBlockNumbers;
325
+ private generateDappSuggestedGasFees;
299
326
  }
300
327
  export default TransactionController;
301
328
  //# sourceMappingURL=TransactionController.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../src/TransactionController.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAoB,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAEV,kBAAkB,EAEnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACV,UAAU,EACV,SAAS,EACT,6BAA6B,EAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAc3D,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,EACT,MAAM,8BAA8B,CAAC;AAKtC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAMtC,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAe1E,eAAO,MAAM,QAAQ,kBAAkB,CAAC;AAExC;;;;GAIG;AACH,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,eAAe,EAAE,eAAe,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,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IAIhC;;OAEG;IACH,aAAa;IAkBb;;;;;;OAMG;IACG,eAAe,CACnB,aAAa,EAAE,MAAM,EACrB,SAAS,CAAC,EAAE,aAAa,GAAG,sBAAsB;IA4FpD;;;;;OAKG;IACG,kBAAkB,CACtB,aAAa,EAAE,MAAM,EACrB,SAAS,CAAC,EAAE,aAAa,GAAG,sBAAsB;IAoHpD;;;;;OAKG;IACG,WAAW,CAAC,WAAW,EAAE,WAAW;;;;;;;;;IA6E1C;;;OAGG;IACG,wBAAwB;IAkC9B;;;;OAIG;IACH,iBAAiB,CAAC,eAAe,EAAE,eAAe;IAWlD;;;;;;;OAOG;IACH,gBAAgB,CAAC,aAAa,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM;IAgC1D,kCAAkC;IAIlC,iCAAiC;YAInB,eAAe;IAyE7B;;;;;;;OAOG;YACW,kBAAkB;IAuFhC;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAezB;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,wBAAwB;IA0BhC;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IASpB;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;;;;OAKG;YACW,oCAAoC;IAmElD;;;;;;;;OAQG;YACW,4BAA4B;YAa5B,eAAe;IAsB7B,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,sBAAsB;IAe9B,OAAO,CAAC,oBAAoB;IAS5B,OAAO,CAAC,oBAAoB;IAS5B;;;;;;;;OAQG;IACH,OAAO,CAAC,sBAAsB;IAwB9B,OAAO,CAAC,sBAAsB;IA0B9B,OAAO,CAAC,gCAAgC;IAaxC,OAAO,CAAC,4BAA4B;CAqCrC;AAED,eAAe,qBAAqB,CAAC"}
@@ -50,15 +50,21 @@ class TransactionController extends base_controller_1.BaseController {
50
50
  * Creates a TransactionController instance.
51
51
  *
52
52
  * @param options - The controller options.
53
+ * @param options.blockTracker - The block tracker used to poll for new blocks data.
53
54
  * @param options.getNetworkState - Gets the state of the network controller.
55
+ * @param options.getSelectedAddress - Gets the address of the currently selected account.
56
+ * @param options.incomingTransactions - Configuration options for incoming transaction support.
57
+ * @param options.incomingTransactions.apiKey - An optional API key to use when fetching remote transaction data.
58
+ * @param options.incomingTransactions.includeTokenTransfers - Whether or not to include ERC20 token transfers.
59
+ * @param options.incomingTransactions.isEnabled - Whether or not incoming transaction retrieval is enabled.
60
+ * @param options.incomingTransactions.updateTransactions - Whether or not to update local transactions using remote transaction data.
61
+ * @param options.messenger - The controller messenger.
54
62
  * @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
55
63
  * @param options.provider - The provider used to create the underlying EthQuery instance.
56
- * @param options.blockTracker - The block tracker used to poll for new blocks data.
57
- * @param options.messenger - The controller messenger.
58
64
  * @param config - Initial options used to configure this controller.
59
65
  * @param state - Initial state to set on this controller.
60
66
  */
61
- constructor({ getNetworkState, onNetworkStateChange, provider, blockTracker, messenger, }, config, state) {
67
+ constructor({ blockTracker, getNetworkState, getSelectedAddress, incomingTransactions = {}, messenger, onNetworkStateChange, provider, }, config, state) {
62
68
  super(config, state);
63
69
  this.mutex = new async_mutex_1.Mutex();
64
70
  /**
@@ -76,6 +82,7 @@ class TransactionController extends base_controller_1.BaseController {
76
82
  this.defaultState = {
77
83
  methodData: {},
78
84
  transactions: [],
85
+ lastFetchedBlockNumbers: {},
79
86
  };
80
87
  this.initialize();
81
88
  this.provider = provider;
@@ -90,11 +97,19 @@ class TransactionController extends base_controller_1.BaseController {
90
97
  getConfirmedTransactions: (address) => (0, utils_1.getAndFormatTransactionsForNonceTracker)(address, types_1.TransactionStatus.confirmed, this.state.transactions),
91
98
  });
92
99
  this.incomingTransactionHelper = new IncomingTransactionHelper_1.IncomingTransactionHelper({
100
+ blockTracker,
101
+ getCurrentAccount: getSelectedAddress,
93
102
  getNetworkState,
94
- getEthQuery: () => this.ethQuery,
103
+ isEnabled: incomingTransactions.isEnabled,
104
+ remoteTransactionSource: new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource({
105
+ apiKey: incomingTransactions.apiKey,
106
+ includeTokenTransfers: incomingTransactions.includeTokenTransfers,
107
+ }),
95
108
  transactionLimit: this.config.txHistoryLimit,
96
- remoteTransactionSource: new EtherscanRemoteTransactionSource_1.EtherscanRemoteTransactionSource(),
109
+ updateTransactions: incomingTransactions.updateTransactions,
97
110
  });
111
+ this.incomingTransactionHelper.hub.on('transactions', this.onIncomingTransactions.bind(this));
112
+ this.incomingTransactionHelper.hub.on('updatedLastFetchedBlockNumbers', this.onUpdatedLastFetchedBlockNumbers.bind(this));
98
113
  onNetworkStateChange(() => {
99
114
  this.ethQuery = new eth_query_1.default(this.provider);
100
115
  this.registry = new eth_method_registry_1.default({ provider: this.provider });
@@ -160,26 +175,30 @@ class TransactionController extends base_controller_1.BaseController {
160
175
  * if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
161
176
  *
162
177
  * @param transaction - The transaction object to add.
163
- * @param origin - The domain origin to append to the generated TransactionMeta.
164
- * @param deviceConfirmedOn - An enum to indicate what device the transaction was confirmed to append to the generated TransactionMeta.
178
+ * @param opts - Additional options to control how the transaction is added.
179
+ * @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
180
+ * @param opts.origin - The origin of the transaction request, such as a dApp hostname.
181
+ * @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
165
182
  * @returns Object containing a promise resolving to the transaction hash if approved.
166
183
  */
167
- addTransaction(transaction, origin, deviceConfirmedOn) {
184
+ addTransaction(transaction, { deviceConfirmedOn, origin, requireApproval, } = {}) {
168
185
  return __awaiter(this, void 0, void 0, function* () {
169
- const { providerConfig, networkId } = this.getNetworkState();
186
+ const { chainId, networkId } = this.getChainAndNetworkId();
170
187
  const { transactions } = this.state;
171
188
  transaction = (0, utils_1.normalizeTransaction)(transaction);
172
189
  (0, utils_1.validateTransaction)(transaction);
190
+ const dappSuggestedGasFees = this.generateDappSuggestedGasFees(transaction, origin);
173
191
  const transactionMeta = {
174
192
  id: (0, uuid_1.v1)(),
175
193
  networkID: networkId !== null && networkId !== void 0 ? networkId : undefined,
176
- chainId: providerConfig.chainId,
194
+ chainId,
177
195
  origin,
178
196
  status: types_1.TransactionStatus.unapproved,
179
197
  time: Date.now(),
180
198
  transaction,
181
199
  deviceConfirmedOn,
182
200
  verifiedOnBlockchain: false,
201
+ dappSuggestedGasFees,
183
202
  };
184
203
  try {
185
204
  const { gas, estimateGasError } = yield this.estimateGas(transaction);
@@ -194,40 +213,39 @@ class TransactionController extends base_controller_1.BaseController {
194
213
  this.update({ transactions: this.trimTransactionsForState(transactions) });
195
214
  this.hub.emit(`unapprovedTransaction`, transactionMeta);
196
215
  return {
197
- result: this.processApproval(transactionMeta),
216
+ result: this.processApproval(transactionMeta, {
217
+ requireApproval,
218
+ }),
198
219
  transactionMeta,
199
220
  };
200
221
  });
201
222
  }
202
- prepareUnsignedEthTx(txParams) {
203
- return tx_1.TransactionFactory.fromTxData(txParams, {
204
- common: this.getCommonConfiguration(),
205
- freeze: false,
223
+ startIncomingTransactionPolling() {
224
+ this.incomingTransactionHelper.start();
225
+ }
226
+ stopIncomingTransactionPolling() {
227
+ this.incomingTransactionHelper.stop();
228
+ }
229
+ updateIncomingTransactions() {
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ yield this.incomingTransactionHelper.update();
206
232
  });
207
233
  }
208
234
  /**
209
- * `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for
210
- * specifying which chain, network, hardfork and EIPs to support for
211
- * a transaction. By referencing this configuration, and analyzing the fields
212
- * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
213
- * transaction type to use.
214
- *
215
- * @returns {Common} common configuration object
235
+ * Creates approvals for all unapproved transactions persisted.
216
236
  */
217
- getCommonConfiguration() {
218
- const { networkId, providerConfig: { type: chain, chainId, nickname: name }, } = this.getNetworkState();
219
- if (chain !== controller_utils_1.RPC &&
220
- chain !== controller_utils_1.NetworkType['linea-goerli'] &&
221
- chain !== controller_utils_1.NetworkType['linea-mainnet']) {
222
- return new common_1.Common({ chain, hardfork: exports.HARDFORK });
237
+ initApprovals() {
238
+ const { networkId, chainId } = this.getChainAndNetworkId();
239
+ const unapprovedTxs = this.state.transactions.filter((transaction) => transaction.status === types_1.TransactionStatus.unapproved &&
240
+ (0, utils_1.transactionMatchesNetwork)(transaction, chainId, networkId));
241
+ for (const txMeta of unapprovedTxs) {
242
+ this.processApproval(txMeta, {
243
+ shouldShowRequest: false,
244
+ }).catch((error) => {
245
+ /* istanbul ignore next */
246
+ console.error('Error during persisted transaction approval', error);
247
+ });
223
248
  }
224
- const customChainParams = {
225
- name,
226
- chainId: parseInt(chainId, 16),
227
- networkId: networkId === null ? NaN : parseInt(networkId, undefined),
228
- defaultHardfork: exports.HARDFORK,
229
- };
230
- return common_1.Common.custom(customChainParams);
231
249
  }
232
250
  /**
233
251
  * Attempts to cancel a transaction based on its ID by setting its status to "rejected"
@@ -432,8 +450,7 @@ class TransactionController extends base_controller_1.BaseController {
432
450
  queryTransactionStatuses() {
433
451
  return __awaiter(this, void 0, void 0, function* () {
434
452
  const { transactions } = this.state;
435
- const { providerConfig, networkId: currentNetworkID } = this.getNetworkState();
436
- const { chainId: currentChainId } = providerConfig;
453
+ const { chainId: currentChainId, networkId: currentNetworkID } = this.getChainAndNetworkId();
437
454
  let gotUpdates = false;
438
455
  yield (0, controller_utils_1.safelyExecute)(() => Promise.all(transactions.map((meta, index) => __awaiter(this, void 0, void 0, function* () {
439
456
  // Using fallback to networkID only when there is no chainId present.
@@ -474,58 +491,49 @@ class TransactionController extends base_controller_1.BaseController {
474
491
  *
475
492
  * @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the
476
493
  * current network. If `true`, all transactions are wiped.
494
+ * @param address - If specified, only transactions originating from this address will be
495
+ * wiped on current network.
477
496
  */
478
- wipeTransactions(ignoreNetwork) {
497
+ wipeTransactions(ignoreNetwork, address) {
479
498
  /* istanbul ignore next */
480
- if (ignoreNetwork) {
499
+ if (ignoreNetwork && !address) {
481
500
  this.update({ transactions: [] });
482
501
  return;
483
502
  }
484
- const { providerConfig, networkId: currentNetworkID } = this.getNetworkState();
485
- const { chainId: currentChainId } = providerConfig;
486
- const newTransactions = this.state.transactions.filter(({ networkID, chainId }) => {
503
+ const { chainId: currentChainId, networkId: currentNetworkID } = this.getChainAndNetworkId();
504
+ const newTransactions = this.state.transactions.filter(({ networkID, chainId, transaction }) => {
505
+ var _a;
487
506
  // Using fallback to networkID only when there is no chainId present. Should be removed when networkID is completely removed.
488
- const isCurrentNetwork = chainId === currentChainId ||
507
+ const isMatchingNetwork = ignoreNetwork ||
508
+ chainId === currentChainId ||
489
509
  (!chainId && networkID === currentNetworkID);
490
- return !isCurrentNetwork;
510
+ if (!isMatchingNetwork) {
511
+ return true;
512
+ }
513
+ const isMatchingAddress = !address || ((_a = transaction.from) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === address.toLowerCase();
514
+ return !isMatchingAddress;
491
515
  });
492
516
  this.update({
493
517
  transactions: this.trimTransactionsForState(newTransactions),
494
518
  });
495
519
  }
496
- /**
497
- * Get transactions from Etherscan for the given address. By default all transactions are
498
- * returned, but the `fromBlock` option can be given to filter just for transactions from a
499
- * specific block onward.
500
- *
501
- * @param address - The address to fetch the transactions for.
502
- * @param opt - Object containing optional data, fromBlock and Etherscan API key.
503
- * @returns The block number of the latest incoming transaction.
504
- */
505
- fetchAll(address, opt) {
506
- return __awaiter(this, void 0, void 0, function* () {
507
- const { transactions: localTransactions } = this.state;
508
- const { updateRequired, transactions, latestBlockNumber } = yield this.incomingTransactionHelper.reconcile({
509
- address,
510
- localTransactions,
511
- fromBlock: opt === null || opt === void 0 ? void 0 : opt.fromBlock,
512
- apiKey: opt === null || opt === void 0 ? void 0 : opt.etherscanApiKey,
513
- });
514
- if (updateRequired) {
515
- this.update({
516
- transactions: this.trimTransactionsForState(transactions),
517
- });
518
- }
519
- return latestBlockNumber;
520
- });
520
+ startIncomingTransactionProcessing() {
521
+ this.incomingTransactionHelper.start();
522
+ }
523
+ stopIncomingTransactionProcessing() {
524
+ this.incomingTransactionHelper.stop();
521
525
  }
522
- processApproval(transactionMeta) {
526
+ processApproval(transactionMeta, { requireApproval, shouldShowRequest = true, }) {
523
527
  return __awaiter(this, void 0, void 0, function* () {
524
528
  const transactionId = transactionMeta.id;
525
529
  let resultCallbacks;
526
530
  try {
527
- const acceptResult = yield this.requestApproval(transactionMeta);
528
- resultCallbacks = acceptResult.resultCallbacks;
531
+ if (requireApproval !== false) {
532
+ const acceptResult = yield this.requestApproval(transactionMeta, {
533
+ shouldShowRequest,
534
+ });
535
+ resultCallbacks = acceptResult.resultCallbacks;
536
+ }
529
537
  const { meta, isCompleted } = this.isTransactionCompleted(transactionId);
530
538
  if (meta && !isCompleted) {
531
539
  yield this.approveTransaction(transactionId);
@@ -574,8 +582,7 @@ class TransactionController extends base_controller_1.BaseController {
574
582
  return __awaiter(this, void 0, void 0, function* () {
575
583
  const { transactions } = this.state;
576
584
  const releaseLock = yield this.mutex.acquire();
577
- const { providerConfig } = this.getNetworkState();
578
- const { chainId } = providerConfig;
585
+ const { chainId } = this.getChainAndNetworkId();
579
586
  const index = transactions.findIndex(({ id }) => transactionID === id);
580
587
  const transactionMeta = transactions[index];
581
588
  const { transaction: { nonce, from }, } = transactionMeta;
@@ -733,8 +740,14 @@ class TransactionController extends base_controller_1.BaseController {
733
740
  if (!txReceipt) {
734
741
  return [meta, false];
735
742
  }
743
+ const txBlock = yield (0, controller_utils_1.query)(this.ethQuery, 'getBlockByHash', [
744
+ txReceipt.blockHash,
745
+ ]);
736
746
  meta.verifiedOnBlockchain = true;
737
747
  meta.transaction.gasUsed = txReceipt.gasUsed;
748
+ meta.txReceipt = txReceipt;
749
+ meta.baseFeePerGas = txBlock === null || txBlock === void 0 ? void 0 : txBlock.baseFeePerGas;
750
+ meta.blockTimestamp = txBlock === null || txBlock === void 0 ? void 0 : txBlock.timestamp;
738
751
  // According to the Web3 docs:
739
752
  // TRUE if the transaction was successful, FALSE if the EVM reverted the transaction.
740
753
  if (Number(txReceipt.status) === 0) {
@@ -789,7 +802,7 @@ class TransactionController extends base_controller_1.BaseController {
789
802
  return Number(txReceipt.status) === 0;
790
803
  });
791
804
  }
792
- requestApproval(txMeta) {
805
+ requestApproval(txMeta, { shouldShowRequest }) {
793
806
  return __awaiter(this, void 0, void 0, function* () {
794
807
  const id = this.getApprovalId(txMeta);
795
808
  const { origin } = txMeta;
@@ -801,7 +814,7 @@ class TransactionController extends base_controller_1.BaseController {
801
814
  type,
802
815
  requestData,
803
816
  expectsResult: true,
804
- }, true));
817
+ }, shouldShowRequest));
805
818
  });
806
819
  }
807
820
  getTransaction(transactionID) {
@@ -819,6 +832,83 @@ class TransactionController extends base_controller_1.BaseController {
819
832
  const isCompleted = this.isLocalFinalState(transaction.status);
820
833
  return { meta: transaction, isCompleted };
821
834
  }
835
+ getChainAndNetworkId() {
836
+ const { networkId, providerConfig } = this.getNetworkState();
837
+ const chainId = providerConfig === null || providerConfig === void 0 ? void 0 : providerConfig.chainId;
838
+ return { networkId, chainId };
839
+ }
840
+ prepareUnsignedEthTx(txParams) {
841
+ return tx_1.TransactionFactory.fromTxData(txParams, {
842
+ common: this.getCommonConfiguration(),
843
+ freeze: false,
844
+ });
845
+ }
846
+ /**
847
+ * `@ethereumjs/tx` uses `@ethereumjs/common` as a configuration tool for
848
+ * specifying which chain, network, hardfork and EIPs to support for
849
+ * a transaction. By referencing this configuration, and analyzing the fields
850
+ * specified in txParams, @ethereumjs/tx is able to determine which EIP-2718
851
+ * transaction type to use.
852
+ *
853
+ * @returns common configuration object
854
+ */
855
+ getCommonConfiguration() {
856
+ const { networkId, providerConfig: { type: chain, chainId, nickname: name }, } = this.getNetworkState();
857
+ if (chain !== controller_utils_1.RPC &&
858
+ chain !== controller_utils_1.NetworkType['linea-goerli'] &&
859
+ chain !== controller_utils_1.NetworkType['linea-mainnet']) {
860
+ return new common_1.Common({ chain, hardfork: exports.HARDFORK });
861
+ }
862
+ const customChainParams = {
863
+ name,
864
+ chainId: parseInt(chainId, 16),
865
+ networkId: networkId === null ? NaN : parseInt(networkId, undefined),
866
+ defaultHardfork: exports.HARDFORK,
867
+ };
868
+ return common_1.Common.custom(customChainParams);
869
+ }
870
+ onIncomingTransactions({ added, updated, }) {
871
+ const { transactions: currentTransactions } = this.state;
872
+ const updatedTransactions = [
873
+ ...added,
874
+ ...currentTransactions.map((originalTransaction) => {
875
+ const updatedTransaction = updated.find(({ transactionHash }) => transactionHash === originalTransaction.transactionHash);
876
+ return updatedTransaction !== null && updatedTransaction !== void 0 ? updatedTransaction : originalTransaction;
877
+ }),
878
+ ];
879
+ this.update({
880
+ transactions: this.trimTransactionsForState(updatedTransactions),
881
+ });
882
+ }
883
+ onUpdatedLastFetchedBlockNumbers({ lastFetchedBlockNumbers, blockNumber, }) {
884
+ this.update({ lastFetchedBlockNumbers });
885
+ this.hub.emit('incomingTransactionBlock', blockNumber);
886
+ }
887
+ generateDappSuggestedGasFees(transaction, origin) {
888
+ if (!origin || origin === controller_utils_1.ORIGIN_METAMASK) {
889
+ return undefined;
890
+ }
891
+ const { gasPrice, maxFeePerGas, maxPriorityFeePerGas, gas } = transaction;
892
+ if (gasPrice === undefined &&
893
+ maxFeePerGas === undefined &&
894
+ maxPriorityFeePerGas === undefined &&
895
+ gas === undefined) {
896
+ return undefined;
897
+ }
898
+ const dappSuggestedGasFees = {};
899
+ if (gasPrice !== undefined) {
900
+ dappSuggestedGasFees.gasPrice = gasPrice;
901
+ }
902
+ else if (maxFeePerGas !== undefined ||
903
+ maxPriorityFeePerGas !== undefined) {
904
+ dappSuggestedGasFees.maxFeePerGas = maxFeePerGas;
905
+ dappSuggestedGasFees.maxPriorityFeePerGas = maxPriorityFeePerGas;
906
+ }
907
+ if (gas !== undefined) {
908
+ dappSuggestedGasFees.gas = gas;
909
+ }
910
+ return dappSuggestedGasFees;
911
+ }
822
912
  }
823
913
  exports.TransactionController = TransactionController;
824
914
  exports.default = TransactionController;