MCPcopy Create free account
hub / github.com/etherspot/transaction-kit / addToBatch

Method addToBatch

lib/TransactionKit.ts:1055–1100  ·  view source on GitHub ↗

* Adds the current transaction to a specified batch, creating the batch if it does not exist. * * This method associates the current working transaction with a batch, identified by batchName. If the batch does not exist, it is created. Throws an error if there is no selected transaction, no wo

({ batchName }: AddToBatchParams)

Source from the content-addressed store, hash-verified

1053 * - The batch is created if it does not already exist.
1054 */
1055 addToBatch({ batchName }: AddToBatchParams): IBatchedTransaction {
1056 if (!this.selectedTransactionName || !this.workingTransaction) {
1057 this.throwError(
1058 'addToBatch(): No named transaction to add to batch. Call name() first.'
1059 );
1060 }
1061 if (typeof batchName !== 'string' || batchName.trim() === '') {
1062 this.throwError(
1063 'addToBatch(): batchName is required and must be a non-empty string.'
1064 );
1065 }
1066 // If the batch does not exist, create it
1067 if (!this.batches[batchName]) {
1068 this.batches[batchName] = [];
1069 log(
1070 `addToBatch(): Created new batch: ${batchName}`,
1071 undefined,
1072 this.debugMode
1073 );
1074 }
1075 this.workingTransaction.batchName = batchName;
1076 const existingIndex = this.batches[batchName].findIndex(
1077 (tx) => tx.transactionName === this.selectedTransactionName
1078 );
1079
1080 if (existingIndex >= 0) {
1081 // Update existing transaction in batch
1082 this.batches[batchName][existingIndex] = { ...this.workingTransaction };
1083 } else {
1084 // Add new transaction to batch
1085 this.batches[batchName].push({ ...this.workingTransaction });
1086 }
1087
1088 // Update namedTransactions
1089 this.namedTransactions[this.selectedTransactionName] = {
1090 ...this.workingTransaction,
1091 };
1092
1093 log(
1094 `addToBatch(): Transaction '${this.selectedTransactionName}' added to batch '${batchName}'`,
1095 undefined,
1096 this.debugMode
1097 );
1098
1099 return this;
1100 }
1101
1102 /**
1103 * Removes the currently selected transaction or batch from the trakit.

Callers

nothing calls this directly

Calls 2

throwErrorMethod · 0.95
logFunction · 0.90

Tested by

no test coverage detected