Skip to content

Commit 3a0a16b

Browse files
committed
fix: applied suggestions
1 parent 564206e commit 3a0a16b

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

packages/transaction-controller/src/TransactionController.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4245,26 +4245,27 @@ export class TransactionController extends BaseController<
42454245
transactionBatchId: Hex;
42464246
gasFeeEstimates?: GasFeeEstimates;
42474247
}) {
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+
});
42584252
}
42594253

4260-
#updateTransactionBatch(batch: TransactionBatchMeta) {
4254+
#updateTransactionBatch(
4255+
batchId: string,
4256+
callback: (batch: TransactionBatchMeta) => TransactionBatchMeta | void,
4257+
): void {
42614258
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}`);
42674263
}
4264+
4265+
const batch = state.transactionBatches[index];
4266+
const updated = callback(batch);
4267+
4268+
state.transactionBatches[index] = updated ?? batch;
42684269
});
42694270
}
42704271

packages/transaction-controller/src/helpers/GasFeePoller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export class GasFeePoller {
202202
}
203203

204204
log(
205-
'Found unapproved batch transactions',
205+
'Found unapproved transaction batches',
206206
unapprovedTransactionBatches.length,
207207
);
208208

packages/transaction-controller/src/utils/batch.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -580,22 +580,28 @@ async function processTransactionWithHook(
580580
};
581581
}
582582

583-
const txMeta = { ...txBatchMeta, txParams: { ...params, from } };
583+
const transactionMetaForGasEstimates = {
584+
...txBatchMeta,
585+
txParams: { ...params, from },
586+
};
584587

585588
if (txBatchMeta) {
586589
updateTransactionGasEstimates({
587-
txMeta: txMeta as TransactionMeta,
590+
txMeta: transactionMetaForGasEstimates as TransactionMeta,
588591
userFeeLevel: GasFeeEstimateLevel.Medium,
589592
});
590593
}
591594

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+
);
599605

600606
const { id, txParams } = transactionMeta;
601607
const data = txParams.data as Hex | undefined;

0 commit comments

Comments
 (0)