@@ -24,6 +24,7 @@ import to.bitkit.di.BgDispatcher
2424import to.bitkit.ext.matchesPaymentId
2525import to.bitkit.ext.rawId
2626import to.bitkit.services.CoreService
27+ import to.bitkit.utils.AddressChecker
2728import to.bitkit.utils.Logger
2829import javax.inject.Inject
2930import javax.inject.Singleton
@@ -37,6 +38,7 @@ class ActivityRepo @Inject constructor(
3738 private val lightningRepo : LightningRepo ,
3839 private val cacheStore : CacheStore ,
3940 private val db : AppDb ,
41+ private val addressChecker : AddressChecker ,
4042) {
4143 var isSyncingLdkNodePayments = MutableStateFlow (false )
4244 private set
@@ -326,15 +328,6 @@ class ActivityRepo @Inject constructor(
326328 private suspend fun syncTagsMetaData (
327329 newPayments : List <PaymentDetails >,
328330 ) = withContext(context = bgDispatcher) {
329- // 1. Check for new activities
330- // 2. Filter receive
331- // 2.1 Lightning -> search for payment hash
332- // 2.2 OnChain -> get payment detail -> output -> search for address
333- // 3. Filter sent
334- // 3.1 Lightning -> search for payment hash
335- // 3.2 OnChain -> search for tx ID
336- // 4. Delete successfull addedd
337-
338331 runCatching {
339332 if (db.tagMetadataDao().getAll().isEmpty()) return @withContext
340333
@@ -356,13 +349,30 @@ class ActivityRepo @Inject constructor(
356349
357350 is PaymentKind .Onchain -> {
358351 when (payment.direction) {
359- PaymentDirection .INBOUND -> TODO ()
352+ PaymentDirection .INBOUND -> {
353+ // TODO Temporary solution while whe ldk-node doesn't return the txId directly
354+ runCatching { addressChecker.getTransaction(kind.txid) }.onSuccess { txDetails ->
355+ txDetails.vout.firstOrNull()?.scriptpubkey_address?.let {
356+ db.tagMetadataDao().searchByAddress(it)
357+ }?.let { tagMetadata ->
358+ addTagsToTransaction(
359+ paymentHashOrTxId = kind.txid,
360+ type = ActivityFilter .ONCHAIN ,
361+ txType = PaymentType .RECEIVED ,
362+ tags = tagMetadata.tags
363+ ).onSuccess {
364+ db.tagMetadataDao().deleteByTxId(kind.txid)
365+ }
366+ }
367+ }
368+ }
369+
360370 PaymentDirection .OUTBOUND -> {
361371 db.tagMetadataDao().searchByTxId(kind.txid)?.let { tagMetadata ->
362372 addTagsToTransaction(
363373 paymentHashOrTxId = kind.txid,
364374 type = ActivityFilter .ONCHAIN ,
365- txType = if (tagMetadata.isReceive) PaymentType . RECEIVED else PaymentType .SENT ,
375+ txType = PaymentType .SENT ,
366376 tags = tagMetadata.tags
367377 ).onSuccess {
368378 db.tagMetadataDao().deleteByTxId(kind.txid)
@@ -371,6 +381,7 @@ class ActivityRepo @Inject constructor(
371381 }
372382 }
373383 }
384+
374385 else -> Unit
375386 }
376387 }
0 commit comments