feat: websocket events update payment db
This commit is contained in:
+24
-1
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user