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