@metamask-previews/smart-transactions-controller 19.2.1-preview-520a56d → 24.2.1-preview-be04faa3e
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.
- package/CHANGELOG.md +2 -703
- package/README.md +36 -77
- package/dist/SmartTransactionsController-method-action-types.cjs +7 -0
- package/dist/SmartTransactionsController-method-action-types.cjs.map +1 -0
- package/dist/SmartTransactionsController-method-action-types.d.cts +94 -0
- package/dist/SmartTransactionsController-method-action-types.d.cts.map +1 -0
- package/dist/SmartTransactionsController-method-action-types.d.mts +94 -0
- package/dist/SmartTransactionsController-method-action-types.d.mts.map +1 -0
- package/dist/SmartTransactionsController-method-action-types.mjs +6 -0
- package/dist/SmartTransactionsController-method-action-types.mjs.map +1 -0
- package/dist/SmartTransactionsController.cjs +164 -120
- package/dist/SmartTransactionsController.cjs.map +1 -1
- package/dist/SmartTransactionsController.d.cts +45 -25
- package/dist/SmartTransactionsController.d.cts.map +1 -1
- package/dist/SmartTransactionsController.d.mts +45 -25
- package/dist/SmartTransactionsController.d.mts.map +1 -1
- package/dist/SmartTransactionsController.mjs +167 -123
- package/dist/SmartTransactionsController.mjs.map +1 -1
- package/dist/constants.cjs +26 -4
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +22 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +22 -1
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +25 -3
- package/dist/constants.mjs.map +1 -1
- package/dist/featureFlags/feature-flags.cjs +121 -0
- package/dist/featureFlags/feature-flags.cjs.map +1 -0
- package/dist/featureFlags/feature-flags.d.cts +76 -0
- package/dist/featureFlags/feature-flags.d.cts.map +1 -0
- package/dist/featureFlags/feature-flags.d.mts +76 -0
- package/dist/featureFlags/feature-flags.d.mts.map +1 -0
- package/dist/featureFlags/feature-flags.mjs +114 -0
- package/dist/featureFlags/feature-flags.mjs.map +1 -0
- package/dist/featureFlags/index.cjs +14 -0
- package/dist/featureFlags/index.cjs.map +1 -0
- package/dist/featureFlags/index.d.cts +3 -0
- package/dist/featureFlags/index.d.cts.map +1 -0
- package/dist/featureFlags/index.d.mts +3 -0
- package/dist/featureFlags/index.d.mts.map +1 -0
- package/dist/featureFlags/index.mjs +3 -0
- package/dist/featureFlags/index.mjs.map +1 -0
- package/dist/featureFlags/validators.cjs +128 -0
- package/dist/featureFlags/validators.cjs.map +1 -0
- package/dist/featureFlags/validators.d.cts +148 -0
- package/dist/featureFlags/validators.d.cts.map +1 -0
- package/dist/featureFlags/validators.d.mts +148 -0
- package/dist/featureFlags/validators.d.mts.map +1 -0
- package/dist/featureFlags/validators.mjs +123 -0
- package/dist/featureFlags/validators.mjs.map +1 -0
- package/dist/index.cjs +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -1
- package/dist/index.mjs.map +1 -1
- package/dist/selectors.cjs +66 -0
- package/dist/selectors.cjs.map +1 -0
- package/dist/selectors.d.cts +181 -0
- package/dist/selectors.d.cts.map +1 -0
- package/dist/selectors.d.mts +181 -0
- package/dist/selectors.d.mts.map +1 -0
- package/dist/selectors.mjs +63 -0
- package/dist/selectors.mjs.map +1 -0
- package/dist/types.cjs +46 -6
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +85 -11
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +85 -11
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +45 -5
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs +57 -78
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +9 -30
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +9 -30
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +56 -75
- package/dist/utils.mjs.map +1 -1
- package/package.json +57 -100
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
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");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
2
7
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
8
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
9
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
10
|
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
11
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
12
|
};
|
|
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
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
|
-
var _SmartTransactionsController_instances, _SmartTransactionsController_interval, _SmartTransactionsController_clientId, _SmartTransactionsController_chainId, _SmartTransactionsController_supportedChainIds, _SmartTransactionsController_ethQuery, _SmartTransactionsController_trackMetaMetricsEvent, _SmartTransactionsController_getMetaMetricsProps,
|
|
16
|
+
var _SmartTransactionsController_instances, _SmartTransactionsController_interval, _SmartTransactionsController_clientId, _SmartTransactionsController_chainId, _SmartTransactionsController_supportedChainIds, _SmartTransactionsController_ethQuery, _SmartTransactionsController_trackMetaMetricsEvent, _SmartTransactionsController_getMetaMetricsProps, _SmartTransactionsController_trace, _SmartTransactionsController_isStxMigrationFlagEnabled, _SmartTransactionsController_validateAndReportFeatureFlags, _SmartTransactionsController_fetch, _SmartTransactionsController_updateSmartTransaction, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction, _SmartTransactionsController_createOrUpdateSmartTransaction, _SmartTransactionsController_confirmSmartTransaction, _SmartTransactionsController_addNonceToTransaction, _SmartTransactionsController_getChainId, _SmartTransactionsController_getChainIds, _SmartTransactionsController_getNetworkClientId, _SmartTransactionsController_getEthQuery, _SmartTransactionsController_getCurrentSmartTransactions, _SmartTransactionsController_wipeSmartTransactionsPerChainId;
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.SmartTransactionsController = exports.getDefaultSmartTransactionsControllerState = exports.DEFAULT_INTERVAL = void 0;
|
|
19
19
|
const bytes_1 = require("@ethersproject/bytes");
|
|
20
20
|
const controller_utils_1 = require("@metamask/controller-utils");
|
|
21
21
|
const eth_query_1 = __importDefault(require("@metamask/eth-query"));
|
|
22
22
|
const polling_controller_1 = require("@metamask/polling-controller");
|
|
23
|
-
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
24
23
|
const bignumber_js_1 = require("bignumber.js");
|
|
25
24
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep.js"));
|
|
26
25
|
const constants_1 = require("./constants.cjs");
|
|
26
|
+
const feature_flags_1 = require("./featureFlags/feature-flags.cjs");
|
|
27
|
+
const validators_1 = require("./featureFlags/validators.cjs");
|
|
27
28
|
const types_1 = require("./types.cjs");
|
|
28
29
|
const utils_1 = require("./utils.cjs");
|
|
29
30
|
const SECOND = 1000;
|
|
@@ -56,6 +57,7 @@ function getDefaultSmartTransactionsControllerState() {
|
|
|
56
57
|
approvalTxFees: null,
|
|
57
58
|
tradeTxFees: null,
|
|
58
59
|
},
|
|
60
|
+
// TODO: set this to false once the clients are all refreshing the liveness state.
|
|
59
61
|
liveness: true,
|
|
60
62
|
livenessByChainId: {
|
|
61
63
|
[controller_utils_1.ChainId.mainnet]: true,
|
|
@@ -75,13 +77,38 @@ function getDefaultSmartTransactionsControllerState() {
|
|
|
75
77
|
};
|
|
76
78
|
}
|
|
77
79
|
exports.getDefaultSmartTransactionsControllerState = getDefaultSmartTransactionsControllerState;
|
|
80
|
+
// === MESSENGER ===
|
|
81
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
82
|
+
'cancelSmartTransaction',
|
|
83
|
+
'checkPoll',
|
|
84
|
+
'clearFees',
|
|
85
|
+
'fetchLiveness',
|
|
86
|
+
'fetchSmartTransactionsStatus',
|
|
87
|
+
'getFees',
|
|
88
|
+
'getSmartTransactionByMinedTxHash',
|
|
89
|
+
'getTransactions',
|
|
90
|
+
'initializeSmartTransactionsForChainId',
|
|
91
|
+
'isNewSmartTransaction',
|
|
92
|
+
'poll',
|
|
93
|
+
'setOptInState',
|
|
94
|
+
'setStatusRefreshInterval',
|
|
95
|
+
'stop',
|
|
96
|
+
'submitSignedTransactions',
|
|
97
|
+
'trackStxStatusChange',
|
|
98
|
+
'updateSmartTransaction',
|
|
99
|
+
'updateSmartTransactions',
|
|
100
|
+
'wipeSmartTransactions',
|
|
101
|
+
];
|
|
78
102
|
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,
|
|
103
|
+
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, trace, }) {
|
|
80
104
|
super({
|
|
81
105
|
name: controllerName,
|
|
82
106
|
metadata: controllerMetadata,
|
|
83
107
|
messenger,
|
|
84
|
-
state:
|
|
108
|
+
state: {
|
|
109
|
+
...getDefaultSmartTransactionsControllerState(),
|
|
110
|
+
...state,
|
|
111
|
+
},
|
|
85
112
|
});
|
|
86
113
|
_SmartTransactionsController_instances.add(this);
|
|
87
114
|
_SmartTransactionsController_interval.set(this, void 0);
|
|
@@ -91,7 +118,6 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
91
118
|
_SmartTransactionsController_ethQuery.set(this, void 0);
|
|
92
119
|
_SmartTransactionsController_trackMetaMetricsEvent.set(this, void 0);
|
|
93
120
|
_SmartTransactionsController_getMetaMetricsProps.set(this, void 0);
|
|
94
|
-
_SmartTransactionsController_getFeatureFlags.set(this, void 0);
|
|
95
121
|
_SmartTransactionsController_trace.set(this, void 0);
|
|
96
122
|
__classPrivateFieldSet(this, _SmartTransactionsController_interval, interval, "f");
|
|
97
123
|
__classPrivateFieldSet(this, _SmartTransactionsController_clientId, clientId, "f");
|
|
@@ -101,8 +127,7 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
101
127
|
__classPrivateFieldSet(this, _SmartTransactionsController_ethQuery, undefined, "f");
|
|
102
128
|
__classPrivateFieldSet(this, _SmartTransactionsController_trackMetaMetricsEvent, trackMetaMetricsEvent, "f");
|
|
103
129
|
__classPrivateFieldSet(this, _SmartTransactionsController_getMetaMetricsProps, getMetaMetricsProps, "f");
|
|
104
|
-
__classPrivateFieldSet(this,
|
|
105
|
-
__classPrivateFieldSet(this, _SmartTransactionsController_trace, trace !== null && trace !== void 0 ? trace : ((_request, fn) => fn === null || fn === void 0 ? void 0 : fn()), "f");
|
|
130
|
+
__classPrivateFieldSet(this, _SmartTransactionsController_trace, trace ?? ((_request, fn) => fn?.()), "f");
|
|
106
131
|
this.initializeSmartTransactionsForChainId();
|
|
107
132
|
this.messenger.subscribe('NetworkController:stateChange', ({ selectedNetworkClientId }) => {
|
|
108
133
|
const { configuration: { chainId }, provider, } = this.messenger.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
@@ -112,13 +137,18 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
112
137
|
this.checkPoll(this.state);
|
|
113
138
|
});
|
|
114
139
|
this.messenger.subscribe(`${controllerName}:stateChange`, (currentState) => this.checkPoll(currentState));
|
|
140
|
+
// Validate feature flags on changes
|
|
141
|
+
this.messenger.subscribe('RemoteFeatureFlagController:stateChange', () => {
|
|
142
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_validateAndReportFeatureFlags).call(this);
|
|
143
|
+
});
|
|
144
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
115
145
|
}
|
|
116
146
|
async _executePoll({ chainIds, }) {
|
|
117
147
|
// if this is going to be truly UI driven polling we shouldn't really reach here
|
|
118
148
|
// with a networkClientId that is not supported, but for now I'll add a check in case
|
|
119
149
|
// wondering if we should add some kind of predicate to the polling controller to check whether
|
|
120
150
|
// we should poll or not
|
|
121
|
-
const filteredChainIds = (chainIds
|
|
151
|
+
const filteredChainIds = (chainIds ?? []).filter((chainId) => __classPrivateFieldGet(this, _SmartTransactionsController_supportedChainIds, "f").includes(chainId));
|
|
122
152
|
if (filteredChainIds.length === 0) {
|
|
123
153
|
return Promise.resolve();
|
|
124
154
|
}
|
|
@@ -126,20 +156,19 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
126
156
|
}
|
|
127
157
|
checkPoll({ smartTransactionsState: { smartTransactions }, }) {
|
|
128
158
|
const smartTransactionsForAllChains = Object.values(smartTransactions).flat();
|
|
129
|
-
const pendingTransactions = smartTransactionsForAllChains
|
|
130
|
-
if (!this.timeoutHandle &&
|
|
159
|
+
const pendingTransactions = smartTransactionsForAllChains?.filter(utils_1.isSmartTransactionPending);
|
|
160
|
+
if (!this.timeoutHandle && pendingTransactions?.length > 0) {
|
|
131
161
|
this.poll();
|
|
132
162
|
}
|
|
133
|
-
else if (this.timeoutHandle &&
|
|
163
|
+
else if (this.timeoutHandle && pendingTransactions?.length === 0) {
|
|
134
164
|
this.stop();
|
|
135
165
|
}
|
|
136
166
|
}
|
|
137
167
|
initializeSmartTransactionsForChainId() {
|
|
138
168
|
if (__classPrivateFieldGet(this, _SmartTransactionsController_supportedChainIds, "f").includes(__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"))) {
|
|
139
169
|
this.update((state) => {
|
|
140
|
-
var _a;
|
|
141
170
|
state.smartTransactionsState.smartTransactions[__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")] =
|
|
142
|
-
|
|
171
|
+
state.smartTransactionsState.smartTransactions[__classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")] ?? [];
|
|
143
172
|
});
|
|
144
173
|
}
|
|
145
174
|
}
|
|
@@ -167,8 +196,11 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
167
196
|
}
|
|
168
197
|
trackStxStatusChange(smartTransaction, prevSmartTransaction) {
|
|
169
198
|
let updatedSmartTransaction = (0, cloneDeep_1.default)(smartTransaction);
|
|
170
|
-
updatedSmartTransaction =
|
|
171
|
-
|
|
199
|
+
updatedSmartTransaction = {
|
|
200
|
+
...(0, cloneDeep_1.default)(prevSmartTransaction),
|
|
201
|
+
...updatedSmartTransaction,
|
|
202
|
+
};
|
|
203
|
+
if (updatedSmartTransaction.status === prevSmartTransaction?.status) {
|
|
172
204
|
return; // If status hasn't changed, don't track it again.
|
|
173
205
|
}
|
|
174
206
|
__classPrivateFieldGet(this, _SmartTransactionsController_trackMetaMetricsEvent, "f").call(this, {
|
|
@@ -180,8 +212,8 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
180
212
|
}
|
|
181
213
|
isNewSmartTransaction(smartTransactionUuid, chainId) {
|
|
182
214
|
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
183
|
-
const currentSmartTransactions = smartTransactions[chainId
|
|
184
|
-
const currentIndex = currentSmartTransactions
|
|
215
|
+
const currentSmartTransactions = smartTransactions[chainId ?? __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")];
|
|
216
|
+
const currentIndex = currentSmartTransactions?.findIndex((stx) => stx.uuid === smartTransactionUuid);
|
|
185
217
|
return currentIndex === -1 || currentIndex === undefined;
|
|
186
218
|
}
|
|
187
219
|
updateSmartTransaction(smartTransaction, { networkClientId } = {}) {
|
|
@@ -212,7 +244,7 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
212
244
|
.map((pendingSmartTransaction) => {
|
|
213
245
|
// Use the transaction's chainId (from the key) to derive a networkClientId
|
|
214
246
|
const networkClientIdToUse = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getNetworkClientId).call(this, {
|
|
215
|
-
chainId
|
|
247
|
+
chainId,
|
|
216
248
|
});
|
|
217
249
|
return {
|
|
218
250
|
uuid: pendingSmartTransaction.uuid,
|
|
@@ -238,7 +270,8 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
238
270
|
networkClientId: transactions[0].networkClientId,
|
|
239
271
|
});
|
|
240
272
|
// Construct the URL and fetch the data
|
|
241
|
-
const
|
|
273
|
+
const useSentinelForBatchStatus = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_isStxMigrationFlagEnabled).call(this, 'stxMigrationBatchStatus');
|
|
274
|
+
const url = `${(0, utils_1.getAPIRequestURL)(types_1.APIType.BATCH_STATUS, chainId, useSentinelForBatchStatus)}?${params.toString()}`;
|
|
242
275
|
const data = (await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_fetch).call(this, url));
|
|
243
276
|
// Process each returned status
|
|
244
277
|
for (const [uuid, stxStatus] of Object.entries(data)) {
|
|
@@ -272,7 +305,8 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
272
305
|
return fees;
|
|
273
306
|
}
|
|
274
307
|
async getFees(tradeTx, approvalTx, { networkClientId } = {}) {
|
|
275
|
-
const selectedNetworkClientId = networkClientId
|
|
308
|
+
const selectedNetworkClientId = networkClientId ??
|
|
309
|
+
this.messenger.call('NetworkController:getState').selectedNetworkClientId;
|
|
276
310
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, {
|
|
277
311
|
networkClientId: selectedNetworkClientId,
|
|
278
312
|
});
|
|
@@ -281,9 +315,11 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
281
315
|
if (approvalTx) {
|
|
282
316
|
const unsignedApprovalTransactionWithNonce = await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_addNonceToTransaction).call(this, approvalTx, selectedNetworkClientId);
|
|
283
317
|
transactions.push(unsignedApprovalTransactionWithNonce);
|
|
284
|
-
unsignedTradeTransactionWithNonce =
|
|
318
|
+
unsignedTradeTransactionWithNonce = {
|
|
319
|
+
...tradeTx,
|
|
285
320
|
// If there is an approval tx, the trade tx's nonce is increased by 1.
|
|
286
|
-
nonce: (0, utils_1.incrementNonceInHex)(unsignedApprovalTransactionWithNonce.nonce)
|
|
321
|
+
nonce: (0, utils_1.incrementNonceInHex)(unsignedApprovalTransactionWithNonce.nonce),
|
|
322
|
+
};
|
|
287
323
|
}
|
|
288
324
|
else if (tradeTx.nonce) {
|
|
289
325
|
unsignedTradeTransactionWithNonce = tradeTx;
|
|
@@ -292,7 +328,8 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
292
328
|
unsignedTradeTransactionWithNonce = await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_addNonceToTransaction).call(this, tradeTx, selectedNetworkClientId);
|
|
293
329
|
}
|
|
294
330
|
transactions.push(unsignedTradeTransactionWithNonce);
|
|
295
|
-
const
|
|
331
|
+
const useSentinelForGetFees = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_isStxMigrationFlagEnabled).call(this, 'stxMigrationGetFees');
|
|
332
|
+
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, useSentinelForGetFees), {
|
|
296
333
|
method: 'POST',
|
|
297
334
|
body: JSON.stringify({
|
|
298
335
|
txs: transactions,
|
|
@@ -301,12 +338,12 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
301
338
|
let approvalTxFees;
|
|
302
339
|
let tradeTxFees;
|
|
303
340
|
if (approvalTx) {
|
|
304
|
-
approvalTxFees = data
|
|
305
|
-
tradeTxFees = data
|
|
341
|
+
approvalTxFees = data?.txs[0];
|
|
342
|
+
tradeTxFees = data?.txs[1];
|
|
306
343
|
}
|
|
307
344
|
else {
|
|
308
345
|
approvalTxFees = null;
|
|
309
|
-
tradeTxFees = data
|
|
346
|
+
tradeTxFees = data?.txs[0];
|
|
310
347
|
}
|
|
311
348
|
this.update((state) => {
|
|
312
349
|
if (chainId === __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f")) {
|
|
@@ -327,26 +364,28 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
327
364
|
}
|
|
328
365
|
// * After this successful call client must add a nonce representative to
|
|
329
366
|
// * transaction controller external transactions list
|
|
330
|
-
async submitSignedTransactions({ transactionMeta, txParams, signedTransactions, signedCanceledTransactions = [], networkClientId, }) {
|
|
331
|
-
|
|
332
|
-
|
|
367
|
+
async submitSignedTransactions({ transactionMeta, txParams, signedTransactions, signedCanceledTransactions = [], signedTransactionsWithMetadata, networkClientId, }) {
|
|
368
|
+
const selectedNetworkClientId = networkClientId ??
|
|
369
|
+
this.messenger.call('NetworkController:getState').selectedNetworkClientId;
|
|
333
370
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, {
|
|
334
371
|
networkClientId: selectedNetworkClientId,
|
|
335
372
|
});
|
|
336
373
|
const ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getEthQuery).call(this, {
|
|
337
374
|
networkClientId: selectedNetworkClientId,
|
|
338
375
|
});
|
|
339
|
-
const
|
|
376
|
+
const useSentinelForSubmitTransactions = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_isStxMigrationFlagEnabled).call(this, 'stxMigrationSubmitTransactions');
|
|
377
|
+
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, useSentinelForSubmitTransactions), {
|
|
340
378
|
method: 'POST',
|
|
341
379
|
body: JSON.stringify({
|
|
342
380
|
rawTxs: signedTransactions,
|
|
343
381
|
rawCancelTxs: signedCanceledTransactions,
|
|
382
|
+
rawTxsWithMetadata: signedTransactionsWithMetadata,
|
|
344
383
|
}),
|
|
345
384
|
}));
|
|
346
385
|
const time = Date.now();
|
|
347
386
|
let preTxBalance;
|
|
348
387
|
try {
|
|
349
|
-
if (txParams
|
|
388
|
+
if (txParams?.from) {
|
|
350
389
|
const preTxBalanceBN = await (0, controller_utils_1.query)(ethQuery, 'getBalance', [
|
|
351
390
|
txParams.from,
|
|
352
391
|
]);
|
|
@@ -366,7 +405,7 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
366
405
|
nonceLock = await this.messenger.call('TransactionController:getNonceLock', txParams.from, selectedNetworkClientId);
|
|
367
406
|
nonce = (0, bytes_1.hexlify)(nonceLock.nextNonce);
|
|
368
407
|
nonceDetails = nonceLock.nonceDetails;
|
|
369
|
-
|
|
408
|
+
txParams.nonce ?? (txParams.nonce = nonce);
|
|
370
409
|
}
|
|
371
410
|
catch (error) {
|
|
372
411
|
console.error('Failed to acquire nonce lock:', error);
|
|
@@ -374,8 +413,11 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
374
413
|
}
|
|
375
414
|
}
|
|
376
415
|
const txHashes = signedTransactions.map((tx) => (0, utils_1.getTxHash)(tx));
|
|
377
|
-
const submitTransactionResponse =
|
|
378
|
-
|
|
416
|
+
const submitTransactionResponse = {
|
|
417
|
+
...data,
|
|
418
|
+
txHash: txHashes[txHashes.length - 1], // For backward compatibility - use the last tx hash
|
|
419
|
+
txHashes,
|
|
420
|
+
};
|
|
379
421
|
try {
|
|
380
422
|
await __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_createOrUpdateSmartTransaction).call(this, {
|
|
381
423
|
chainId,
|
|
@@ -387,8 +429,8 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
387
429
|
uuid: submitTransactionResponse.uuid,
|
|
388
430
|
txHash: submitTransactionResponse.txHash,
|
|
389
431
|
cancellable: true,
|
|
390
|
-
type:
|
|
391
|
-
transactionId: transactionMeta
|
|
432
|
+
type: transactionMeta?.type ?? 'swap',
|
|
433
|
+
transactionId: transactionMeta?.id,
|
|
392
434
|
networkClientId: selectedNetworkClientId,
|
|
393
435
|
txHashes, // Add support for multiple transaction hashes
|
|
394
436
|
}, { chainId, ethQuery });
|
|
@@ -409,19 +451,29 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
409
451
|
// in transaction controller external transactions list
|
|
410
452
|
async cancelSmartTransaction(uuid, { networkClientId, } = {}) {
|
|
411
453
|
const chainId = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, { networkClientId });
|
|
412
|
-
|
|
454
|
+
const useSentinelForCancel = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_isStxMigrationFlagEnabled).call(this, 'stxMigrationCancel');
|
|
455
|
+
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, useSentinelForCancel), {
|
|
413
456
|
method: 'POST',
|
|
414
457
|
body: JSON.stringify({ uuid }),
|
|
415
458
|
}));
|
|
416
459
|
}
|
|
417
|
-
|
|
418
|
-
|
|
460
|
+
/**
|
|
461
|
+
* Fetches the liveness status of Smart Transactions for a given chain.
|
|
462
|
+
*
|
|
463
|
+
* @param options - The options object.
|
|
464
|
+
* @param options.chainId - The chain ID to fetch liveness for. Preferred over networkClientId.
|
|
465
|
+
* @param options.networkClientId - The network client ID to derive chain ID from.
|
|
466
|
+
* @returns A promise that resolves to the liveness status.
|
|
467
|
+
*/
|
|
468
|
+
async fetchLiveness({ networkClientId, chainId: chainIdArg, } = {}) {
|
|
469
|
+
// Use chainId directly if provided, otherwise derive from networkClientId
|
|
470
|
+
const chainId = chainIdArg ?? __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getChainId).call(this, { networkClientId });
|
|
419
471
|
let liveness = false;
|
|
420
472
|
try {
|
|
421
473
|
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
474
|
liveness = Boolean(response.smartTransactions);
|
|
423
475
|
}
|
|
424
|
-
catch
|
|
476
|
+
catch {
|
|
425
477
|
console.log('"fetchLiveness" API call failed');
|
|
426
478
|
}
|
|
427
479
|
this.update((state) => {
|
|
@@ -440,8 +492,7 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
440
492
|
getTransactions({ addressFrom, status, }) {
|
|
441
493
|
const currentSmartTransactions = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getCurrentSmartTransactions).call(this);
|
|
442
494
|
return currentSmartTransactions.filter((stx) => {
|
|
443
|
-
|
|
444
|
-
return stx.status === status && ((_a = stx.txParams) === null || _a === void 0 ? void 0 : _a.from) === addressFrom;
|
|
495
|
+
return stx.status === status && stx.txParams?.from === addressFrom;
|
|
445
496
|
});
|
|
446
497
|
}
|
|
447
498
|
getSmartTransactionByMinedTxHash(txHash) {
|
|
@@ -450,8 +501,7 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
450
501
|
}
|
|
451
502
|
const currentSmartTransactions = __classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_getCurrentSmartTransactions).call(this);
|
|
452
503
|
return currentSmartTransactions.find((smartTransaction) => {
|
|
453
|
-
|
|
454
|
-
return (((_b = (_a = smartTransaction.statusMetadata) === null || _a === void 0 ? void 0 : _a.minedHash) === null || _b === void 0 ? void 0 : _b.toLowerCase()) ===
|
|
504
|
+
return (smartTransaction.statusMetadata?.minedHash?.toLowerCase() ===
|
|
455
505
|
txHash.toLowerCase());
|
|
456
506
|
});
|
|
457
507
|
}
|
|
@@ -478,16 +528,46 @@ class SmartTransactionsController extends (0, polling_controller_1.StaticInterva
|
|
|
478
528
|
}
|
|
479
529
|
}
|
|
480
530
|
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(),
|
|
531
|
+
_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_trace = new WeakMap(), _SmartTransactionsController_instances = new WeakSet(), _SmartTransactionsController_isStxMigrationFlagEnabled = function _SmartTransactionsController_isStxMigrationFlagEnabled(flagName) {
|
|
532
|
+
const flag = this.messenger.call('RemoteFeatureFlagController:getState')
|
|
533
|
+
?.remoteFeatureFlags?.[flagName];
|
|
534
|
+
return Boolean(flag && typeof flag === 'object' && 'value' in flag && flag.value);
|
|
535
|
+
}, _SmartTransactionsController_validateAndReportFeatureFlags = function _SmartTransactionsController_validateAndReportFeatureFlags() {
|
|
536
|
+
const remoteFeatureFlagControllerState = this.messenger.call('RemoteFeatureFlagController:getState');
|
|
537
|
+
const rawFlags = remoteFeatureFlagControllerState?.remoteFeatureFlags
|
|
538
|
+
?.smartTransactionsNetworks;
|
|
539
|
+
const { errors } = (0, validators_1.validateSmartTransactionsFeatureFlags)(rawFlags);
|
|
540
|
+
// Report each validation error to Sentry
|
|
541
|
+
for (const error of errors) {
|
|
542
|
+
this.messenger.captureException?.(new Error(`[SmartTransactionsController] Feature flag validation failed: ${error.message}. Please check the SmartTransactionNetworks feature flag in Remote Config. Smart transactions are disabled for this network. Default disabled config: ${JSON.stringify(constants_1.DEFAULT_DISABLED_SMART_TRANSACTIONS_FEATURE_FLAGS.default)}`));
|
|
543
|
+
}
|
|
544
|
+
}, _SmartTransactionsController_fetch =
|
|
482
545
|
/* istanbul ignore next */
|
|
483
546
|
async function _SmartTransactionsController_fetch(request, options) {
|
|
484
|
-
const
|
|
547
|
+
const headers = {
|
|
548
|
+
'Content-Type': 'application/json',
|
|
549
|
+
...(__classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f") && { 'X-Client-Id': __classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f") }),
|
|
550
|
+
};
|
|
551
|
+
const urlMatches = request.startsWith(constants_1.API_BASE_URL) ||
|
|
552
|
+
Object.values(constants_1.SENTINEL_API_BASE_URL_MAP).some((baseUrl) => request.startsWith(baseUrl));
|
|
553
|
+
if (urlMatches) {
|
|
554
|
+
const token = await this.messenger.call('AuthenticationController:getBearerToken');
|
|
555
|
+
if (token) {
|
|
556
|
+
headers.Authorization = `Bearer ${token}`;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
const fetchOptions = {
|
|
560
|
+
...options,
|
|
561
|
+
headers: {
|
|
562
|
+
...headers,
|
|
563
|
+
...options?.headers,
|
|
564
|
+
},
|
|
565
|
+
};
|
|
485
566
|
return (0, utils_1.handleFetch)(request, fetchOptions);
|
|
486
567
|
}, _SmartTransactionsController_updateSmartTransaction = function _SmartTransactionsController_updateSmartTransaction(smartTransaction, { chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"), }) {
|
|
487
|
-
var _a;
|
|
488
568
|
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
489
|
-
const currentSmartTransactions =
|
|
490
|
-
const currentIndex = currentSmartTransactions
|
|
569
|
+
const currentSmartTransactions = smartTransactions[chainId] ?? [];
|
|
570
|
+
const currentIndex = currentSmartTransactions?.findIndex((stx) => stx.uuid === smartTransaction.uuid);
|
|
491
571
|
if (currentIndex === -1) {
|
|
492
572
|
return; // Smart transaction not found, don't update anything.
|
|
493
573
|
}
|
|
@@ -495,19 +575,21 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
495
575
|
return;
|
|
496
576
|
}
|
|
497
577
|
this.update((state) => {
|
|
498
|
-
state.smartTransactionsState.smartTransactions[chainId][currentIndex] =
|
|
578
|
+
state.smartTransactionsState.smartTransactions[chainId][currentIndex] = {
|
|
579
|
+
...state.smartTransactionsState.smartTransactions[chainId][currentIndex],
|
|
580
|
+
...smartTransaction,
|
|
581
|
+
};
|
|
499
582
|
});
|
|
500
583
|
}, _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction = async function _SmartTransactionsController_addMetaMetricsPropsToNewSmartTransaction(smartTransaction) {
|
|
501
584
|
const metaMetricsProps = await __classPrivateFieldGet(this, _SmartTransactionsController_getMetaMetricsProps, "f").call(this);
|
|
502
585
|
smartTransaction.accountHardwareType =
|
|
503
|
-
metaMetricsProps
|
|
504
|
-
smartTransaction.accountType = metaMetricsProps
|
|
505
|
-
smartTransaction.deviceModel = metaMetricsProps
|
|
586
|
+
metaMetricsProps?.accountHardwareType;
|
|
587
|
+
smartTransaction.accountType = metaMetricsProps?.accountType;
|
|
588
|
+
smartTransaction.deviceModel = metaMetricsProps?.deviceModel;
|
|
506
589
|
}, _SmartTransactionsController_createOrUpdateSmartTransaction = async function _SmartTransactionsController_createOrUpdateSmartTransaction(smartTransaction, { chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"), ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f"), }) {
|
|
507
|
-
var _a;
|
|
508
590
|
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
509
|
-
const currentSmartTransactions =
|
|
510
|
-
const currentIndex = currentSmartTransactions
|
|
591
|
+
const currentSmartTransactions = smartTransactions[chainId] ?? [];
|
|
592
|
+
const currentIndex = currentSmartTransactions?.findIndex((stx) => stx.uuid === smartTransaction.uuid);
|
|
511
593
|
const isNewSmartTransaction = this.isNewSmartTransaction(smartTransaction.uuid, chainId);
|
|
512
594
|
if (ethQuery === undefined) {
|
|
513
595
|
throw new Error(ETH_QUERY_ERROR_MSG);
|
|
@@ -526,14 +608,11 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
526
608
|
: currentSmartTransactions[currentIndex]);
|
|
527
609
|
if (isNewSmartTransaction) {
|
|
528
610
|
// add smart transaction
|
|
529
|
-
const cancelledNonceIndex = currentSmartTransactions
|
|
530
|
-
|
|
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
|
-
});
|
|
611
|
+
const cancelledNonceIndex = currentSmartTransactions?.findIndex((stx) => stx.txParams?.nonce === smartTransaction.txParams?.nonce &&
|
|
612
|
+
stx.status?.startsWith('cancelled'));
|
|
534
613
|
const snapshot = (0, cloneDeep_1.default)(smartTransaction);
|
|
535
614
|
const history = [snapshot];
|
|
536
|
-
const historifiedSmartTransaction =
|
|
615
|
+
const historifiedSmartTransaction = { ...smartTransaction, history };
|
|
537
616
|
const nextSmartTransactions = cancelledNonceIndex > -1
|
|
538
617
|
? currentSmartTransactions
|
|
539
618
|
.slice(0, cancelledNonceIndex)
|
|
@@ -547,16 +626,19 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
547
626
|
return;
|
|
548
627
|
}
|
|
549
628
|
const currentSmartTransaction = currentSmartTransactions[currentIndex];
|
|
550
|
-
const nextSmartTransaction =
|
|
551
|
-
|
|
552
|
-
|
|
629
|
+
const nextSmartTransaction = {
|
|
630
|
+
...currentSmartTransaction,
|
|
631
|
+
...smartTransaction,
|
|
632
|
+
};
|
|
633
|
+
// We have to emit this event here, so a txHash is returned to the TransactionController once it's available.
|
|
553
634
|
this.messenger.publish(`SmartTransactionsController:smartTransaction`, nextSmartTransaction);
|
|
554
|
-
|
|
635
|
+
const featureFlags = (0, feature_flags_1.getSmartTransactionsFeatureFlagsForChain)((0, feature_flags_1.getSmartTransactionsFeatureFlags)(this.messenger), chainId);
|
|
636
|
+
if ((0, utils_1.shouldMarkRegularTransactionsAsFailed)({
|
|
555
637
|
smartTransaction: nextSmartTransaction,
|
|
556
638
|
clientId: __classPrivateFieldGet(this, _SmartTransactionsController_clientId, "f"),
|
|
557
|
-
|
|
639
|
+
featureFlags,
|
|
558
640
|
})) {
|
|
559
|
-
(0, utils_1.
|
|
641
|
+
(0, utils_1.markRegularTransactionsAsFailed)({
|
|
560
642
|
smartTransaction: nextSmartTransaction,
|
|
561
643
|
getRegularTransactions: () => this.messenger.call('TransactionController:getTransactions'),
|
|
562
644
|
updateTransaction: (transactionMeta, note) => this.messenger.call('TransactionController:updateTransaction', transactionMeta, note),
|
|
@@ -575,62 +657,21 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
575
657
|
chainId,
|
|
576
658
|
});
|
|
577
659
|
}
|
|
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
660
|
}, _SmartTransactionsController_confirmSmartTransaction = async function _SmartTransactionsController_confirmSmartTransaction(smartTransaction, { chainId = __classPrivateFieldGet(this, _SmartTransactionsController_chainId, "f"), ethQuery = __classPrivateFieldGet(this, _SmartTransactionsController_ethQuery, "f"), }) {
|
|
595
|
-
var _a;
|
|
596
661
|
if (ethQuery === undefined) {
|
|
597
662
|
throw new Error(ETH_QUERY_ERROR_MSG);
|
|
598
663
|
}
|
|
599
|
-
const txHash =
|
|
664
|
+
const txHash = smartTransaction.statusMetadata?.minedHash;
|
|
600
665
|
try {
|
|
601
666
|
const transactionReceipt = await (0, controller_utils_1.query)(ethQuery, 'getTransactionReceipt', [txHash]);
|
|
602
|
-
|
|
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
|
-
}
|
|
667
|
+
if (transactionReceipt?.blockNumber) {
|
|
627
668
|
__classPrivateFieldGet(this, _SmartTransactionsController_trackMetaMetricsEvent, "f").call(this, {
|
|
628
669
|
event: constants_1.MetaMetricsEventName.StxConfirmed,
|
|
629
670
|
category: constants_1.MetaMetricsEventCategory.Transactions,
|
|
630
671
|
properties: (0, utils_1.getSmartTransactionMetricsProperties)(smartTransaction),
|
|
631
672
|
sensitiveProperties: (0, utils_1.getSmartTransactionMetricsSensitiveProperties)(smartTransaction),
|
|
632
673
|
});
|
|
633
|
-
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_updateSmartTransaction).call(this,
|
|
674
|
+
__classPrivateFieldGet(this, _SmartTransactionsController_instances, "m", _SmartTransactionsController_updateSmartTransaction).call(this, { ...smartTransaction, confirmed: true }, {
|
|
634
675
|
chainId,
|
|
635
676
|
});
|
|
636
677
|
}
|
|
@@ -649,7 +690,10 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
649
690
|
const nonceLock = await this.messenger.call('TransactionController:getNonceLock', transaction.from, networkClientId);
|
|
650
691
|
const nonce = nonceLock.nextNonce;
|
|
651
692
|
nonceLock.releaseLock();
|
|
652
|
-
return
|
|
693
|
+
return {
|
|
694
|
+
...transaction,
|
|
695
|
+
nonce: `0x${nonce.toString(16)}`,
|
|
696
|
+
};
|
|
653
697
|
}, _SmartTransactionsController_getChainId = function _SmartTransactionsController_getChainId({ networkClientId, } = {}) {
|
|
654
698
|
if (networkClientId) {
|
|
655
699
|
return this.messenger.call('NetworkController:getNetworkClientById', networkClientId).configuration.chainId;
|
|
@@ -680,12 +724,12 @@ async function _SmartTransactionsController_fetch(request, options) {
|
|
|
680
724
|
return smartTransactionsForAllChains;
|
|
681
725
|
}, _SmartTransactionsController_wipeSmartTransactionsPerChainId = function _SmartTransactionsController_wipeSmartTransactionsPerChainId({ chainId, addressLowerCase, }) {
|
|
682
726
|
const { smartTransactionsState: { smartTransactions }, } = this.state;
|
|
683
|
-
const smartTransactionsForSelectedChain = smartTransactions
|
|
727
|
+
const smartTransactionsForSelectedChain = smartTransactions?.[chainId];
|
|
684
728
|
if (!smartTransactionsForSelectedChain ||
|
|
685
729
|
smartTransactionsForSelectedChain.length === 0) {
|
|
686
730
|
return;
|
|
687
731
|
}
|
|
688
|
-
const newSmartTransactionsForSelectedChain = smartTransactionsForSelectedChain.filter((smartTransaction) =>
|
|
732
|
+
const newSmartTransactionsForSelectedChain = smartTransactionsForSelectedChain.filter((smartTransaction) => smartTransaction.txParams?.from !== addressLowerCase);
|
|
689
733
|
this.update((state) => {
|
|
690
734
|
state.smartTransactionsState.smartTransactions[chainId] =
|
|
691
735
|
newSmartTransactionsForSelectedChain;
|