@metamask-previews/smart-transactions-controller 19.2.1-preview-54c655a

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 (44) hide show
  1. package/CHANGELOG.md +715 -0
  2. package/LICENSE +18 -0
  3. package/README.md +103 -0
  4. package/dist/SmartTransactionsController.cjs +694 -0
  5. package/dist/SmartTransactionsController.cjs.map +1 -0
  6. package/dist/SmartTransactionsController.d.cts +150 -0
  7. package/dist/SmartTransactionsController.d.cts.map +1 -0
  8. package/dist/SmartTransactionsController.d.mts +150 -0
  9. package/dist/SmartTransactionsController.d.mts.map +1 -0
  10. package/dist/SmartTransactionsController.mjs +702 -0
  11. package/dist/SmartTransactionsController.mjs.map +1 -0
  12. package/dist/constants.cjs +33 -0
  13. package/dist/constants.cjs.map +1 -0
  14. package/dist/constants.d.cts +23 -0
  15. package/dist/constants.d.cts.map +1 -0
  16. package/dist/constants.d.mts +23 -0
  17. package/dist/constants.d.mts.map +1 -0
  18. package/dist/constants.mjs +33 -0
  19. package/dist/constants.mjs.map +1 -0
  20. package/dist/index.cjs +17 -0
  21. package/dist/index.cjs.map +1 -0
  22. package/dist/index.d.cts +6 -0
  23. package/dist/index.d.cts.map +1 -0
  24. package/dist/index.d.mts +6 -0
  25. package/dist/index.d.mts.map +1 -0
  26. package/dist/index.mjs +17 -0
  27. package/dist/index.mjs.map +1 -0
  28. package/dist/types.cjs +54 -0
  29. package/dist/types.cjs.map +1 -0
  30. package/dist/types.d.cts +118 -0
  31. package/dist/types.d.cts.map +1 -0
  32. package/dist/types.d.mts +118 -0
  33. package/dist/types.d.mts.map +1 -0
  34. package/dist/types.mjs +54 -0
  35. package/dist/types.mjs.map +1 -0
  36. package/dist/utils.cjs +281 -0
  37. package/dist/utils.cjs.map +1 -0
  38. package/dist/utils.d.cts +90 -0
  39. package/dist/utils.d.cts.map +1 -0
  40. package/dist/utils.d.mts +90 -0
  41. package/dist/utils.d.mts.map +1 -0
  42. package/dist/utils.mjs +289 -0
  43. package/dist/utils.mjs.map +1 -0
  44. package/package.json +135 -0
@@ -0,0 +1,702 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ 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");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ 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");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _SmartTransactionsController_instances, _SmartTransactionsController_interval, _SmartTransactionsController_clientId, _SmartTransactionsController_chainId, _SmartTransactionsController_supportedChainIds, _SmartTransactionsController_ethQuery, _SmartTransactionsController_trackMetaMetricsEvent, _SmartTransactionsController_getMetaMetricsProps, _SmartTransactionsController_getFeatureFlags, _SmartTransactionsController_trace, _SmartTransactionsController_fetch, _SmartTransactionsController_updateSmartTransaction, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction, _SmartTransactionsController_createOrUpdateSmartTransaction, _SmartTransactionsController_doesTransactionNeedConfirmation, _SmartTransactionsController_confirmSmartTransaction, _SmartTransactionsController_addNonceToTransaction, _SmartTransactionsController_getChainId, _SmartTransactionsController_getChainIds, _SmartTransactionsController_getNetworkClientId, _SmartTransactionsController_getEthQuery, _SmartTransactionsController_getCurrentSmartTransactions, _SmartTransactionsController_wipeSmartTransactionsPerChainId;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.SmartTransactionsController = exports.getDefaultSmartTransactionsControllerState = exports.DEFAULT_INTERVAL = void 0;
19
+ function $importDefault(module) {
20
+ if (module === null || module === void 0 ? void 0 : module.__esModule) {
21
+ return module.default;
22
+ }
23
+ return module;
24
+ }
25
+ const bytes_1 = require("@ethersproject/bytes");
26
+ const controller_utils_1 = require("@metamask/controller-utils");
27
+ const eth_query_1 = __importDefault(require("@metamask/eth-query"));
28
+ const EthQuery = $importDefault($EthQuery);
29
+ const polling_controller_1 = require("@metamask/polling-controller");
30
+ const transaction_controller_1 = require("@metamask/transaction-controller");
31
+ const bignumber_js_1 = require("bignumber.js");
32
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep.js"));
33
+ const cloneDeep = $importDefault($cloneDeep);
34
+ const constants_1 = require("./constants.mjs");
35
+ const types_1 = require("./types.mjs");
36
+ const utils_1 = require("./utils.mjs");
37
+ const SECOND = 1000;
38
+ exports.DEFAULT_INTERVAL = SECOND * 5;
39
+ const ETH_QUERY_ERROR_MSG = '`ethQuery` is not defined on SmartTransactionsController';
40
+ /**
41
+ * The name of the {@link SmartTransactionsController}
42
+ */
43
+ const controllerName = 'SmartTransactionsController';
44
+ const controllerMetadata = {
45
+ smartTransactionsState: {
46
+ includeInStateLogs: true,
47
+ persist: false,
48
+ includeInDebugSnapshot: true,
49
+ usedInUi: true,
50
+ },
51
+ };
52
+ /**
53
+ * Get the default {@link SmartTransactionsController} state.
54
+ *
55
+ * @returns The default {@link SmartTransactionsController} state.
56
+ */
57
+ function getDefaultSmartTransactionsControllerState() {
58
+ return {
59
+ smartTransactionsState: {
60
+ smartTransactions: {},
61
+ userOptIn: null,
62
+ userOptInV2: null,
63
+ fees: {
64
+ approvalTxFees: null,
65
+ tradeTxFees: null,
66
+ },
67
+ liveness: true,
68
+ livenessByChainId: {
69
+ [controller_utils_1.ChainId.mainnet]: true,
70
+ [controller_utils_1.ChainId.sepolia]: true,
71
+ },
72
+ feesByChainId: {
73
+ [controller_utils_1.ChainId.mainnet]: {
74
+ approvalTxFees: null,
75
+ tradeTxFees: null,
76
+ },
77
+ [controller_utils_1.ChainId.sepolia]: {
78
+ approvalTxFees: null,
79
+ tradeTxFees: null,
80
+ },
81
+ },
82
+ },
83
+ };
84
+ }
85
+ exports.getDefaultSmartTransactionsControllerState = getDefaultSmartTransactionsControllerState;
86
+ class SmartTransactionsController extends (0, polling_controller_1.StaticIntervalPollingController)() {
87
+ constructor({ interval = exports.DEFAULT_INTERVAL, clientId, chainId: InitialChainId = controller_utils_1.ChainId.mainnet, supportedChainIds = [controller_utils_1.ChainId.mainnet, controller_utils_1.ChainId.sepolia], trackMetaMetricsEvent, state = {}, messenger, getMetaMetricsProps, getFeatureFlags, trace, }) {
88
+ super({
89
+ name: controllerName,
90
+ metadata: controllerMetadata,
91
+ messenger,
92
+ state: Object.assign(Object.assign({}, getDefaultSmartTransactionsControllerState()), state),
93
+ });
94
+ _SmartTransactionsController_instances.add(this);
95
+ _SmartTransactionsController_interval.set(this, void 0);
96
+ _SmartTransactionsController_clientId.set(this, void 0);
97
+ _SmartTransactionsController_chainId.set(this, void 0);
98
+ _SmartTransactionsController_supportedChainIds.set(this, void 0);
99
+ _SmartTransactionsController_ethQuery.set(this, void 0);
100
+ _SmartTransactionsController_trackMetaMetricsEvent.set(this, void 0);
101
+ _SmartTransactionsController_getMetaMetricsProps.set(this, void 0);
102
+ _SmartTransactionsController_getFeatureFlags.set(this, void 0);
103
+ _SmartTransactionsController_trace.set(this, void 0);
104
+ __classPrivateFieldSet(this, _SmartTransactionsController_interval, interval, "f");
105
+ __classPrivateFieldSet(this, _SmartTransactionsController_clientId, clientId, "f");
106
+ __classPrivateFieldSet(this, _SmartTransactionsController_chainId, InitialChainId, "f");
107
+ __classPrivateFieldSet(this, _SmartTransactionsController_supportedChainIds, supportedChainIds, "f");
108
+ this.setIntervalLength(interval);
109
+ __classPrivateFieldSet(this, _SmartTransactionsController_ethQuery, undefined, "f");
110
+ __classPrivateFieldSet(this, _SmartTransactionsController_trackMetaMetricsEvent, trackMetaMetricsEvent, "f");
111
+ __classPrivateFieldSet(this, _SmartTransactionsController_getMetaMetricsProps, getMetaMetricsProps, "f");
112
+ __classPrivateFieldSet(this, _SmartTransactionsController_getFeatureFlags, getFeatureFlags, "f");
113
+ __classPrivateFieldSet(this, _SmartTransactionsController_trace, trace !== null && trace !== void 0 ? trace : ((_request, fn) => fn === null || fn === void 0 ? void 0 : fn()), "f");
114
+ this.initializeSmartTransactionsForChainId();
115
+ this.messenger.subscribe('NetworkController:stateChange', ({ selectedNetworkClientId }) => {
116
+ const { configuration: { chainId }, provider, } = this.messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
117
+ __classPrivateFieldSet(this, _SmartTransactionsController_chainId, chainId, "f");
118
+ __classPrivateFieldSet(this, _SmartTransactionsController_ethQuery, new eth_query_1.default(provider), "f");
119
+ this.initializeSmartTransactionsForChainId();
120
+ this.checkPoll(this.state);
121
+ });
122
+ this.messenger.subscribe(`${controllerName}:stateChange`, (currentState) => this.checkPoll(currentState));
123
+ }
124
+ async _executePoll({ chainIds, }) {
125
+ // if this is going to be truly UI driven polling we shouldn't really reach here
126
+ // with a networkClientId that is not supported, but for now I'll add a check in case
127
+ // wondering if we should add some kind of predicate to the polling controller to check whether
128
+ // we should poll or not
129
+ const filteredChainIds = (chainIds !== null && chainIds !== void 0 ? chainIds : []).filter((chainId) => __classPrivateFieldGet(this, _SmartTransactionsController_supportedChainIds, "f").includes(chainId));
130
+ if (filteredChainIds.length === 0) {
131
+ return Promise.resolve();
132
+ }
133
+ return this.updateSmartTransactions({ chainIds: filteredChainIds });
134
+ }
135
+ checkPoll({ smartTransactionsState: { smartTransactions }, }) {
136
+ const smartTransactionsForAllChains = Object.values(smartTransactions).flat();
137
+ const pendingTransactions = smartTransactionsForAllChains === null || smartTransactionsForAllChains === void 0 ? void 0 : smartTransactionsForAllChains.filter(utils_1.isSmartTransactionPending);
138
+ if (!this.timeoutHandle && (pendingTransactions === null || pendingTransactions === void 0 ? void 0 : pendingTransactions.length) > 0) {
139
+ this.poll();
140
+ }
141
+ else if (this.timeoutHandle && (pendingTransactions === null || pendingTransactions === void 0 ? void 0 : pendingTransactions.length) === 0) {
142
+ this.stop();
143
+ }
144
+ }
145
+ initializeSmartTransactionsForChainId() {
146
+ if (__classPrivateFieldGet(this, _SmartTransactionsController_supportedChainIds, "f").includes(__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"))) {
147
+ this.update((state) => {
148
+ var _a;
149
+ state.smartTransactionsState.smartTransactions[__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")] =
150
+ (_a = state.smartTransactionsState.smartTransactions[__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")]) !== null && _a !== void 0 ? _a : [];
151
+ });
152
+ }
153
+ }
154
+ async poll(interval) {
155
+ if (interval) {
156
+ __classPrivateFieldSet(this, _SmartTransactionsController_interval, interval, "f");
157
+ }
158
+ this.timeoutHandle && clearInterval(this.timeoutHandle);
159
+ if (!__classPrivateFieldGet(this, _SmartTransactionsController_supportedChainIds, "f").includes(__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"))) {
160
+ return;
161
+ }
162
+ this.timeoutHandle = setInterval(() => {
163
+ (0, controller_utils_1.safelyExecute)(async () => this.updateSmartTransactions());
164
+ }, __classPrivateFieldGet(this, _SmartTransactionsController_interval, "f"));
165
+ await (0, controller_utils_1.safelyExecute)(async () => this.updateSmartTransactions());
166
+ }
167
+ async stop() {
168
+ this.timeoutHandle && clearInterval(this.timeoutHandle);
169
+ this.timeoutHandle = undefined;
170
+ }
171
+ setOptInState(optInState) {
172
+ this.update((state) => {
173
+ state.smartTransactionsState.userOptInV2 = optInState;
174
+ });
175
+ }
176
+ trackStxStatusChange(smartTransaction, prevSmartTransaction) {
177
+ let updatedSmartTransaction = (0, cloneDeep_1.default)(smartTransaction);
178
+ updatedSmartTransaction = Object.assign(Object.assign({}, (0, cloneDeep_1.default)(prevSmartTransaction)), updatedSmartTransaction);
179
+ if (updatedSmartTransaction.status === (prevSmartTransaction === null || prevSmartTransaction === void 0 ? void 0 : prevSmartTransaction.status)) {
180
+ return; // If status hasn't changed, don't track it again.
181
+ }
182
+ __classPrivateFieldGet(this, _SmartTransactionsController_trackMetaMetricsEvent, "f").call(this, {
183
+ event: constants_1.MetaMetricsEventName.StxStatusUpdated,
184
+ category: constants_1.MetaMetricsEventCategory.Transactions,
185
+ properties: (0, utils_1.getSmartTransactionMetricsProperties)(updatedSmartTransaction),
186
+ sensitiveProperties: (0, utils_1.getSmartTransactionMetricsSensitiveProperties)(updatedSmartTransaction),
187
+ });
188
+ }
189
+ isNewSmartTransaction(smartTransactionUuid, chainId) {
190
+ const { smartTransactionsState: { smartTransactions }, } = this.state;
191
+ const currentSmartTransactions = smartTransactions[chainId !== null && chainId !== void 0 ? chainId : __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")];
192
+ const currentIndex = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.findIndex((stx) => stx.uuid === smartTransactionUuid);
193
+ return currentIndex === -1 || currentIndex === undefined;
194
+ }
195
+ updateSmartTransaction(smartTransaction, { networkClientId } = {}) {
196
+ let ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f");
197
+ let chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f");
198
+ if (networkClientId) {
199
+ const { configuration, provider } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
200
+ chainId = configuration.chainId;
201
+ ethQuery = new eth_query_1.default(provider);
202
+ }
203
+ __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_createOrUpdateSmartTransaction).call(this, smartTransaction, {
204
+ chainId,
205
+ ethQuery,
206
+ });
207
+ }
208
+ async updateSmartTransactions({ chainIds, } = {
209
+ chainIds: __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainIds).call(this),
210
+ }) {
211
+ const { smartTransactionsState: { smartTransactions }, } = this.state;
212
+ // Iterate over each chain group directly
213
+ for (const [chainId, transactions] of Object.entries(smartTransactions)) {
214
+ if (chainIds && !chainIds.includes(chainId)) {
215
+ continue;
216
+ }
217
+ // Filter pending transactions and map them to the desired shape
218
+ const pendingTransactions = transactions
219
+ .filter(utils_1.isSmartTransactionPending)
220
+ .map((pendingSmartTransaction) => {
221
+ // Use the transaction's chainId (from the key) to derive a networkClientId
222
+ const networkClientIdToUse = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getNetworkClientId).call(this, {
223
+ chainId: chainId,
224
+ });
225
+ return {
226
+ uuid: pendingSmartTransaction.uuid,
227
+ networkClientId: networkClientIdToUse,
228
+ chainId: pendingSmartTransaction.chainId, // same as the key, but explicit on the transaction
229
+ };
230
+ });
231
+ if (pendingTransactions.length > 0) {
232
+ // Since each group is per chain, all transactions share the same chainId.
233
+ await this.fetchSmartTransactionsStatus(pendingTransactions);
234
+ }
235
+ }
236
+ }
237
+ // ! Ask backend API to accept list of uuids as params
238
+ async fetchSmartTransactionsStatus(transactions) {
239
+ // Since transactions come from the same chain group, take the chainId from the first one.
240
+ const { chainId } = transactions[0];
241
+ // Build query parameters with all UUIDs
242
+ const uuids = transactions.map((tx) => tx.uuid);
243
+ const params = new URLSearchParams({ uuids: uuids.join(',') });
244
+ // Get the ethQuery for the first transaction's networkClientId
245
+ const ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getEthQuery).call(this, {
246
+ networkClientId: transactions[0].networkClientId,
247
+ });
248
+ // Construct the URL and fetch the data
249
+ const url = `${(0, utils_1.getAPIRequestURL)(types_1.APIType.BATCH_STATUS, chainId)}?${params.toString()}`;
250
+ const data = (await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, url));
251
+ // Process each returned status
252
+ for (const [uuid, stxStatus] of Object.entries(data)) {
253
+ const matchingTx = transactions.find((tx) => tx.uuid === uuid);
254
+ if (!matchingTx) {
255
+ console.error(`No matching transaction found for uuid: ${uuid}`);
256
+ continue;
257
+ }
258
+ const smartTransaction = {
259
+ statusMetadata: stxStatus,
260
+ status: (0, utils_1.calculateStatus)(stxStatus),
261
+ cancellable: (0, utils_1.isSmartTransactionCancellable)(stxStatus),
262
+ uuid,
263
+ networkClientId: matchingTx.networkClientId,
264
+ };
265
+ await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_createOrUpdateSmartTransaction).call(this, smartTransaction, {
266
+ chainId,
267
+ ethQuery,
268
+ });
269
+ }
270
+ return data;
271
+ }
272
+ clearFees() {
273
+ const fees = {
274
+ approvalTxFees: null,
275
+ tradeTxFees: null,
276
+ };
277
+ this.update((state) => {
278
+ state.smartTransactionsState.fees = fees;
279
+ });
280
+ return fees;
281
+ }
282
+ async getFees(tradeTx, approvalTx, { networkClientId } = {}) {
283
+ const selectedNetworkClientId = networkClientId !== null && networkClientId !== void 0 ? networkClientId : this.messenger.call('NetworkController:getState').selectedNetworkClientId;
284
+ const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, {
285
+ networkClientId: selectedNetworkClientId,
286
+ });
287
+ const transactions = [];
288
+ let unsignedTradeTransactionWithNonce;
289
+ if (approvalTx) {
290
+ const unsignedApprovalTransactionWithNonce = await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_addNonceToTransaction).call(this, approvalTx, selectedNetworkClientId);
291
+ transactions.push(unsignedApprovalTransactionWithNonce);
292
+ unsignedTradeTransactionWithNonce = Object.assign(Object.assign({}, tradeTx), {
293
+ // If there is an approval tx, the trade tx's nonce is increased by 1.
294
+ nonce: (0, utils_1.incrementNonceInHex)(unsignedApprovalTransactionWithNonce.nonce) });
295
+ }
296
+ else if (tradeTx.nonce) {
297
+ unsignedTradeTransactionWithNonce = tradeTx;
298
+ }
299
+ else {
300
+ unsignedTradeTransactionWithNonce = await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_addNonceToTransaction).call(this, tradeTx, selectedNetworkClientId);
301
+ }
302
+ transactions.push(unsignedTradeTransactionWithNonce);
303
+ const data = await __classPrivateFieldGet(this, _SmartTransactionsController_trace, "f").call(this, { name: constants_1.SmartTransactionsTraceName.GetFees }, async () => await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, (0, utils_1.getAPIRequestURL)(types_1.APIType.GET_FEES, chainId), {
304
+ method: 'POST',
305
+ body: JSON.stringify({
306
+ txs: transactions,
307
+ }),
308
+ }));
309
+ let approvalTxFees;
310
+ let tradeTxFees;
311
+ if (approvalTx) {
312
+ approvalTxFees = data === null || data === void 0 ? void 0 : data.txs[0];
313
+ tradeTxFees = data === null || data === void 0 ? void 0 : data.txs[1];
314
+ }
315
+ else {
316
+ approvalTxFees = null;
317
+ tradeTxFees = data === null || data === void 0 ? void 0 : data.txs[0];
318
+ }
319
+ this.update((state) => {
320
+ if (chainId === __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")) {
321
+ state.smartTransactionsState.fees = {
322
+ approvalTxFees,
323
+ tradeTxFees,
324
+ };
325
+ }
326
+ state.smartTransactionsState.feesByChainId[chainId] = {
327
+ approvalTxFees,
328
+ tradeTxFees,
329
+ };
330
+ });
331
+ return {
332
+ approvalTxFees,
333
+ tradeTxFees,
334
+ };
335
+ }
336
+ // * After this successful call client must add a nonce representative to
337
+ // * transaction controller external transactions list
338
+ async submitSignedTransactions({ transactionMeta, txParams, signedTransactions, signedCanceledTransactions = [], networkClientId, }) {
339
+ var _a, _b;
340
+ const selectedNetworkClientId = networkClientId !== null && networkClientId !== void 0 ? networkClientId : this.messenger.call('NetworkController:getState').selectedNetworkClientId;
341
+ const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, {
342
+ networkClientId: selectedNetworkClientId,
343
+ });
344
+ const ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getEthQuery).call(this, {
345
+ networkClientId: selectedNetworkClientId,
346
+ });
347
+ const data = await __classPrivateFieldGet(this, _SmartTransactionsController_trace, "f").call(this, { name: constants_1.SmartTransactionsTraceName.SubmitTransactions }, async () => await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, (0, utils_1.getAPIRequestURL)(types_1.APIType.SUBMIT_TRANSACTIONS, chainId), {
348
+ method: 'POST',
349
+ body: JSON.stringify({
350
+ rawTxs: signedTransactions,
351
+ rawCancelTxs: signedCanceledTransactions,
352
+ }),
353
+ }));
354
+ const time = Date.now();
355
+ let preTxBalance;
356
+ try {
357
+ if (txParams === null || txParams === void 0 ? void 0 : txParams.from) {
358
+ const preTxBalanceBN = await (0, controller_utils_1.query)(ethQuery, 'getBalance', [
359
+ txParams.from,
360
+ ]);
361
+ preTxBalance = new bignumber_js_1.BigNumber(preTxBalanceBN).toString(16);
362
+ }
363
+ }
364
+ catch (error) {
365
+ console.error('ethQuery.getBalance error:', error);
366
+ }
367
+ const requiresNonce = txParams && !txParams.nonce;
368
+ let nonce;
369
+ let nonceLock;
370
+ let nonceDetails = {};
371
+ // This should only happen for Swaps. Non-swaps transactions should already have a nonce
372
+ if (requiresNonce) {
373
+ try {
374
+ nonceLock = await this.messenger.call('TransactionController:getNonceLock', txParams.from, selectedNetworkClientId);
375
+ nonce = (0, bytes_1.hexlify)(nonceLock.nextNonce);
376
+ nonceDetails = nonceLock.nonceDetails;
377
+ (_a = txParams.nonce) !== null && _a !== void 0 ? _a : (txParams.nonce = nonce);
378
+ }
379
+ catch (error) {
380
+ console.error('Failed to acquire nonce lock:', error);
381
+ throw error;
382
+ }
383
+ }
384
+ const txHashes = signedTransactions.map((tx) => (0, utils_1.getTxHash)(tx));
385
+ const submitTransactionResponse = Object.assign(Object.assign({}, data), { txHash: txHashes[txHashes.length - 1], // For backward compatibility - use the last tx hash
386
+ txHashes });
387
+ try {
388
+ await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_createOrUpdateSmartTransaction).call(this, {
389
+ chainId,
390
+ nonceDetails,
391
+ preTxBalance,
392
+ status: types_1.SmartTransactionStatuses.PENDING,
393
+ time,
394
+ txParams,
395
+ uuid: submitTransactionResponse.uuid,
396
+ txHash: submitTransactionResponse.txHash,
397
+ cancellable: true,
398
+ type: (_b = transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.type) !== null && _b !== void 0 ? _b : 'swap',
399
+ transactionId: transactionMeta === null || transactionMeta === void 0 ? void 0 : transactionMeta.id,
400
+ networkClientId: selectedNetworkClientId,
401
+ txHashes, // Add support for multiple transaction hashes
402
+ }, { chainId, ethQuery });
403
+ }
404
+ catch (error) {
405
+ console.error('Failed to create a smart transaction:', error);
406
+ throw error;
407
+ }
408
+ finally {
409
+ if (nonceLock) {
410
+ nonceLock.releaseLock();
411
+ }
412
+ }
413
+ return submitTransactionResponse;
414
+ }
415
+ // TODO: This should return if the cancellation was on chain or not (for nonce management)
416
+ // After this successful call client must update nonce representative
417
+ // in transaction controller external transactions list
418
+ async cancelSmartTransaction(uuid, { networkClientId, } = {}) {
419
+ const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, { networkClientId });
420
+ await __classPrivateFieldGet(this, _SmartTransactionsController_trace, "f").call(this, { name: constants_1.SmartTransactionsTraceName.CancelTransaction }, async () => await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, (0, utils_1.getAPIRequestURL)(types_1.APIType.CANCEL, chainId), {
421
+ method: 'POST',
422
+ body: JSON.stringify({ uuid }),
423
+ }));
424
+ }
425
+ async fetchLiveness({ networkClientId, } = {}) {
426
+ const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, { networkClientId });
427
+ let liveness = false;
428
+ try {
429
+ const response = await __classPrivateFieldGet(this, _SmartTransactionsController_trace, "f").call(this, { name: constants_1.SmartTransactionsTraceName.FetchLiveness }, async () => await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, (0, utils_1.getAPIRequestURL)(types_1.APIType.LIVENESS, chainId)));
430
+ liveness = Boolean(response.smartTransactions);
431
+ }
432
+ catch (error) {
433
+ console.log('"fetchLiveness" API call failed');
434
+ }
435
+ this.update((state) => {
436
+ if (chainId === __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")) {
437
+ state.smartTransactionsState.liveness = liveness;
438
+ }
439
+ state.smartTransactionsState.livenessByChainId[chainId] = liveness;
440
+ });
441
+ return liveness;
442
+ }
443
+ async setStatusRefreshInterval(interval) {
444
+ if (interval !== __classPrivateFieldGet(this, _SmartTransactionsController_interval, "f")) {
445
+ __classPrivateFieldSet(this, _SmartTransactionsController_interval, interval, "f");
446
+ }
447
+ }
448
+ getTransactions({ addressFrom, status, }) {
449
+ const currentSmartTransactions = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getCurrentSmartTransactions).call(this);
450
+ return currentSmartTransactions.filter((stx) => {
451
+ var _a;
452
+ return stx.status === status && ((_a = stx.txParams) === null || _a === void 0 ? void 0 : _a.from) === addressFrom;
453
+ });
454
+ }
455
+ getSmartTransactionByMinedTxHash(txHash) {
456
+ if (!txHash) {
457
+ return undefined;
458
+ }
459
+ const currentSmartTransactions = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getCurrentSmartTransactions).call(this);
460
+ return currentSmartTransactions.find((smartTransaction) => {
461
+ var _a, _b;
462
+ return (((_b = (_a = smartTransaction.statusMetadata) === null || _a === void 0 ? void 0 : _a.minedHash) === null || _b === void 0 ? void 0 : _b.toLowerCase()) ===
463
+ txHash.toLowerCase());
464
+ });
465
+ }
466
+ wipeSmartTransactions({ address, ignoreNetwork, }) {
467
+ if (!address) {
468
+ return;
469
+ }
470
+ const addressLowerCase = address.toLowerCase();
471
+ if (ignoreNetwork) {
472
+ const { smartTransactionsState: { smartTransactions }, } = this.state;
473
+ Object.keys(smartTransactions).forEach((chainId) => {
474
+ __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_wipeSmartTransactionsPerChainId).call(this, {
475
+ chainId,
476
+ addressLowerCase,
477
+ });
478
+ });
479
+ }
480
+ else {
481
+ __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_wipeSmartTransactionsPerChainId).call(this, {
482
+ chainId: __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"),
483
+ addressLowerCase,
484
+ });
485
+ }
486
+ }
487
+ }
488
+ exports.SmartTransactionsController = SmartTransactionsController;
489
+ _SmartTransactionsController_interval = new WeakMap(), _SmartTransactionsController_clientId = new WeakMap(), _SmartTransactionsController_chainId = new WeakMap(), _SmartTransactionsController_supportedChainIds = new WeakMap(), _SmartTransactionsController_ethQuery = new WeakMap(), _SmartTransactionsController_trackMetaMetricsEvent = new WeakMap(), _SmartTransactionsController_getMetaMetricsProps = new WeakMap(), _SmartTransactionsController_getFeatureFlags = new WeakMap(), _SmartTransactionsController_trace = new WeakMap(), _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsController_fetch =
490
+ /* istanbul ignore next */
491
+ async function _SmartTransactionsController_fetch(request, options) {
492
+ const fetchOptions = Object.assign(Object.assign({}, options), { headers: Object.assign({ 'Content-Type': 'application/json' }, (__classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f") && { 'X-Client-Id': __classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f") })) });
493
+ return (0, utils_1.handleFetch)(request, fetchOptions);
494
+ }, _SmartTransactionsController_updateSmartTransaction = function _SmartTransactionsController_updateSmartTransaction(smartTransaction, { chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"), }) {
495
+ var _a;
496
+ const { smartTransactionsState: { smartTransactions }, } = this.state;
497
+ const currentSmartTransactions = (_a = smartTransactions[chainId]) !== null && _a !== void 0 ? _a : [];
498
+ const currentIndex = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.findIndex((stx) => stx.uuid === smartTransaction.uuid);
499
+ if (currentIndex === -1) {
500
+ return; // Smart transaction not found, don't update anything.
501
+ }
502
+ if (!(0, controller_utils_1.isSafeDynamicKey)(chainId)) {
503
+ return;
504
+ }
505
+ this.update((state) => {
506
+ state.smartTransactionsState.smartTransactions[chainId][currentIndex] = Object.assign(Object.assign({}, state.smartTransactionsState.smartTransactions[chainId][currentIndex]), smartTransaction);
507
+ });
508
+ }, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction = async function _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction(smartTransaction) {
509
+ const metaMetricsProps = await __classPrivateFieldGet(this, _SmartTransactionsController_getMetaMetricsProps, "f").call(this);
510
+ smartTransaction.accountHardwareType =
511
+ metaMetricsProps === null || metaMetricsProps === void 0 ? void 0 : metaMetricsProps.accountHardwareType;
512
+ smartTransaction.accountType = metaMetricsProps === null || metaMetricsProps === void 0 ? void 0 : metaMetricsProps.accountType;
513
+ smartTransaction.deviceModel = metaMetricsProps === null || metaMetricsProps === void 0 ? void 0 : metaMetricsProps.deviceModel;
514
+ }, _SmartTransactionsController_createOrUpdateSmartTransaction = async function _SmartTransactionsController_createOrUpdateSmartTransaction(smartTransaction, { chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"), ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f"), }) {
515
+ var _a;
516
+ const { smartTransactionsState: { smartTransactions }, } = this.state;
517
+ const currentSmartTransactions = (_a = smartTransactions[chainId]) !== null && _a !== void 0 ? _a : [];
518
+ const currentIndex = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.findIndex((stx) => stx.uuid === smartTransaction.uuid);
519
+ const isNewSmartTransaction = this.isNewSmartTransaction(smartTransaction.uuid, chainId);
520
+ if (ethQuery === undefined) {
521
+ throw new Error(ETH_QUERY_ERROR_MSG);
522
+ }
523
+ if (isNewSmartTransaction) {
524
+ try {
525
+ await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction).call(this, smartTransaction);
526
+ }
527
+ catch (error) {
528
+ console.error('Failed to add metrics props to smart transaction:', error);
529
+ // Continue without metrics props
530
+ }
531
+ }
532
+ this.trackStxStatusChange(smartTransaction, isNewSmartTransaction
533
+ ? undefined
534
+ : currentSmartTransactions[currentIndex]);
535
+ if (isNewSmartTransaction) {
536
+ // add smart transaction
537
+ const cancelledNonceIndex = currentSmartTransactions === null || currentSmartTransactions === void 0 ? void 0 : currentSmartTransactions.findIndex((stx) => {
538
+ var _a, _b, _c;
539
+ return ((_a = stx.txParams) === null || _a === void 0 ? void 0 : _a.nonce) === ((_b = smartTransaction.txParams) === null || _b === void 0 ? void 0 : _b.nonce) &&
540
+ ((_c = stx.status) === null || _c === void 0 ? void 0 : _c.startsWith('cancelled'));
541
+ });
542
+ const snapshot = (0, cloneDeep_1.default)(smartTransaction);
543
+ const history = [snapshot];
544
+ const historifiedSmartTransaction = Object.assign(Object.assign({}, smartTransaction), { history });
545
+ const nextSmartTransactions = cancelledNonceIndex > -1
546
+ ? currentSmartTransactions
547
+ .slice(0, cancelledNonceIndex)
548
+ .concat(currentSmartTransactions.slice(cancelledNonceIndex + 1))
549
+ .concat(historifiedSmartTransaction)
550
+ : currentSmartTransactions.concat(historifiedSmartTransaction);
551
+ this.update((state) => {
552
+ state.smartTransactionsState.smartTransactions[chainId] =
553
+ nextSmartTransactions;
554
+ });
555
+ return;
556
+ }
557
+ const currentSmartTransaction = currentSmartTransactions[currentIndex];
558
+ const nextSmartTransaction = Object.assign(Object.assign({}, currentSmartTransaction), smartTransaction);
559
+ // We have to emit this event here, because then a txHash is returned to the TransactionController once it's available
560
+ // and the #doesTransactionNeedConfirmation function will work properly, since it will find the txHash in the regular transactions list.
561
+ this.messenger.publish(`SmartTransactionsController:smartTransaction`, nextSmartTransaction);
562
+ if ((0, utils_1.shouldMarkRegularTransactionAsFailed)({
563
+ smartTransaction: nextSmartTransaction,
564
+ clientId: __classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f"),
565
+ getFeatureFlags: __classPrivateFieldGet(this, _SmartTransactionsController_getFeatureFlags, "f"),
566
+ })) {
567
+ (0, utils_1.markRegularTransactionAsFailed)({
568
+ smartTransaction: nextSmartTransaction,
569
+ getRegularTransactions: () => this.messenger.call('TransactionController:getTransactions'),
570
+ updateTransaction: (transactionMeta, note) => this.messenger.call('TransactionController:updateTransaction', transactionMeta, note),
571
+ });
572
+ }
573
+ if ((smartTransaction.status === types_1.SmartTransactionStatuses.SUCCESS ||
574
+ smartTransaction.status === types_1.SmartTransactionStatuses.REVERTED) &&
575
+ !smartTransaction.confirmed) {
576
+ await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_confirmSmartTransaction).call(this, nextSmartTransaction, {
577
+ chainId,
578
+ ethQuery,
579
+ });
580
+ }
581
+ else {
582
+ __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_updateSmartTransaction).call(this, smartTransaction, {
583
+ chainId,
584
+ });
585
+ }
586
+ }, _SmartTransactionsController_doesTransactionNeedConfirmation = function _SmartTransactionsController_doesTransactionNeedConfirmation(txHash) {
587
+ if (!txHash) {
588
+ return true;
589
+ }
590
+ const transactions = this.messenger.call('TransactionController:getTransactions');
591
+ const foundTransaction = transactions === null || transactions === void 0 ? void 0 : transactions.find((tx) => {
592
+ var _a;
593
+ return ((_a = tx.hash) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === txHash.toLowerCase();
594
+ });
595
+ if (!foundTransaction) {
596
+ return true;
597
+ }
598
+ // If a found transaction is either confirmed or submitted, it doesn't need confirmation from the STX controller.
599
+ // When it's in the submitted state, the TransactionController checks its status and confirms it,
600
+ // so no need to confirm it again here.
601
+ return ![transaction_controller_1.TransactionStatus.confirmed, transaction_controller_1.TransactionStatus.submitted].includes(foundTransaction.status);
602
+ }, _SmartTransactionsController_confirmSmartTransaction = async function _SmartTransactionsController_confirmSmartTransaction(smartTransaction, { chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"), ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f"), }) {
603
+ var _a;
604
+ if (ethQuery === undefined) {
605
+ throw new Error(ETH_QUERY_ERROR_MSG);
606
+ }
607
+ const txHash = (_a = smartTransaction.statusMetadata) === null || _a === void 0 ? void 0 : _a.minedHash;
608
+ try {
609
+ const transactionReceipt = await (0, controller_utils_1.query)(ethQuery, 'getTransactionReceipt', [txHash]);
610
+ const transaction = await (0, controller_utils_1.query)(ethQuery, 'getTransactionByHash', [txHash]);
611
+ const maxFeePerGas = transaction === null || transaction === void 0 ? void 0 : transaction.maxFeePerGas;
612
+ const maxPriorityFeePerGas = transaction === null || transaction === void 0 ? void 0 : transaction.maxPriorityFeePerGas;
613
+ if (transactionReceipt === null || transactionReceipt === void 0 ? void 0 : transactionReceipt.blockNumber) {
614
+ const blockData = await (0, controller_utils_1.query)(ethQuery, 'getBlockByNumber', [transactionReceipt === null || transactionReceipt === void 0 ? void 0 : transactionReceipt.blockNumber, false]);
615
+ const baseFeePerGas = blockData === null || blockData === void 0 ? void 0 : blockData.baseFeePerGas;
616
+ const updatedTxParams = Object.assign(Object.assign({}, smartTransaction.txParams), { maxFeePerGas,
617
+ maxPriorityFeePerGas });
618
+ // call confirmExternalTransaction
619
+ const originalTxMeta = Object.assign(Object.assign({}, smartTransaction), { id: smartTransaction.uuid, status: transaction_controller_1.TransactionStatus.confirmed, hash: txHash, txParams: updatedTxParams });
620
+ // create txMeta snapshot for history
621
+ const snapshot = (0, utils_1.snapshotFromTxMeta)(originalTxMeta);
622
+ // recover previous tx state obj
623
+ const previousState = (0, utils_1.replayHistory)(originalTxMeta.history);
624
+ // generate history entry and add to history
625
+ const entry = (0, utils_1.generateHistoryEntry)(previousState, snapshot, 'txStateManager: setting status to confirmed');
626
+ const txMeta = entry.length > 0
627
+ ? Object.assign(Object.assign({}, originalTxMeta), { history: originalTxMeta.history.concat(entry) }) : originalTxMeta;
628
+ if (__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_doesTransactionNeedConfirmation).call(this, txHash)) {
629
+ this.messenger.call('TransactionController:confirmExternalTransaction',
630
+ // TODO: Replace 'as' assertion with correct typing for `txMeta`
631
+ txMeta, transactionReceipt,
632
+ // TODO: Replace 'as' assertion with correct typing for `baseFeePerGas`
633
+ baseFeePerGas);
634
+ }
635
+ __classPrivateFieldGet(this, _SmartTransactionsController_trackMetaMetricsEvent, "f").call(this, {
636
+ event: constants_1.MetaMetricsEventName.StxConfirmed,
637
+ category: constants_1.MetaMetricsEventCategory.Transactions,
638
+ properties: (0, utils_1.getSmartTransactionMetricsProperties)(smartTransaction),
639
+ sensitiveProperties: (0, utils_1.getSmartTransactionMetricsSensitiveProperties)(smartTransaction),
640
+ });
641
+ __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_updateSmartTransaction).call(this, Object.assign(Object.assign({}, smartTransaction), { confirmed: true }), {
642
+ chainId,
643
+ });
644
+ }
645
+ }
646
+ catch (error) {
647
+ __classPrivateFieldGet(this, _SmartTransactionsController_trackMetaMetricsEvent, "f").call(this, {
648
+ event: constants_1.MetaMetricsEventName.StxConfirmationFailed,
649
+ category: constants_1.MetaMetricsEventCategory.Transactions,
650
+ });
651
+ console.error('confirm error', error);
652
+ }
653
+ finally {
654
+ this.messenger.publish(`SmartTransactionsController:smartTransactionConfirmationDone`, smartTransaction);
655
+ }
656
+ }, _SmartTransactionsController_addNonceToTransaction = async function _SmartTransactionsController_addNonceToTransaction(transaction, networkClientId) {
657
+ const nonceLock = await this.messenger.call('TransactionController:getNonceLock', transaction.from, networkClientId);
658
+ const nonce = nonceLock.nextNonce;
659
+ nonceLock.releaseLock();
660
+ return Object.assign(Object.assign({}, transaction), { nonce: `0x${nonce.toString(16)}` });
661
+ }, _SmartTransactionsController_getChainId = function _SmartTransactionsController_getChainId({ networkClientId, } = {}) {
662
+ if (networkClientId) {
663
+ return this.messenger.call('NetworkController:getNetworkClientById', networkClientId).configuration.chainId;
664
+ }
665
+ return __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f");
666
+ }, _SmartTransactionsController_getChainIds = function _SmartTransactionsController_getChainIds() {
667
+ const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
668
+ return Object.keys(networkConfigurationsByChainId).filter((chainId) => __classPrivateFieldGet(this, _SmartTransactionsController_supportedChainIds, "f").includes(chainId));
669
+ }, _SmartTransactionsController_getNetworkClientId = function _SmartTransactionsController_getNetworkClientId({ chainId }) {
670
+ const { networkConfigurationsByChainId } = this.messenger.call('NetworkController:getState');
671
+ return networkConfigurationsByChainId[chainId].rpcEndpoints[networkConfigurationsByChainId[chainId].defaultRpcEndpointIndex].networkClientId;
672
+ }, _SmartTransactionsController_getEthQuery = function _SmartTransactionsController_getEthQuery({ networkClientId, } = {}) {
673
+ if (networkClientId) {
674
+ const { provider } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
675
+ return new eth_query_1.default(provider);
676
+ }
677
+ if (__classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f") === undefined) {
678
+ throw new Error(ETH_QUERY_ERROR_MSG);
679
+ }
680
+ return __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f");
681
+ }, _SmartTransactionsController_getCurrentSmartTransactions = function _SmartTransactionsController_getCurrentSmartTransactions() {
682
+ const { smartTransactionsState: { smartTransactions }, } = this.state;
683
+ const smartTransactionsForAllChains = Object.values(smartTransactions).flat();
684
+ if (!smartTransactionsForAllChains ||
685
+ smartTransactionsForAllChains.length === 0) {
686
+ return [];
687
+ }
688
+ return smartTransactionsForAllChains;
689
+ }, _SmartTransactionsController_wipeSmartTransactionsPerChainId = function _SmartTransactionsController_wipeSmartTransactionsPerChainId({ chainId, addressLowerCase, }) {
690
+ const { smartTransactionsState: { smartTransactions }, } = this.state;
691
+ const smartTransactionsForSelectedChain = smartTransactions === null || smartTransactions === void 0 ? void 0 : smartTransactions[chainId];
692
+ if (!smartTransactionsForSelectedChain ||
693
+ smartTransactionsForSelectedChain.length === 0) {
694
+ return;
695
+ }
696
+ const newSmartTransactionsForSelectedChain = smartTransactionsForSelectedChain.filter((smartTransaction) => { var _a; return ((_a = smartTransaction.txParams) === null || _a === void 0 ? void 0 : _a.from) !== addressLowerCase; });
697
+ this.update((state) => {
698
+ state.smartTransactionsState.smartTransactions[chainId] =
699
+ newSmartTransactionsForSelectedChain;
700
+ });
701
+ };
702
+ //# sourceMappingURL=SmartTransactionsController.mjs.map