@metamask/transaction-controller 40.1.0 → 41.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +50 -1
  2. package/README.md +4 -0
  3. package/dist/TransactionController.cjs +116 -227
  4. package/dist/TransactionController.cjs.map +1 -1
  5. package/dist/TransactionController.d.cts +34 -52
  6. package/dist/TransactionController.d.cts.map +1 -1
  7. package/dist/TransactionController.d.mts +34 -52
  8. package/dist/TransactionController.d.mts.map +1 -1
  9. package/dist/TransactionController.mjs +119 -232
  10. package/dist/TransactionController.mjs.map +1 -1
  11. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs +1 -2
  12. package/dist/gas-flows/OracleLayer1GasFeeFlow.mjs.map +1 -1
  13. package/dist/helpers/EtherscanRemoteTransactionSource.cjs +13 -12
  14. package/dist/helpers/EtherscanRemoteTransactionSource.cjs.map +1 -1
  15. package/dist/helpers/EtherscanRemoteTransactionSource.d.cts.map +1 -1
  16. package/dist/helpers/EtherscanRemoteTransactionSource.d.mts.map +1 -1
  17. package/dist/helpers/EtherscanRemoteTransactionSource.mjs +13 -12
  18. package/dist/helpers/EtherscanRemoteTransactionSource.mjs.map +1 -1
  19. package/dist/helpers/GasFeePoller.cjs +6 -4
  20. package/dist/helpers/GasFeePoller.cjs.map +1 -1
  21. package/dist/helpers/GasFeePoller.d.cts +1 -1
  22. package/dist/helpers/GasFeePoller.d.cts.map +1 -1
  23. package/dist/helpers/GasFeePoller.d.mts +1 -1
  24. package/dist/helpers/GasFeePoller.d.mts.map +1 -1
  25. package/dist/helpers/GasFeePoller.mjs +6 -4
  26. package/dist/helpers/GasFeePoller.mjs.map +1 -1
  27. package/dist/helpers/IncomingTransactionHelper.cjs +20 -11
  28. package/dist/helpers/IncomingTransactionHelper.cjs.map +1 -1
  29. package/dist/helpers/IncomingTransactionHelper.d.cts.map +1 -1
  30. package/dist/helpers/IncomingTransactionHelper.d.mts.map +1 -1
  31. package/dist/helpers/IncomingTransactionHelper.mjs +21 -12
  32. package/dist/helpers/IncomingTransactionHelper.mjs.map +1 -1
  33. package/dist/helpers/MethodDataHelper.cjs +80 -0
  34. package/dist/helpers/MethodDataHelper.cjs.map +1 -0
  35. package/dist/helpers/MethodDataHelper.d.cts +14 -0
  36. package/dist/helpers/MethodDataHelper.d.cts.map +1 -0
  37. package/dist/helpers/MethodDataHelper.d.mts +14 -0
  38. package/dist/helpers/MethodDataHelper.d.mts.map +1 -0
  39. package/dist/helpers/MethodDataHelper.mjs +73 -0
  40. package/dist/helpers/MethodDataHelper.mjs.map +1 -0
  41. package/dist/helpers/MultichainTrackingHelper.cjs +87 -104
  42. package/dist/helpers/MultichainTrackingHelper.cjs.map +1 -1
  43. package/dist/helpers/MultichainTrackingHelper.d.cts +16 -22
  44. package/dist/helpers/MultichainTrackingHelper.d.cts.map +1 -1
  45. package/dist/helpers/MultichainTrackingHelper.d.mts +16 -22
  46. package/dist/helpers/MultichainTrackingHelper.d.mts.map +1 -1
  47. package/dist/helpers/MultichainTrackingHelper.mjs +88 -109
  48. package/dist/helpers/MultichainTrackingHelper.mjs.map +1 -1
  49. package/dist/helpers/PendingTransactionTracker.cjs +26 -22
  50. package/dist/helpers/PendingTransactionTracker.cjs.map +1 -1
  51. package/dist/helpers/PendingTransactionTracker.d.cts.map +1 -1
  52. package/dist/helpers/PendingTransactionTracker.d.mts.map +1 -1
  53. package/dist/helpers/PendingTransactionTracker.mjs +26 -22
  54. package/dist/helpers/PendingTransactionTracker.mjs.map +1 -1
  55. package/dist/types.cjs.map +1 -1
  56. package/dist/types.d.cts +7 -3
  57. package/dist/types.d.cts.map +1 -1
  58. package/dist/types.d.mts +7 -3
  59. package/dist/types.d.mts.map +1 -1
  60. package/dist/types.mjs.map +1 -1
  61. package/dist/utils/etherscan.cjs +2 -1
  62. package/dist/utils/etherscan.cjs.map +1 -1
  63. package/dist/utils/etherscan.d.cts.map +1 -1
  64. package/dist/utils/etherscan.d.mts.map +1 -1
  65. package/dist/utils/etherscan.mjs +3 -2
  66. package/dist/utils/etherscan.mjs.map +1 -1
  67. package/package.json +8 -6
@@ -9,20 +9,18 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- var _TransactionController_instances, _TransactionController_internalEvents, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_trace, _TransactionController_transactionHistoryLimit, _TransactionController_isFirstTimeInteractionEnabled, _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_updateFirstTimeInteraction, _TransactionController_updateSimulationData, _TransactionController_onGasFeePollerTransactionUpdate, _TransactionController_getNetworkClientId, _TransactionController_getGlobalNetworkClientId, _TransactionController_getGlobalChainId, _TransactionController_isCustomNetwork, _TransactionController_getSelectedAccount, _TransactionController_updateSubmitHistory;
12
+ var _TransactionController_instances, _TransactionController_internalEvents, _TransactionController_methodDataHelper, _TransactionController_incomingTransactionOptions, _TransactionController_pendingTransactionOptions, _TransactionController_trace, _TransactionController_transactionHistoryLimit, _TransactionController_isFirstTimeInteractionEnabled, _TransactionController_isSimulationEnabled, _TransactionController_testGasFeeFlows, _TransactionController_multichainTrackingHelper, _TransactionController_retryTransaction, _TransactionController_getChainId, _TransactionController_getNetworkClientId, _TransactionController_getEthQuery, _TransactionController_getProvider, _TransactionController_createNonceTracker, _TransactionController_createRemoteTransactionSource, _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_updateFirstTimeInteraction, _TransactionController_updateSimulationData, _TransactionController_onGasFeePollerTransactionUpdate, _TransactionController_getSelectedAccount, _TransactionController_updateSubmitHistory;
13
13
  function $importDefault(module) {
14
14
  if (module?.__esModule) {
15
15
  return module.default;
16
16
  }
17
17
  return module;
18
18
  }
19
- import $ethereumjscommon from "@ethereumjs/common";
20
- const { Hardfork, Common } = $ethereumjscommon;
19
+ import { Hardfork, Common } from "@ethereumjs/common";
21
20
  import { TransactionFactory } from "@ethereumjs/tx";
22
- import $ethereumjsutil from "@ethereumjs/util";
23
- const { bufferToHex } = $ethereumjsutil;
21
+ import { bufferToHex } from "@ethereumjs/util";
24
22
  import { BaseController } from "@metamask/base-controller";
25
- import { query, ApprovalType, ORIGIN_METAMASK, convertHexToDecimal, isInfuraNetworkType } from "@metamask/controller-utils";
23
+ import { query, ApprovalType, ORIGIN_METAMASK, convertHexToDecimal } from "@metamask/controller-utils";
26
24
  import $EthQuery from "@metamask/eth-query";
27
25
  const EthQuery = $importDefault($EthQuery);
28
26
  import { NetworkClientType } from "@metamask/network-controller";
@@ -30,7 +28,8 @@ import { NonceTracker } from "@metamask/nonce-tracker";
30
28
  import { errorCodes, rpcErrors, providerErrors } from "@metamask/rpc-errors";
31
29
  import { add0x, hexToNumber } from "@metamask/utils";
32
30
  import { Mutex } from "async-mutex";
33
- import { MethodRegistry } from "eth-method-registry";
31
+ // This package purposefully relies on Node's EventEmitter module.
32
+ // eslint-disable-next-line import/no-nodejs-modules
34
33
  import { EventEmitter } from "events";
35
34
  import $lodash from "lodash";
36
35
  const { cloneDeep, mapValues, merge, pickBy, sortBy } = $lodash;
@@ -44,6 +43,7 @@ import { TestGasFeeFlow } from "./gas-flows/TestGasFeeFlow.mjs";
44
43
  import { EtherscanRemoteTransactionSource } from "./helpers/EtherscanRemoteTransactionSource.mjs";
45
44
  import { GasFeePoller } from "./helpers/GasFeePoller.mjs";
46
45
  import { IncomingTransactionHelper } from "./helpers/IncomingTransactionHelper.mjs";
46
+ import { MethodDataHelper } from "./helpers/MethodDataHelper.mjs";
47
47
  import { MultichainTrackingHelper } from "./helpers/MultichainTrackingHelper.mjs";
48
48
  import { PendingTransactionTracker } from "./helpers/PendingTransactionTracker.mjs";
49
49
  import { projectLogger as log } from "./logger.mjs";
@@ -153,22 +153,10 @@ export class TransactionController extends BaseController {
153
153
  this.messagingSystem.publish(`${controllerName}:transactionFinished`, newTransactionMeta);
154
154
  __classPrivateFieldGet(this, _TransactionController_internalEvents, "f").emit(`${transactionMeta.id}:finished`, newTransactionMeta);
155
155
  }
156
- async registryLookup(fourBytePrefix) {
157
- const registryMethod = await this.registry.lookup(fourBytePrefix);
158
- if (!registryMethod) {
159
- return {
160
- registryMethod: '',
161
- parsedRegistryMethod: { name: undefined, args: undefined },
162
- };
163
- }
164
- const parsedRegistryMethod = this.registry.parse(registryMethod);
165
- return { registryMethod, parsedRegistryMethod };
166
- }
167
156
  /**
168
157
  * Constructs a TransactionController.
169
158
  *
170
159
  * @param options - The controller options.
171
- * @param options.blockTracker - The block tracker used to poll for new blocks data.
172
160
  * @param options.disableHistory - Whether to disable storing history in transaction metadata.
173
161
  * @param options.disableSendFlowHistory - Explicitly disable transaction metadata history.
174
162
  * @param options.disableSwaps - Whether to disable additional processing on swaps transactions.
@@ -181,13 +169,10 @@ export class TransactionController extends BaseController {
181
169
  * @param options.getPermittedAccounts - Get accounts that a given origin has permissions for.
182
170
  * @param options.getSavedGasFees - Gets the saved gas fee config.
183
171
  * @param options.incomingTransactions - Configuration options for incoming transaction support.
184
- * @param options.isMultichainEnabled - Enable multichain support.
185
172
  * @param options.isFirstTimeInteractionEnabled - Whether first time interaction checks are enabled.
186
173
  * @param options.isSimulationEnabled - Whether new transactions will be automatically simulated.
187
174
  * @param options.messenger - The controller messenger.
188
- * @param options.onNetworkStateChange - Allows subscribing to network controller state changes.
189
175
  * @param options.pendingTransactions - Configuration options for pending transaction support.
190
- * @param options.provider - The provider used to create the underlying EthQuery instance.
191
176
  * @param options.securityProviderRequest - A function for verifying a transaction, whether it is malicious or not.
192
177
  * @param options.sign - Function used to sign transactions.
193
178
  * @param options.state - Initial state to set on this controller.
@@ -196,7 +181,7 @@ export class TransactionController extends BaseController {
196
181
  * @param options.transactionHistoryLimit - Transaction history limit.
197
182
  * @param options.hooks - The controller hooks.
198
183
  */
199
- constructor({ blockTracker, disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkClientRegistry, getNetworkState, getPermittedAccounts, getSavedGasFees, incomingTransactions = {}, isMultichainEnabled = false, isFirstTimeInteractionEnabled, isSimulationEnabled, messenger, onNetworkStateChange, pendingTransactions = {}, provider, securityProviderRequest, sign, state, testGasFeeFlows, trace, transactionHistoryLimit = 40, hooks, }) {
184
+ constructor({ disableHistory, disableSendFlowHistory, disableSwaps, getCurrentAccountEIP1559Compatibility, getCurrentNetworkEIP1559Compatibility, getExternalPendingTransactions, getGasFeeEstimates, getNetworkClientRegistry, getNetworkState, getPermittedAccounts, getSavedGasFees, incomingTransactions = {}, isFirstTimeInteractionEnabled, isSimulationEnabled, messenger, pendingTransactions = {}, securityProviderRequest, sign, state, testGasFeeFlows, trace, transactionHistoryLimit = 40, hooks, }) {
200
185
  super({
201
186
  name: controllerName,
202
187
  metadata,
@@ -209,6 +194,7 @@ export class TransactionController extends BaseController {
209
194
  _TransactionController_instances.add(this);
210
195
  _TransactionController_internalEvents.set(this, new EventEmitter());
211
196
  this.approvingTransactionIds = new Set();
197
+ _TransactionController_methodDataHelper.set(this, void 0);
212
198
  this.mutex = new Mutex();
213
199
  _TransactionController_incomingTransactionOptions.set(this, void 0);
214
200
  _TransactionController_pendingTransactionOptions.set(this, void 0);
@@ -220,8 +206,6 @@ export class TransactionController extends BaseController {
220
206
  _TransactionController_testGasFeeFlows.set(this, void 0);
221
207
  _TransactionController_multichainTrackingHelper.set(this, void 0);
222
208
  _TransactionController_checkForPendingTransactionAndStartPolling.set(this, () => {
223
- // PendingTransactionTracker reads state through its getTransactions hook
224
- this.pendingTransactionTracker.startIfPendingTransactions();
225
209
  __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").checkForPendingTransactionAndStartPolling();
226
210
  });
227
211
  this.messagingSystem = messenger;
@@ -231,8 +215,6 @@ export class TransactionController extends BaseController {
231
215
  this.isSwapsDisabled = disableSwaps ?? false;
232
216
  __classPrivateFieldSet(this, _TransactionController_isFirstTimeInteractionEnabled, isFirstTimeInteractionEnabled ?? (() => true), "f");
233
217
  __classPrivateFieldSet(this, _TransactionController_isSimulationEnabled, isSimulationEnabled ?? (() => true), "f");
234
- // @ts-expect-error the type in eth-method-registry is inappropriate and should be changed
235
- this.registry = new MethodRegistry({ provider });
236
218
  this.getSavedGasFees = getSavedGasFees ?? ((_chainId) => undefined);
237
219
  this.getCurrentAccountEIP1559Compatibility =
238
220
  getCurrentAccountEIP1559Compatibility ?? (() => Promise.resolve(true));
@@ -260,18 +242,10 @@ export class TransactionController extends BaseController {
260
242
  hooks?.getAdditionalSignArguments ?? (() => []);
261
243
  this.publish =
262
244
  hooks?.publish ?? (() => Promise.resolve({ transactionHash: undefined }));
263
- this.nonceTracker = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createNonceTracker).call(this, {
264
- provider,
265
- blockTracker,
266
- });
267
245
  const findNetworkClientIdByChainId = (chainId) => {
268
246
  return this.messagingSystem.call(`NetworkController:findNetworkClientIdByChainId`, chainId);
269
247
  };
270
248
  __classPrivateFieldSet(this, _TransactionController_multichainTrackingHelper, new MultichainTrackingHelper({
271
- isMultichainEnabled,
272
- provider,
273
- nonceTracker: this.nonceTracker,
274
- incomingTransactionOptions: incomingTransactions,
275
249
  findNetworkClientIdByChainId,
276
250
  getNetworkClientById: ((networkClientId) => {
277
251
  return this.messagingSystem.call(`NetworkController:getNetworkClientById`, networkClientId);
@@ -282,33 +256,19 @@ export class TransactionController extends BaseController {
282
256
  createNonceTracker: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createNonceTracker).bind(this),
283
257
  createIncomingTransactionHelper: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createIncomingTransactionHelper).bind(this),
284
258
  createPendingTransactionTracker: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createPendingTransactionTracker).bind(this),
259
+ createRemoteTransactionSource: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createRemoteTransactionSource).bind(this),
285
260
  onNetworkStateChange: (listener) => {
286
261
  this.messagingSystem.subscribe('NetworkController:stateChange', listener);
287
262
  },
288
263
  }), "f");
289
264
  __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").initialize();
290
- const etherscanRemoteTransactionSource = new EtherscanRemoteTransactionSource({
291
- apiKeysByChainId: incomingTransactions.etherscanApiKeysByChainId,
292
- includeTokenTransfers: incomingTransactions.includeTokenTransfers,
293
- });
294
- this.incomingTransactionHelper = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createIncomingTransactionHelper).call(this, {
295
- blockTracker,
296
- etherscanRemoteTransactionSource,
297
- });
298
- this.pendingTransactionTracker = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_createPendingTransactionTracker).call(this, {
299
- provider,
300
- blockTracker,
301
- });
302
265
  this.gasFeeFlows = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getGasFeeFlows).call(this);
303
266
  this.layer1GasFeeFlows = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getLayer1GasFeeFlows).call(this);
304
267
  const gasFeePoller = new GasFeePoller({
305
268
  findNetworkClientIdByChainId,
306
269
  gasFeeFlows: this.gasFeeFlows,
307
270
  getGasFeeControllerEstimates: this.getGasFeeEstimates,
308
- getProvider: (chainId, networkClientId) => __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getProvider({
309
- networkClientId,
310
- chainId,
311
- }),
271
+ getProvider: (networkClientId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getProvider).call(this, { networkClientId }),
312
272
  getTransactions: () => this.state.transactions,
313
273
  layer1GasFeeFlows: this.layer1GasFeeFlows,
314
274
  onStateChange: (listener) => {
@@ -316,15 +276,18 @@ export class TransactionController extends BaseController {
316
276
  },
317
277
  });
318
278
  gasFeePoller.hub.on('transaction-updated', __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_onGasFeePollerTransactionUpdate).bind(this));
279
+ __classPrivateFieldSet(this, _TransactionController_methodDataHelper, new MethodDataHelper({
280
+ getProvider: (networkClientId) => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getProvider).call(this, { networkClientId }),
281
+ getState: () => this.state.methodData,
282
+ }), "f");
283
+ __classPrivateFieldGet(this, _TransactionController_methodDataHelper, "f").hub.on('update', ({ fourBytePrefix, methodData }) => {
284
+ this.update((_state) => {
285
+ _state.methodData[fourBytePrefix] = methodData;
286
+ });
287
+ });
319
288
  // when transactionsController state changes
320
289
  // check for pending transactions and start polling if there are any
321
290
  this.messagingSystem.subscribe('TransactionController:stateChange', __classPrivateFieldGet(this, _TransactionController_checkForPendingTransactionAndStartPolling, "f"));
322
- // TODO once v2 is merged make sure this only runs when
323
- // selectedNetworkClientId changes
324
- onNetworkStateChange(() => {
325
- log('Detected network change', this.getChainId());
326
- this.pendingTransactionTracker.startIfPendingTransactions();
327
- });
328
291
  this.onBootCleanup();
329
292
  __classPrivateFieldGet(this, _TransactionController_checkForPendingTransactionAndStartPolling, "f").call(this);
330
293
  }
@@ -338,25 +301,11 @@ export class TransactionController extends BaseController {
338
301
  * Handle new method data request.
339
302
  *
340
303
  * @param fourBytePrefix - The method prefix.
304
+ * @param networkClientId - The ID of the network client used to fetch the method data.
341
305
  * @returns The method data object corresponding to the given signature prefix.
342
306
  */
343
- async handleMethodData(fourBytePrefix) {
344
- const releaseLock = await this.mutex.acquire();
345
- try {
346
- const { methodData } = this.state;
347
- const knownMethod = Object.keys(methodData).find((knownFourBytePrefix) => fourBytePrefix === knownFourBytePrefix);
348
- if (knownMethod) {
349
- return methodData[fourBytePrefix];
350
- }
351
- const registry = await this.registryLookup(fourBytePrefix);
352
- this.update((state) => {
353
- state.methodData[fourBytePrefix] = registry;
354
- });
355
- return registry;
356
- }
357
- finally {
358
- releaseLock();
359
- }
307
+ async handleMethodData(fourBytePrefix, networkClientId) {
308
+ return __classPrivateFieldGet(this, _TransactionController_methodDataHelper, "f").lookup(fourBytePrefix, networkClientId);
360
309
  }
361
310
  /**
362
311
  * Add a new unapproved transaction to state. Parameters will be validated, a
@@ -364,40 +313,38 @@ export class TransactionController extends BaseController {
364
313
  * if not provided. If A `<tx.id>:unapproved` hub event will be emitted once added.
365
314
  *
366
315
  * @param txParams - Standard parameters for an Ethereum transaction.
367
- * @param opts - Additional options to control how the transaction is added.
368
- * @param opts.actionId - Unique ID to prevent duplicate requests.
369
- * @param opts.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
370
- * @param opts.method - RPC method that requested the transaction.
371
- * @param opts.origin - The origin of the transaction request, such as a dApp hostname.
372
- * @param opts.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
373
- * @param opts.securityAlertResponse - Response from security validator.
374
- * @param opts.sendFlowHistory - The sendFlowHistory entries to add.
375
- * @param opts.type - Type of transaction to add, such as 'cancel' or 'swap'.
376
- * @param opts.swaps - Options for swaps transactions.
377
- * @param opts.swaps.hasApproveTx - Whether the transaction has an approval transaction.
378
- * @param opts.swaps.meta - Metadata for swap transaction.
379
- * @param opts.networkClientId - The id of the network client for this transaction.
380
- * @param opts.traceContext - The parent context for any new traces.
316
+ * @param options - Additional options to control how the transaction is added.
317
+ * @param options.actionId - Unique ID to prevent duplicate requests.
318
+ * @param options.deviceConfirmedOn - An enum to indicate what device confirmed the transaction.
319
+ * @param options.method - RPC method that requested the transaction.
320
+ * @param options.origin - The origin of the transaction request, such as a dApp hostname.
321
+ * @param options.requireApproval - Whether the transaction requires approval by the user, defaults to true unless explicitly disabled.
322
+ * @param options.securityAlertResponse - Response from security validator.
323
+ * @param options.sendFlowHistory - The sendFlowHistory entries to add.
324
+ * @param options.type - Type of transaction to add, such as 'cancel' or 'swap'.
325
+ * @param options.swaps - Options for swaps transactions.
326
+ * @param options.swaps.hasApproveTx - Whether the transaction has an approval transaction.
327
+ * @param options.swaps.meta - Metadata for swap transaction.
328
+ * @param options.networkClientId - The id of the network client for this transaction.
329
+ * @param options.traceContext - The parent context for any new traces.
381
330
  * @returns Object containing a promise resolving to the transaction hash if approved.
382
331
  */
383
- async addTransaction(txParams, { actionId, deviceConfirmedOn, method, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, networkClientId: requestNetworkClientId, } = {}) {
384
- log('Adding transaction', txParams);
332
+ async addTransaction(txParams, options) {
333
+ log('Adding transaction', txParams, options);
334
+ const { actionId, deviceConfirmedOn, method, networkClientId, origin, requireApproval, securityAlertResponse, sendFlowHistory, swaps = {}, traceContext, type, } = options;
385
335
  txParams = normalizeTransactionParams(txParams);
386
- if (requestNetworkClientId &&
387
- !__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").has(requestNetworkClientId)) {
388
- throw new Error('The networkClientId for this transaction could not be found');
336
+ if (!__classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").has(networkClientId)) {
337
+ throw new Error(`Network client not found - ${networkClientId}`);
389
338
  }
390
- const networkClientId = requestNetworkClientId ?? __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getGlobalNetworkClientId).call(this);
391
339
  const isEIP1559Compatible = await this.getEIP1559Compatibility(networkClientId);
392
340
  validateTxParams(txParams, isEIP1559Compatible);
393
341
  if (origin && this.getPermittedAccounts) {
394
342
  await validateTransactionOrigin(await this.getPermittedAccounts(origin), __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getSelectedAccount).call(this).address, txParams.from, origin);
395
343
  }
396
344
  const dappSuggestedGasFees = this.generateDappSuggestedGasFees(txParams, origin);
397
- const chainId = this.getChainId(networkClientId);
398
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
345
+ const chainId = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getChainId).call(this, networkClientId);
346
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
399
347
  networkClientId,
400
- chainId,
401
348
  });
402
349
  const transactionType = type ?? (await determineTransactionType(txParams, ethQuery)).type;
403
350
  const existingTransactionMeta = this.getTransactionWithActionId(actionId);
@@ -474,29 +421,13 @@ export class TransactionController extends BaseController {
474
421
  transactionMeta: addedTransactionMeta,
475
422
  };
476
423
  }
477
- startIncomingTransactionPolling(networkClientIds = []) {
478
- if (networkClientIds.length === 0) {
479
- this.incomingTransactionHelper.start();
480
- return;
481
- }
424
+ startIncomingTransactionPolling(networkClientIds) {
482
425
  __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").startIncomingTransactionPolling(networkClientIds);
483
426
  }
484
- stopIncomingTransactionPolling(networkClientIds = []) {
485
- if (networkClientIds.length === 0) {
486
- this.incomingTransactionHelper.stop();
487
- return;
488
- }
427
+ stopIncomingTransactionPolling(networkClientIds) {
489
428
  __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").stopIncomingTransactionPolling(networkClientIds);
490
429
  }
491
- stopAllIncomingTransactionPolling() {
492
- this.incomingTransactionHelper.stop();
493
- __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").stopAllIncomingTransactionPolling();
494
- }
495
430
  async updateIncomingTransactions(networkClientIds = []) {
496
- if (networkClientIds.length === 0) {
497
- await this.incomingTransactionHelper.update();
498
- return;
499
- }
500
431
  await __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").updateIncomingTransactions(networkClientIds);
501
432
  }
502
433
  /**
@@ -560,7 +491,7 @@ export class TransactionController extends BaseController {
560
491
  * @returns The gas and gas price.
561
492
  */
562
493
  async estimateGas(transaction, networkClientId) {
563
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
494
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
564
495
  networkClientId,
565
496
  });
566
497
  const { estimatedGas, simulationFails } = await estimateGas(transaction, ethQuery);
@@ -574,7 +505,7 @@ export class TransactionController extends BaseController {
574
505
  * @param networkClientId - The network client id to use for the estimate.
575
506
  */
576
507
  async estimateGasBuffered(transaction, multiplier, networkClientId) {
577
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
508
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, {
578
509
  networkClientId,
579
510
  });
580
511
  const { blockGasLimit, estimatedGas, simulationFails } = await estimateGas(transaction, ethQuery);
@@ -617,24 +548,21 @@ export class TransactionController extends BaseController {
617
548
  this.updateTransaction(updatedTransactionMeta, `${controllerName}:updatesecurityAlertResponse - securityAlertResponse updated`);
618
549
  }
619
550
  /**
620
- * Removes all transactions from state, optionally based on the current network.
551
+ * Remove transactions from state.
621
552
  *
622
- * @param ignoreNetwork - Determines whether to wipe all transactions, or just those on the
623
- * current network. If `true`, all transactions are wiped.
624
- * @param address - If specified, only transactions originating from this address will be
625
- * wiped on current network.
553
+ * @param options - The options bag.
554
+ * @param options.address - Remove transactions from this account only. Defaults to all accounts.
555
+ * @param options.chainId - Remove transactions for the specified chain only. Defaults to all chains.
626
556
  */
627
- wipeTransactions(ignoreNetwork, address) {
628
- /* istanbul ignore next */
629
- if (ignoreNetwork && !address) {
557
+ wipeTransactions({ address, chainId, } = {}) {
558
+ if (!chainId && !address) {
630
559
  this.update((state) => {
631
560
  state.transactions = [];
632
561
  });
633
562
  return;
634
563
  }
635
- const currentChainId = this.getChainId();
636
- const newTransactions = this.state.transactions.filter(({ chainId, txParams }) => {
637
- const isMatchingNetwork = ignoreNetwork || chainId === currentChainId;
564
+ const newTransactions = this.state.transactions.filter(({ chainId: txChainId, txParams }) => {
565
+ const isMatchingNetwork = !chainId || chainId === txChainId;
638
566
  if (!isMatchingNetwork) {
639
567
  return true;
640
568
  }
@@ -824,10 +752,8 @@ export class TransactionController extends BaseController {
824
752
  };
825
753
  editableParams.txParams = pickBy(editableParams.txParams);
826
754
  const updatedTransaction = merge({}, transactionMeta, editableParams);
827
- const provider = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getProvider({
828
- chainId: transactionMeta.chainId,
829
- networkClientId: transactionMeta.networkClientId,
830
- });
755
+ const { networkClientId } = transactionMeta;
756
+ const provider = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getProvider).call(this, { networkClientId });
831
757
  const ethQuery = new EthQuery(provider);
832
758
  const { type } = await determineTransactionType(updatedTransaction.txParams, ethQuery);
833
759
  updatedTransaction.type = type;
@@ -855,19 +781,9 @@ export class TransactionController extends BaseController {
855
781
  return '';
856
782
  }
857
783
  const initialTx = listOfTxParams[0];
858
- const common = this.getCommonConfiguration(initialTx.chainId);
859
- // We need to ensure we get the nonce using the the NonceTracker on the chain matching
860
- // the txParams. In this context we only have chainId available to us, but the
861
- // NonceTrackers are keyed by networkClientId. To workaround this, we attempt to find
862
- // a networkClientId that matches the chainId. As a fallback, the globally selected
863
- // network's NonceTracker will be used instead.
864
- let networkClientId;
865
- try {
866
- networkClientId = this.messagingSystem.call(`NetworkController:findNetworkClientIdByChainId`, initialTx.chainId);
867
- }
868
- catch (err) {
869
- log('failed to find networkClientId from chainId', err);
870
- }
784
+ const { chainId } = initialTx;
785
+ const common = this.getCommonConfiguration(chainId);
786
+ const networkClientId = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getNetworkClientId).call(this, { chainId });
871
787
  const initialTxAsEthTx = TransactionFactory.fromTxData(initialTx, {
872
788
  common,
873
789
  });
@@ -949,14 +865,12 @@ export class TransactionController extends BaseController {
949
865
  * Search transaction metadata for matching entries.
950
866
  *
951
867
  * @param opts - Options bag.
952
- * @param opts.searchCriteria - An object containing values or functions for transaction properties to filter transactions with.
953
868
  * @param opts.initialList - The transactions to search. Defaults to the current state.
954
- * @param opts.filterToCurrentNetwork - Whether to filter the results to the current network. Defaults to true.
955
869
  * @param opts.limit - The maximum number of transactions to return. No limit by default.
870
+ * @param opts.searchCriteria - An object containing values or functions for transaction properties to filter transactions with.
956
871
  * @returns An array of transactions matching the provided options.
957
872
  */
958
- getTransactions({ searchCriteria = {}, initialList, filterToCurrentNetwork = true, limit, } = {}) {
959
- const chainId = this.getChainId();
873
+ getTransactions({ initialList, limit, searchCriteria = {}, } = {}) {
960
874
  // searchCriteria is an object that might have values that aren't predicate
961
875
  // methods. When providing any other value type (string, number, etc), we
962
876
  // consider this shorthand for "check the value at key for strict equality
@@ -974,9 +888,6 @@ export class TransactionController extends BaseController {
974
888
  // Combine sortBy and pickBy to transform our state object into an array of
975
889
  // matching transactions that are sorted by time.
976
890
  const filteredTransactions = sortBy(pickBy(transactionsToFilter, (transaction) => {
977
- if (filterToCurrentNetwork && transaction.chainId !== chainId) {
978
- return false;
979
- }
980
891
  // iterate over the predicateMethods keys to check if the transaction
981
892
  // matches the searchCriteria
982
893
  for (const [key, predicate] of Object.entries(predicateMethods)) {
@@ -1032,9 +943,9 @@ export class TransactionController extends BaseController {
1032
943
  return filteredTransactions;
1033
944
  }
1034
945
  async estimateGasFee({ transactionParams, chainId, networkClientId: requestNetworkClientId, }) {
1035
- const networkClientId = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getNetworkClientId).call(this, {
1036
- networkClientId: requestNetworkClientId,
946
+ const { id: networkClientId, provider } = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNetworkClient({
1037
947
  chainId,
948
+ networkClientId: requestNetworkClientId,
1038
949
  });
1039
950
  const transactionMeta = {
1040
951
  txParams: transactionParams,
@@ -1043,10 +954,7 @@ export class TransactionController extends BaseController {
1043
954
  };
1044
955
  // Guaranteed as the default gas fee flow matches all transactions.
1045
956
  const gasFeeFlow = getGasFeeFlow(transactionMeta, this.gasFeeFlows);
1046
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
1047
- networkClientId,
1048
- chainId,
1049
- });
957
+ const ethQuery = new EthQuery(provider);
1050
958
  const gasFeeControllerData = await this.getGasFeeEstimates({
1051
959
  networkClientId,
1052
960
  });
@@ -1065,9 +973,9 @@ export class TransactionController extends BaseController {
1065
973
  * @param request.networkClientId - The ID of a specific network client to process the transaction.
1066
974
  */
1067
975
  async getLayer1GasFee({ transactionParams, chainId, networkClientId, }) {
1068
- const provider = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getProvider({
1069
- networkClientId,
976
+ const provider = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getProvider).call(this, {
1070
977
  chainId,
978
+ networkClientId,
1071
979
  });
1072
980
  return await getTransactionLayer1GasFee({
1073
981
  layer1GasFeeFlows: this.layer1GasFeeFlows,
@@ -1138,15 +1046,10 @@ export class TransactionController extends BaseController {
1138
1046
  const isEIP1559Compatible = transactionMeta.txParams.type !== TransactionEnvelopeType.legacy &&
1139
1047
  (await this.getEIP1559Compatibility(transactionMeta.networkClientId));
1140
1048
  const { networkClientId, chainId } = transactionMeta;
1141
- const isCustomNetwork = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_isCustomNetwork).call(this, networkClientId);
1142
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
1143
- networkClientId,
1144
- chainId,
1145
- });
1146
- const provider = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getProvider({
1147
- networkClientId,
1148
- chainId,
1149
- });
1049
+ const isCustomNetwork = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNetworkClient({ networkClientId })
1050
+ .configuration.type === NetworkClientType.Custom;
1051
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId });
1052
+ const provider = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getProvider).call(this, { networkClientId });
1150
1053
  await __classPrivateFieldGet(this, _TransactionController_trace, "f").call(this, { name: 'Update Gas', parentContext: traceContext }, async () => {
1151
1054
  await updateGas({
1152
1055
  ethQuery,
@@ -1304,10 +1207,8 @@ export class TransactionController extends BaseController {
1304
1207
  if (!rawTx) {
1305
1208
  return ApprovalState.NotApproved;
1306
1209
  }
1307
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
1308
- networkClientId: transactionMeta.networkClientId,
1309
- chainId: transactionMeta.chainId,
1310
- });
1210
+ const { networkClientId } = transactionMeta;
1211
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId });
1311
1212
  let preTxBalance;
1312
1213
  const shouldUpdatePreTxBalance = transactionMeta.type === TransactionType.swap;
1313
1214
  if (shouldUpdatePreTxBalance) {
@@ -1501,14 +1402,6 @@ export class TransactionController extends BaseController {
1501
1402
  const isCompleted = this.isLocalFinalState(transaction.status);
1502
1403
  return { meta: transaction, isCompleted };
1503
1404
  }
1504
- getChainId(networkClientId) {
1505
- const globalChainId = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getGlobalChainId).call(this);
1506
- const globalNetworkClientId = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getGlobalNetworkClientId).call(this);
1507
- if (!networkClientId || networkClientId === globalNetworkClientId) {
1508
- return globalChainId;
1509
- }
1510
- return this.messagingSystem.call(`NetworkController:getNetworkClientById`, networkClientId).configuration.chainId;
1511
- }
1512
1405
  prepareUnsignedEthTx(chainId, txParams) {
1513
1406
  return TransactionFactory.fromTxData(txParams, {
1514
1407
  freeze: false,
@@ -1534,14 +1427,16 @@ export class TransactionController extends BaseController {
1534
1427
  }
1535
1428
  onIncomingTransactions({ added, updated, }) {
1536
1429
  this.update((state) => {
1537
- const { transactions: currentTransactions } = state;
1538
- const updatedTransactions = [
1539
- ...added,
1540
- ...currentTransactions.map((originalTransaction) => {
1541
- const updatedTransaction = updated.find(({ hash }) => hash === originalTransaction.hash);
1542
- return updatedTransaction ?? originalTransaction;
1543
- }),
1544
- ];
1430
+ const { transactions } = state;
1431
+ const existingTransactions = transactions.map((tx) => updated.find(({ hash }) => hash === tx.hash) ?? tx);
1432
+ const updatedTransactions = [...added, ...existingTransactions].map((tx) => {
1433
+ const { chainId } = tx;
1434
+ const networkClientId = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getNetworkClientId).call(this, { chainId });
1435
+ return {
1436
+ ...tx,
1437
+ networkClientId,
1438
+ };
1439
+ });
1545
1440
  state.transactions = this.trimTransactionsForState(updatedTransactions);
1546
1441
  });
1547
1442
  }
@@ -1734,7 +1629,7 @@ export class TransactionController extends BaseController {
1734
1629
  transactionMeta,
1735
1630
  });
1736
1631
  }
1737
- getNonceTrackerTransactions(status, address, chainId = this.getChainId()) {
1632
+ getNonceTrackerTransactions(status, address, chainId) {
1738
1633
  return getAndFormatTransactionsForNonceTracker(chainId, address, status, this.state.transactions);
1739
1634
  }
1740
1635
  onConfirmedTransaction(transactionMeta) {
@@ -1750,13 +1645,11 @@ export class TransactionController extends BaseController {
1750
1645
  }
1751
1646
  async updatePostBalance(transactionMeta) {
1752
1647
  try {
1753
- if (transactionMeta.type !== TransactionType.swap) {
1648
+ const { networkClientId, type } = transactionMeta;
1649
+ if (type !== TransactionType.swap) {
1754
1650
  return;
1755
1651
  }
1756
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
1757
- networkClientId: transactionMeta.networkClientId,
1758
- chainId: transactionMeta.chainId,
1759
- });
1652
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId });
1760
1653
  const { updatedTransactionMeta, approvalTransactionMeta } = await updatePostTransactionBalance(transactionMeta, {
1761
1654
  ethQuery,
1762
1655
  getTransaction: this.getTransaction.bind(this),
@@ -1778,7 +1671,6 @@ export class TransactionController extends BaseController {
1778
1671
  }
1779
1672
  catch (error) {
1780
1673
  if (this.isTransactionAlreadyConfirmedError(error)) {
1781
- await this.pendingTransactionTracker.forceCheckTransaction(transactionMeta);
1782
1674
  throw new Error('Previous transaction is already confirmed');
1783
1675
  }
1784
1676
  throw error;
@@ -1798,7 +1690,7 @@ export class TransactionController extends BaseController {
1798
1690
  error?.data?.message?.includes('nonce too low'));
1799
1691
  }
1800
1692
  }
1801
- _TransactionController_internalEvents = new WeakMap(), _TransactionController_incomingTransactionOptions = new WeakMap(), _TransactionController_pendingTransactionOptions = new WeakMap(), _TransactionController_trace = new WeakMap(), _TransactionController_transactionHistoryLimit = new WeakMap(), _TransactionController_isFirstTimeInteractionEnabled = new WeakMap(), _TransactionController_isSimulationEnabled = new WeakMap(), _TransactionController_testGasFeeFlows = new WeakMap(), _TransactionController_multichainTrackingHelper = new WeakMap(), _TransactionController_checkForPendingTransactionAndStartPolling = new WeakMap(), _TransactionController_instances = new WeakSet(), _TransactionController_retryTransaction = async function _TransactionController_retryTransaction({ actionId, afterSubmit, estimatedBaseFee, gasValues, label, prepareTransactionParams, rate, transactionId, transactionType, }) {
1693
+ _TransactionController_internalEvents = new WeakMap(), _TransactionController_methodDataHelper = new WeakMap(), _TransactionController_incomingTransactionOptions = new WeakMap(), _TransactionController_pendingTransactionOptions = new WeakMap(), _TransactionController_trace = new WeakMap(), _TransactionController_transactionHistoryLimit = new WeakMap(), _TransactionController_isFirstTimeInteractionEnabled = new WeakMap(), _TransactionController_isSimulationEnabled = new WeakMap(), _TransactionController_testGasFeeFlows = new WeakMap(), _TransactionController_multichainTrackingHelper = new WeakMap(), _TransactionController_checkForPendingTransactionAndStartPolling = new WeakMap(), _TransactionController_instances = new WeakSet(), _TransactionController_retryTransaction = async function _TransactionController_retryTransaction({ actionId, afterSubmit, estimatedBaseFee, gasValues, label, prepareTransactionParams, rate, transactionId, transactionType, }) {
1802
1694
  // If transaction is found for same action id, do not create a new transaction.
1803
1695
  if (this.getTransactionWithActionId(actionId)) {
1804
1696
  return;
@@ -1833,10 +1725,8 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
1833
1725
  newFee,
1834
1726
  txParams: newTxParams,
1835
1727
  });
1836
- const ethQuery = __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getEthQuery({
1837
- networkClientId: transactionMeta.networkClientId,
1838
- chainId: transactionMeta.chainId,
1839
- });
1728
+ const { networkClientId } = transactionMeta;
1729
+ const ethQuery = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getEthQuery).call(this, { networkClientId });
1840
1730
  const newTransactionMeta = {
1841
1731
  ...transactionMetaWithRsv,
1842
1732
  actionId,
@@ -1865,6 +1755,23 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
1865
1755
  actionId,
1866
1756
  });
1867
1757
  afterSubmit?.(newTransactionMeta);
1758
+ }, _TransactionController_getChainId = function _TransactionController_getChainId(networkClientId) {
1759
+ return __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNetworkClient({ networkClientId })
1760
+ .configuration.chainId;
1761
+ }, _TransactionController_getNetworkClientId = function _TransactionController_getNetworkClientId({ chainId, networkClientId, }) {
1762
+ if (networkClientId) {
1763
+ return networkClientId;
1764
+ }
1765
+ return __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNetworkClient({
1766
+ chainId,
1767
+ }).id;
1768
+ }, _TransactionController_getEthQuery = function _TransactionController_getEthQuery({ chainId, networkClientId, }) {
1769
+ return new EthQuery(__classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getProvider).call(this, { chainId, networkClientId }));
1770
+ }, _TransactionController_getProvider = function _TransactionController_getProvider({ chainId, networkClientId, }) {
1771
+ return __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").getNetworkClient({
1772
+ chainId,
1773
+ networkClientId,
1774
+ }).provider;
1868
1775
  }, _TransactionController_createNonceTracker = function _TransactionController_createNonceTracker({ provider, blockTracker, chainId, }) {
1869
1776
  return new NonceTracker({
1870
1777
  // TODO: Fix types
@@ -1873,18 +1780,23 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
1873
1780
  // TODO: Fix types
1874
1781
  blockTracker,
1875
1782
  getPendingTransactions: __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getNonceTrackerPendingTransactions).bind(this, chainId),
1876
- getConfirmedTransactions: this.getNonceTrackerTransactions.bind(this, TransactionStatus.confirmed),
1783
+ getConfirmedTransactions: this.getNonceTrackerTransactions.bind(this, TransactionStatus.confirmed, chainId),
1877
1784
  });
1878
- }, _TransactionController_createIncomingTransactionHelper = function _TransactionController_createIncomingTransactionHelper({ blockTracker, etherscanRemoteTransactionSource, chainId, }) {
1785
+ }, _TransactionController_createRemoteTransactionSource = function _TransactionController_createRemoteTransactionSource() {
1786
+ return new EtherscanRemoteTransactionSource({
1787
+ apiKeysByChainId: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").etherscanApiKeysByChainId,
1788
+ includeTokenTransfers: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").includeTokenTransfers,
1789
+ });
1790
+ }, _TransactionController_createIncomingTransactionHelper = function _TransactionController_createIncomingTransactionHelper({ blockTracker, remoteTransactionSource, chainId, }) {
1879
1791
  const incomingTransactionHelper = new IncomingTransactionHelper({
1880
1792
  blockTracker,
1881
1793
  getCurrentAccount: () => __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getSelectedAccount).call(this),
1882
1794
  getLastFetchedBlockNumbers: () => this.state.lastFetchedBlockNumbers,
1883
1795
  getLocalTransactions: () => this.state.transactions,
1884
- getChainId: chainId ? () => chainId : this.getChainId.bind(this),
1796
+ getChainId: () => chainId,
1885
1797
  isEnabled: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").isEnabled,
1886
1798
  queryEntireHistory: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").queryEntireHistory,
1887
- remoteTransactionSource: etherscanRemoteTransactionSource,
1799
+ remoteTransactionSource,
1888
1800
  transactionLimit: __classPrivateFieldGet(this, _TransactionController_transactionHistoryLimit, "f"),
1889
1801
  updateTransactions: __classPrivateFieldGet(this, _TransactionController_incomingTransactionOptions, "f").updateTransactions,
1890
1802
  });
@@ -1892,15 +1804,14 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
1892
1804
  return incomingTransactionHelper;
1893
1805
  }, _TransactionController_createPendingTransactionTracker = function _TransactionController_createPendingTransactionTracker({ provider, blockTracker, chainId, }) {
1894
1806
  const ethQuery = new EthQuery(provider);
1895
- const getChainId = chainId ? () => chainId : this.getChainId.bind(this);
1896
1807
  const pendingTransactionTracker = new PendingTransactionTracker({
1897
1808
  blockTracker,
1898
- getChainId,
1809
+ getChainId: () => chainId,
1899
1810
  getEthQuery: () => ethQuery,
1900
1811
  getTransactions: () => this.state.transactions,
1901
1812
  isResubmitEnabled: __classPrivateFieldGet(this, _TransactionController_pendingTransactionOptions, "f").isResubmitEnabled,
1902
1813
  getGlobalLock: () => __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").acquireNonceLockForChainIdKey({
1903
- chainId: getChainId(),
1814
+ chainId,
1904
1815
  }),
1905
1816
  publishTransaction: (_ethQuery, transactionMeta) => this.publishTransaction(_ethQuery, transactionMeta, {
1906
1817
  skipSubmitHistory: true,
@@ -1913,10 +1824,6 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
1913
1824
  __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_addPendingTransactionTrackerListeners).call(this, pendingTransactionTracker);
1914
1825
  return pendingTransactionTracker;
1915
1826
  }, _TransactionController_stopAllTracking = function _TransactionController_stopAllTracking() {
1916
- this.pendingTransactionTracker.stop();
1917
- __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_removePendingTransactionTrackerListeners).call(this, this.pendingTransactionTracker);
1918
- this.incomingTransactionHelper.stop();
1919
- __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_removeIncomingTransactionHelperListeners).call(this, this.incomingTransactionHelper);
1920
1827
  __classPrivateFieldGet(this, _TransactionController_multichainTrackingHelper, "f").stopAllTracking();
1921
1828
  }, _TransactionController_removeIncomingTransactionHelperListeners = function _TransactionController_removeIncomingTransactionHelperListeners(incomingTransactionHelper) {
1922
1829
  incomingTransactionHelper.hub.removeAllListeners('transactions');
@@ -2073,26 +1980,6 @@ _TransactionController_internalEvents = new WeakMap(), _TransactionController_in
2073
1980
  txMeta.layer1GasFee = layer1GasFee;
2074
1981
  }
2075
1982
  });
2076
- }, _TransactionController_getNetworkClientId = function _TransactionController_getNetworkClientId({ networkClientId: requestNetworkClientId, chainId, }) {
2077
- const globalChainId = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getGlobalChainId).call(this);
2078
- const globalNetworkClientId = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getGlobalNetworkClientId).call(this);
2079
- if (requestNetworkClientId) {
2080
- return requestNetworkClientId;
2081
- }
2082
- if (!chainId || chainId === globalChainId) {
2083
- return globalNetworkClientId;
2084
- }
2085
- return this.messagingSystem.call(`NetworkController:findNetworkClientIdByChainId`, chainId);
2086
- }, _TransactionController_getGlobalNetworkClientId = function _TransactionController_getGlobalNetworkClientId() {
2087
- return this.getNetworkState().selectedNetworkClientId;
2088
- }, _TransactionController_getGlobalChainId = function _TransactionController_getGlobalChainId() {
2089
- return this.messagingSystem.call(`NetworkController:getNetworkClientById`, this.getNetworkState().selectedNetworkClientId).configuration.chainId;
2090
- }, _TransactionController_isCustomNetwork = function _TransactionController_isCustomNetwork(networkClientId) {
2091
- const globalNetworkClientId = __classPrivateFieldGet(this, _TransactionController_instances, "m", _TransactionController_getGlobalNetworkClientId).call(this);
2092
- if (!networkClientId || networkClientId === globalNetworkClientId) {
2093
- return !isInfuraNetworkType(this.getNetworkState().selectedNetworkClientId);
2094
- }
2095
- return (this.messagingSystem.call(`NetworkController:getNetworkClientById`, networkClientId).configuration.type === NetworkClientType.Custom);
2096
1983
  }, _TransactionController_getSelectedAccount = function _TransactionController_getSelectedAccount() {
2097
1984
  return this.messagingSystem.call('AccountsController:getSelectedAccount');
2098
1985
  }, _TransactionController_updateSubmitHistory = function _TransactionController_updateSubmitHistory(transactionMeta, hash) {