@@ -222,6 +222,26 @@ function getControllers(
222
222
} ;
223
223
}
224
224
225
+ function getSmartTransactionCommonParams ( flatState : ControllerFlatState ) {
226
+ // UI state is required to support shared selectors to avoid duplicate logic in frontend and backend.
227
+ // Ideally all backend logic would instead rely on messenger event / state subscriptions.
228
+ const uiState = getUIState ( flatState ) ;
229
+
230
+ // @ts -expect-error Smart transaction selector types does not match controller state
231
+ const isSmartTransaction = getIsSmartTransaction ( uiState ) ;
232
+
233
+ // @ts -expect-error Smart transaction selector types does not match controller state
234
+ const featureFlags = getFeatureFlagsByChainId ( uiState ) ;
235
+
236
+ const isHardwareWalletAccount = isHardwareWallet ( uiState ) ;
237
+
238
+ return {
239
+ isSmartTransaction,
240
+ featureFlags,
241
+ isHardwareWalletAccount,
242
+ } ;
243
+ }
244
+
225
245
function publishSmartTransactionHook (
226
246
transactionController : TransactionController ,
227
247
smartTransactionsController : SmartTransactionsController ,
@@ -230,29 +250,22 @@ function publishSmartTransactionHook(
230
250
transactionMeta : TransactionMeta ,
231
251
signedTransactionInHex : Hex ,
232
252
) {
233
- // UI state is required to support shared selectors to avoid duplicate logic in frontend and backend.
234
- // Ideally all backend logic would instead rely on messenger event / state subscriptions.
235
- const uiState = getUIState ( flatState ) ;
236
-
237
- // @ts -expect-error Smart transaction selector types does not match controller state
238
- const isSmartTransaction = getIsSmartTransaction ( uiState ) ;
253
+ const { isSmartTransaction, featureFlags, isHardwareWalletAccount } =
254
+ getSmartTransactionCommonParams ( flatState ) ;
239
255
240
256
if ( ! isSmartTransaction ) {
241
257
// Will cause TransactionController to publish to the RPC provider as normal.
242
258
return { transactionHash : undefined } ;
243
259
}
244
260
245
- // @ts -expect-error Smart transaction selector types does not match controller state
246
- const featureFlags = getFeatureFlagsByChainId ( uiState ) ;
247
-
248
261
return submitSmartTransactionHook ( {
249
262
transactionMeta,
250
263
signedTransactionInHex,
251
264
transactionController,
252
265
smartTransactionsController,
253
266
controllerMessenger : hookControllerMessenger ,
254
267
isSmartTransaction,
255
- isHardwareWallet : isHardwareWallet ( uiState ) ,
268
+ isHardwareWallet : isHardwareWalletAccount ,
256
269
// @ts -expect-error Smart transaction selector return type does not match FeatureFlags type from hook
257
270
featureFlags,
258
271
} ) ;
@@ -271,21 +284,16 @@ function publishBatchSmartTransactionHook({
271
284
flatState : ControllerFlatState ;
272
285
transactions : PublishBatchHookTransaction [ ] ;
273
286
} ) {
274
- // UI state is required to support shared selectors to avoid duplicate logic in frontend and backend.
275
- // Ideally all backend logic would instead rely on messenger event / state subscriptions.
276
- const uiState = getUIState ( flatState ) ;
277
-
278
- // @ts -expect-error Smart transaction selector types does not match controller state
279
- const isSmartTransaction = getIsSmartTransaction ( uiState ) ;
287
+ const { isSmartTransaction, featureFlags, isHardwareWalletAccount } =
288
+ getSmartTransactionCommonParams ( flatState ) ;
280
289
281
290
if ( ! isSmartTransaction ) {
282
291
// Will cause TransactionController to publish to the RPC provider as normal.
283
- return undefined ;
292
+ throw new Error (
293
+ 'publishBatchSmartTransactionHook: Smart Transaction is required for batch submissions' ,
294
+ ) ;
284
295
}
285
296
286
- // @ts -expect-error Smart transaction selector types does not match controller state
287
- const featureFlags = getFeatureFlagsByChainId ( uiState ) ;
288
-
289
297
// Get transactionMeta based on the last transaction ID
290
298
const lastTransaction = transactions [ transactions . length - 1 ] ;
291
299
const transactionMeta = getTransactionById (
@@ -295,10 +303,9 @@ function publishBatchSmartTransactionHook({
295
303
296
304
// If we couldn't find the transaction, we should handle that gracefully
297
305
if ( ! transactionMeta ) {
298
- console . warn (
299
- `Publish batch hook: could not find transaction with id ${ lastTransaction . id } ` ,
306
+ throw new Error (
307
+ `publishBatchSmartTransactionHook: Could not find transaction with id ${ lastTransaction . id } ` ,
300
308
) ;
301
- return undefined ;
302
309
}
303
310
304
311
return submitBatchSmartTransactionHook ( {
@@ -307,7 +314,7 @@ function publishBatchSmartTransactionHook({
307
314
smartTransactionsController,
308
315
controllerMessenger : hookControllerMessenger ,
309
316
isSmartTransaction,
310
- isHardwareWallet : isHardwareWallet ( uiState ) ,
317
+ isHardwareWallet : isHardwareWalletAccount ,
311
318
// @ts -expect-error Smart transaction selector return type does not match FeatureFlags type from hook
312
319
featureFlags,
313
320
transactionMeta,
0 commit comments