Melt counter fixes and model removal fixes

This commit is contained in:
minibits-cash
2025-11-18 15:47:59 +01:00
parent 0ceb484c48
commit 5049e5df78
6 changed files with 31 additions and 14 deletions
+1 -1
View File
@@ -1 +1 @@
019a65ce-c4d4-743b-82e5-36596526cf2b
019a7dcc-68e1-7ed1-83b7-69f47c8a166b
+5 -2
View File
@@ -57,8 +57,11 @@ export const MintProofsCounterModel = types.model('MintProofsCounter', {
}
},
removeInFlightRequest(transactionId: number) {
// Only work with the array if this node is alive
if (!isAlive(self)) return
if (!isAlive(self)) {
log.error('[removeInFlightRequest]', 'ProofsCounter is not alive, aborting removal', { keyset: self.keyset })
return
}
// Create a shallow copy to avoid modifying during iteration
const idx = self.inFlightRequests.findIndex(r => r.transactionId === transactionId)
+2
View File
@@ -154,6 +154,8 @@ export const ProofsStoreModel = types
// Update counters
for (const [keysetId, proofs] of proofsByKeyset) {
if(isPending) continue // do not update counters for move to pending proofs
const counter = mintInstance.getProofsCounterByKeysetId(keysetId)
counter?.increaseProofsCounter(proofs.length)
}
+6 -1
View File
@@ -1,4 +1,4 @@
import { Instance, SnapshotIn, SnapshotOut, types } from 'mobx-state-tree'
import { Instance, isAlive, SnapshotIn, SnapshotOut, types } from 'mobx-state-tree'
import { log } from '../services/logService'
import { MintUnit } from '../services/wallet/currency'
import { Database } from '../services'
@@ -73,6 +73,11 @@ export const TransactionModel = types
// Update multiple fields in database with a single query
const updatedTransaction = Database.updateTransaction(self.id, fields)
if (!isAlive(self)) {
log.error('[update]', 'Transaction instance is not alive, aborting state update', { id: self.id })
return
}
// Update the model to keep store in sync
Object.keys(updatedTransaction).forEach(key => {
;(self as any)[key] = (updatedTransaction as any)[key]
+1 -1
View File
@@ -827,7 +827,7 @@ export const WalletStoreModel = types
currentCounter.increaseProofsCounter(countChangeOutputs)
}
log.debug('[WalletStore.payLightningMelt] counter before melt', {localCounter: currentCounter.counter, counterValueForMelt})
log.trace('[WalletStore.payLightningMelt] Counter state before melt', {localCounter: currentCounter.counter, counterValueForMelt})
const meltParams: MeltParams = options?.inFlightRequest?.request || {
meltQuote,
+16 -9
View File
@@ -1531,17 +1531,24 @@ const handlePendingQueue = async function (): Promise<void> {
if (isBefore(transfer.expiresAt as Date, new Date())) {
log.debug('[handlePendingQueue]', `Transfer invoice expired: ${transfer.paymentId} ${transfer.quote}`)
const transactionData = JSON.parse(transfer.data)
transactionData.push({
const update = {
status: TransactionStatus.EXPIRED,
message: 'Invoice expired',
message: '[handlePendingQueue] related invoice expired',
createdAt: new Date(),
})
transfer.update({
status: TransactionStatus.EXPIRED,
data: JSON.stringify(transactionData)
})
}
try {
const transactionData = JSON.parse(transfer.data)
transactionData.push(update)
transfer.update({
status: TransactionStatus.EXPIRED,
data: JSON.stringify(transactionData)
})
} catch (e) {
transfer.update(update)
}
}
}
}