Skip to content

Commit d8928cd

Browse files
committed
feat: cache in progress transfers
1 parent 10dc3fd commit d8928cd

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

app/src/main/java/to/bitkit/repositories/ActivityRepo.kt

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ import com.synonym.bitkitcore.PaymentType
77
import com.synonym.bitkitcore.SortDirection
88
import kotlinx.coroutines.CoroutineDispatcher
99
import kotlinx.coroutines.delay
10+
import kotlinx.coroutines.flow.MutableStateFlow
11+
import kotlinx.coroutines.flow.asStateFlow
12+
import kotlinx.coroutines.flow.combine
1013
import kotlinx.coroutines.flow.first
1114
import kotlinx.coroutines.withContext
1215
import org.lightningdevkit.ldknode.PaymentDetails
1316
import to.bitkit.data.CacheStore
17+
import to.bitkit.data.dto.InProgressTransfer
1418
import to.bitkit.data.dto.PendingBoostActivity
19+
import to.bitkit.data.dto.TransferType
1520
import to.bitkit.di.BgDispatcher
1621
import to.bitkit.ext.matchesPaymentId
1722
import to.bitkit.ext.rawId
@@ -31,6 +36,9 @@ class ActivityRepo @Inject constructor(
3136

3237
var isSyncingLdkNodePayments = false
3338

39+
private val _pendingTransfers: MutableStateFlow<List<Activity.Onchain>> = MutableStateFlow(emptyList())
40+
val pendingTransfers = _pendingTransfers.asStateFlow()
41+
3442
suspend fun syncActivities(): Result<Unit> = withContext(bgDispatcher) {
3543
Logger.debug("syncActivities called", context = TAG)
3644

@@ -278,20 +286,33 @@ class ActivityRepo @Inject constructor(
278286

279287
when (activityToUpdate) {
280288
is Activity.Onchain -> {
289+
val onChainActivity = activityToUpdate.v1.copy(
290+
feeRate = activityMetaData.feeRate.toULong(),
291+
address = activityMetaData.address,
292+
isTransfer = activityMetaData.isTransfer,
293+
channelId = activityMetaData.channelId,
294+
transferTxId = activityMetaData.transferTxId
295+
)
281296
val updatedActivity = Onchain(
282-
v1 = activityToUpdate.v1.copy(
283-
feeRate = activityMetaData.feeRate.toULong(),
284-
address = activityMetaData.address,
285-
isTransfer = activityMetaData.isTransfer,
286-
channelId = activityMetaData.channelId,
287-
transferTxId = activityMetaData.transferTxId
288-
)
297+
v1 = onChainActivity
289298
)
290299

291300
updateActivity(
292301
id = updatedActivity.v1.id,
293302
activity = updatedActivity
294303
).onSuccess {
304+
if (onChainActivity.isTransfer && onChainActivity.doesExist) {
305+
cacheStore.addInProgressTransfer(
306+
InProgressTransfer(
307+
activityId = updatedActivity.v1.id,
308+
type = if (onChainActivity.txType == PaymentType.SENT) {
309+
TransferType.TO_SPENDING
310+
} else {
311+
TransferType.TO_SAVINGS
312+
}
313+
)
314+
)
315+
}
295316
cacheStore.removeTransactionMetadata(activityMetaData)
296317
}
297318
}

0 commit comments

Comments
 (0)