feat: websocket events update payment db

This commit is contained in:
2026-06-01 15:44:19 +02:00
parent 18c8697ce9
commit 385536db25
6 changed files with 277 additions and 68 deletions
@@ -9,12 +9,13 @@ import android.os.IBinder
import android.util.Log
import com.bitcointxoko.gudariwallet.api.GsonProvider
import com.bitcointxoko.gudariwallet.api.LNbitsClient
import com.bitcointxoko.gudariwallet.api.PaymentRecord
import com.bitcointxoko.gudariwallet.api.WsPaymentMessage
import com.bitcointxoko.gudariwallet.data.PaymentCacheRepository
import com.bitcointxoko.gudariwallet.security.EncryptedSecretStore
import com.bitcointxoko.gudariwallet.util.NotificationConstants
import com.bitcointxoko.gudariwallet.util.NotificationHelper
import com.bitcointxoko.gudariwallet.util.WalletConstants
import com.google.gson.Gson
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -48,6 +49,8 @@ private const val TAG = "WalletNotifService"
*/
class WalletNotificationService : Service() {
private val paymentCache by lazy { PaymentCacheRepository(applicationContext) }
// ── Companion: shared state accessible by ViewModel ───────────────────────
companion object {
@@ -231,6 +234,26 @@ class WalletNotificationService : Service() {
)
)
}
// Persist the incoming payment directly to DB
// so the cache is fresh even if the History screen isn't open
serviceScope.launch {
paymentCache.upsertPayment(
PaymentRecord(
checkingId = payment.checkingId,
paymentHash = payment.paymentHash,
amountMsat = payment.amount,
feeMsat = 0L, // WsPaymentMessage doesn't carry fee
memo = payment.memo,
time = payment.time,
status = payment.status,
bolt11 = payment.bolt11,
pending = false, // we only act on status == "success"
preimage = payment.preimage,
extra = payment.extra
)
)
}
}
private fun scheduleReconnect() {