File tree Expand file tree Collapse file tree 3 files changed +33
-26
lines changed
packages/transaction-controller/src Expand file tree Collapse file tree 3 files changed +33
-26
lines changed Original file line number Diff line number Diff line change @@ -4245,26 +4245,27 @@ export class TransactionController extends BaseController<
4245
4245
transactionBatchId : Hex ;
4246
4246
gasFeeEstimates ?: GasFeeEstimates ;
4247
4247
} ) {
4248
- const batch = this . state . transactionBatches . find (
4249
- ( txBatch ) => txBatch . id === transactionBatchId ,
4250
- ) ;
4251
- if ( ! batch ) {
4252
- return ;
4253
- }
4254
-
4255
- batch . gasFeeEstimates = gasFeeEstimates ;
4256
-
4257
- this . #updateTransactionBatch( batch ) ;
4248
+ this . #updateTransactionBatch( transactionBatchId , ( batch ) => {
4249
+ batch . gasFeeEstimates = gasFeeEstimates ;
4250
+ return batch ;
4251
+ } ) ;
4258
4252
}
4259
4253
4260
- #updateTransactionBatch( batch : TransactionBatchMeta ) {
4254
+ #updateTransactionBatch(
4255
+ batchId : string ,
4256
+ callback : ( batch : TransactionBatchMeta ) => TransactionBatchMeta | void ,
4257
+ ) : void {
4261
4258
this . update ( ( state ) => {
4262
- const index = state . transactionBatches . findIndex (
4263
- ( b ) => b . id === batch . id ,
4264
- ) ;
4265
- if ( index >= 0 ) {
4266
- state . transactionBatches [ index ] = batch ;
4259
+ const index = state . transactionBatches . findIndex ( ( b ) => b . id === batchId ) ;
4260
+
4261
+ if ( index === - 1 ) {
4262
+ throw new Error ( `Cannot update batch, ID not found - ${ batchId } ` ) ;
4267
4263
}
4264
+
4265
+ const batch = state . transactionBatches [ index ] ;
4266
+ const updated = callback ( batch ) ;
4267
+
4268
+ state . transactionBatches [ index ] = updated ?? batch ;
4268
4269
} ) ;
4269
4270
}
4270
4271
Original file line number Diff line number Diff line change @@ -202,7 +202,7 @@ export class GasFeePoller {
202
202
}
203
203
204
204
log (
205
- 'Found unapproved batch transactions ' ,
205
+ 'Found unapproved transaction batches ' ,
206
206
unapprovedTransactionBatches . length ,
207
207
) ;
208
208
Original file line number Diff line number Diff line change @@ -580,22 +580,28 @@ async function processTransactionWithHook(
580
580
} ;
581
581
}
582
582
583
- const txMeta = { ...txBatchMeta , txParams : { ...params , from } } ;
583
+ const transactionMetaForGasEstimates = {
584
+ ...txBatchMeta ,
585
+ txParams : { ...params , from } ,
586
+ } ;
584
587
585
588
if ( txBatchMeta ) {
586
589
updateTransactionGasEstimates ( {
587
- txMeta : txMeta as TransactionMeta ,
590
+ txMeta : transactionMetaForGasEstimates as TransactionMeta ,
588
591
userFeeLevel : GasFeeEstimateLevel . Medium ,
589
592
} ) ;
590
593
}
591
594
592
- const { transactionMeta } = await addTransaction ( txMeta . txParams , {
593
- batchId,
594
- disableGasBuffer : true ,
595
- networkClientId,
596
- publishHook,
597
- requireApproval : false ,
598
- } ) ;
595
+ const { transactionMeta } = await addTransaction (
596
+ transactionMetaForGasEstimates . txParams ,
597
+ {
598
+ batchId,
599
+ disableGasBuffer : true ,
600
+ networkClientId,
601
+ publishHook,
602
+ requireApproval : false ,
603
+ } ,
604
+ ) ;
599
605
600
606
const { id, txParams } = transactionMeta ;
601
607
const data = txParams . data as Hex | undefined ;
You can’t perform that action at this time.
0 commit comments