Skip to content

Commit 9b1a6f0

Browse files
committed
chore: cleanup
1 parent 185c51f commit 9b1a6f0

File tree

4 files changed

+19
-33
lines changed

4 files changed

+19
-33
lines changed

app/src/main/java/to/bitkit/services/CoreService.kt

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import com.synonym.bitkitcore.getOrders
3838
import com.synonym.bitkitcore.getTags
3939
import com.synonym.bitkitcore.initDb
4040
import com.synonym.bitkitcore.insertActivity
41-
import com.synonym.bitkitcore.isAddressUsed
4241
import com.synonym.bitkitcore.openChannel
4342
import com.synonym.bitkitcore.refreshActiveCjitEntries
4443
import com.synonym.bitkitcore.refreshActiveOrders
@@ -366,20 +365,6 @@ class ActivityService(
366365
getAllClosedChannels(sortDirection)
367366
}
368367

369-
/**
370-
* Maps all `PaymentDetails` from LDK Node to bitkit-core [Activity] records.
371-
*
372-
* Payments are parallelly processed in chunks, handling both on-chain and Lightning payments
373-
* to create new activity records or updating existing ones based on the payment's status and details.
374-
*
375-
* It's designed to be idempotent, meaning it can be called multiple times with the same payment
376-
* list without creating duplicate entries. It checks the `updatedAt` timestamp to avoid overwriting
377-
* newer local data with older data from LDK.
378-
*
379-
* @param payments The list of `PaymentDetails` from the LDK node to be processed.
380-
* @param forceUpdate If true, it will also update activities previously marked as deleted.
381-
* @param channelIdsByTxId Map of transaction IDs to channel IDs for identifying transfer activities.
382-
*/
383368
suspend fun handlePaymentEvent(paymentHash: String) {
384369
ServiceQueue.CORE.background {
385370
val payments = lightningService.payments ?: run {
@@ -555,7 +540,7 @@ class ActivityService(
555540
val timestamp: ULong,
556541
)
557542

558-
private suspend fun getConfirmationStatus(
543+
private fun getConfirmationStatus(
559544
kind: PaymentKind.Onchain,
560545
timestamp: ULong,
561546
): ConfirmationData {
@@ -575,7 +560,7 @@ class ActivityService(
575560
return ConfirmationData(isConfirmed, confirmedTimestamp, timestamp)
576561
}
577562

578-
private suspend fun buildUpdatedOnchainActivity(
563+
private fun buildUpdatedOnchainActivity(
579564
existingActivity: Activity.Onchain,
580565
confirmationData: ConfirmationData,
581566
channelId: String? = null,
@@ -602,7 +587,7 @@ class ActivityService(
602587
return updatedOnChain
603588
}
604589

605-
private suspend fun buildNewOnchainActivity(
590+
private fun buildNewOnchainActivity(
606591
payment: PaymentDetails,
607592
kind: PaymentKind.Onchain,
608593
confirmationData: ConfirmationData,
@@ -876,7 +861,7 @@ class ActivityService(
876861
}
877862
}
878863

879-
private suspend fun markReplacedActivity(
864+
private fun markReplacedActivity(
880865
txid: String,
881866
replacedActivity: OnchainActivity?,
882867
conflicts: List<String>,
@@ -1144,7 +1129,7 @@ class ActivityService(
11441129
channels: List<ChannelDetails>,
11451130
): String? {
11461131
return runCatching {
1147-
val blocktank = coreService.blocktank ?: return null
1132+
val blocktank = coreService.blocktank
11481133
val orders = blocktank.orders(orderIds = null, filter = null, refresh = false)
11491134
val matchingOrder = orders.firstOrNull { order ->
11501135
order.payment?.onchain?.transactions?.any { transaction -> transaction.txId == txid } == true

app/src/main/java/to/bitkit/services/LightningService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.lightningdevkit.ldknode.PaymentDetails
3333
import org.lightningdevkit.ldknode.PaymentId
3434
import org.lightningdevkit.ldknode.PeerDetails
3535
import org.lightningdevkit.ldknode.SpendableUtxo
36+
import org.lightningdevkit.ldknode.TransactionDetails
3637
import org.lightningdevkit.ldknode.Txid
3738
import org.lightningdevkit.ldknode.defaultConfig
3839
import to.bitkit.async.BaseCoroutineScope
@@ -695,7 +696,7 @@ class LightningService @Inject constructor(
695696
// endregion
696697

697698
// region transaction details
698-
suspend fun getTransactionDetails(txid: Txid): org.lightningdevkit.ldknode.TransactionDetails? {
699+
suspend fun getTransactionDetails(txid: Txid): TransactionDetails? {
699700
val node = this.node ?: return null
700701
return ServiceQueue.LDK.background {
701702
try {

app/src/main/java/to/bitkit/ui/screens/wallets/activity/ActivityDetailScreen.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.material3.HorizontalDivider
2020
import androidx.compose.material3.Icon
2121
import androidx.compose.runtime.Composable
2222
import androidx.compose.runtime.LaunchedEffect
23+
import androidx.compose.runtime.ReadOnlyComposable
2324
import androidx.compose.runtime.getValue
2425
import androidx.compose.runtime.mutableStateOf
2526
import androidx.compose.runtime.remember
@@ -45,7 +46,6 @@ import com.synonym.bitkitcore.PaymentState
4546
import com.synonym.bitkitcore.PaymentType
4647
import to.bitkit.R
4748
import to.bitkit.ext.ellipsisMiddle
48-
import to.bitkit.ext.isBoosted
4949
import to.bitkit.ext.isSent
5050
import to.bitkit.ext.isTransfer
5151
import to.bitkit.ext.rawId
@@ -109,10 +109,10 @@ fun ActivityDetailScreen(
109109
detailViewModel.setActivity(item)
110110
if (item is Activity.Onchain) {
111111
isCpfpChild = detailViewModel.isCpfpChildTransaction(item.v1.txId)
112-
if (item.v1.boostTxIds.isNotEmpty()) {
113-
boostTxDoesExist = detailViewModel.getBoostTxDoesExist(item.v1.boostTxIds)
112+
boostTxDoesExist = if (item.v1.boostTxIds.isNotEmpty()) {
113+
detailViewModel.getBoostTxDoesExist(item.v1.boostTxIds)
114114
} else {
115-
boostTxDoesExist = emptyMap()
115+
emptyMap()
116116
}
117117
} else {
118118
isCpfpChild = false
@@ -864,20 +864,19 @@ private fun PreviewSheetSmallScreen() {
864864
}
865865
}
866866

867+
@ReadOnlyComposable
867868
@Composable
868869
private fun shouldEnableBoostButton(
869870
item: Activity,
870871
isCpfpChild: Boolean,
871-
boostTxDoesExist: Map<String, Boolean>
872+
boostTxDoesExist: Map<String, Boolean>,
872873
): Boolean {
873874
if (item !is Activity.Onchain) return false
874875

875876
val activity = item.v1
876877

877878
// Check all disable conditions
878-
val shouldDisable = isCpfpChild ||
879-
!activity.doesExist ||
880-
activity.confirmed == true ||
879+
val shouldDisable = isCpfpChild || !activity.doesExist || activity.confirmed ||
881880
(activity.isBoosted && isBoostCompleted(activity, boostTxDoesExist))
882881

883882
if (shouldDisable) return false
@@ -886,10 +885,11 @@ private fun shouldEnableBoostButton(
886885
return !activity.isTransfer && activity.value > 0uL
887886
}
888887

888+
@ReadOnlyComposable
889889
@Composable
890890
private fun isBoostCompleted(
891891
activity: OnchainActivity,
892-
boostTxDoesExist: Map<String, Boolean>
892+
boostTxDoesExist: Map<String, Boolean>,
893893
): Boolean {
894894
// If boostTxIds is empty, boost is in progress (RBF case)
895895
if (activity.boostTxIds.isEmpty()) return true

app/src/main/java/to/bitkit/ui/screens/wallets/activity/components/ActivityRow.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ fun ActivityRow(
8383
var isCpfpChild by remember { mutableStateOf(false) }
8484

8585
LaunchedEffect(item) {
86-
if (item is Activity.Onchain && activityListViewModel != null) {
87-
isCpfpChild = activityListViewModel.isCpfpChildTransaction(item.v1.txId)
86+
isCpfpChild = if (item is Activity.Onchain && activityListViewModel != null) {
87+
activityListViewModel.isCpfpChildTransaction(item.v1.txId)
8888
} else {
89-
isCpfpChild = false
89+
false
9090
}
9191
}
9292

0 commit comments

Comments
 (0)