Skip to content

Commit a940c12

Browse files
committed
refactor: clean up
1 parent b8e6a45 commit a940c12

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

services/chronikService.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,16 @@ export class ChronikBlockchainClient {
419419
}
420420
}
421421

422+
private async updateClientPaymentStatusToConfirmed (addressesWithTransactions: AddressWithTransaction[]): Promise<void> {
423+
for (const addressWithTransaction of addressesWithTransactions) {
424+
const parsedOpReturn = parseOpReturnData(addressWithTransaction.transaction.opReturn ?? '')
425+
const paymentId = parsedOpReturn.paymentId
426+
const newClientPaymentStatus = 'CONFIRMED' as ClientPaymentStatus
427+
428+
await updatePaymentStatus(paymentId, newClientPaymentStatus)
429+
}
430+
}
431+
422432
private async processWsMessage (msg: WsMsgClient): Promise<void> {
423433
// delete unconfirmed transaction from our database
424434
// if they were cancelled and not confirmed
@@ -440,13 +450,7 @@ export class ChronikBlockchainClient {
440450
} else if (msg.msgType === 'TX_CONFIRMED') {
441451
console.log(`${this.CHRONIK_MSG_PREFIX}: [${msg.msgType}] ${msg.txid}`)
442452
this.confirmedTxsHashesFromLastBlock = [...this.confirmedTxsHashesFromLastBlock, msg.txid]
443-
for (const addressWithTransaction of addressesWithTransactions) {
444-
const parsedOpReturn = parseOpReturnData(addressWithTransaction.transaction.opReturn ?? '')
445-
const paymentId = parsedOpReturn.paymentId
446-
const newClientPaymentStatus = 'CONFIRMED' as ClientPaymentStatus
447-
448-
await updatePaymentStatus(paymentId, newClientPaymentStatus)
449-
}
453+
await this.updateClientPaymentStatusToConfirmed(addressesWithTransactions)
450454
} else if (msg.msgType === 'TX_ADDED_TO_MEMPOOL') {
451455
if (this.isAlreadyBeingProcessed(msg.txid, false)) {
452456
return

0 commit comments

Comments
 (0)