Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/java/to/bitkit/data/dto/PendingBoostActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import kotlinx.serialization.Serializable
data class PendingBoostActivity(
val txId: String,
val updatedAt: ULong,
val activityToDelete: String?
val activityToDelete: String?,
val boostTxIds: List<String> = emptyList(),
)
9 changes: 6 additions & 3 deletions app/src/main/java/to/bitkit/repositories/ActivityRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -428,22 +428,25 @@ class ActivityRepo @Inject constructor(
val updatedActivity = Activity.Onchain(
v1 = newOnChainActivity.v1.copy(
isBoosted = true,
updatedAt = pendingBoostActivity.updatedAt
boostTxIds = pendingBoostActivity.boostTxIds,
updatedAt = pendingBoostActivity.updatedAt,
)
)

if (pendingBoostActivity.activityToDelete != null) {
// RBF: Replace old activity with new one, applying parent chain boostTxIds
replaceActivity(
id = updatedActivity.v1.id,
activity = updatedActivity,
activityIdToDelete = pendingBoostActivity.activityToDelete
activityIdToDelete = pendingBoostActivity.activityToDelete,
).onSuccess {
cacheStore.removeActivityFromPendingBoost(pendingBoostActivity)
}
} else {
// CPFP: Update existing activity (though CPFP is handled immediately now)
updateActivity(
id = updatedActivity.v1.id,
activity = updatedActivity
activity = updatedActivity,
).onSuccess {
cacheStore.removeActivityFromPendingBoost(pendingBoostActivity)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,6 @@ fun ActivityExploreScreen(
val intent = Intent(Intent.ACTION_VIEW, url.toUri())
context.startActivity(intent)
},
onClickParent = { id ->
app.toast(
type = Toast.ToastType.WARNING,
title = "TODO",
description = "Navigate to Activity Detail for: $id",
)
},
)
}
}
Expand All @@ -133,7 +126,6 @@ private fun ActivityExploreContent(
txDetails: TxDetails? = null,
onCopy: (String) -> Unit = {},
onClickExplore: (String) -> Unit = {},
onClickParent: (String) -> Unit = {},
) {
Column(
modifier = Modifier
Expand Down Expand Up @@ -164,7 +156,6 @@ private fun ActivityExploreContent(
onchain = item,
onCopy = onCopy,
txDetails = txDetails,
onClickParent = onClickParent,
)
Spacer(modifier = Modifier.weight(1f))
PrimaryButton(
Expand Down Expand Up @@ -226,7 +217,6 @@ private fun ColumnScope.OnchainDetails(
onchain: Activity.Onchain,
onCopy: (String) -> Unit,
txDetails: TxDetails?,
onClickParent: (String) -> Unit,
) {
val txId = onchain.v1.txId
Section(
Expand Down Expand Up @@ -271,13 +261,9 @@ private fun ColumnScope.OnchainDetails(
.size(16.dp)
.align(Alignment.CenterHorizontally)
)
} // TODO use real boosted parents from bitkit-core/ldk-node when available
val boostedParents = listOfNotNull(
"todo_first_parent_txid".takeIf { onchain.isBoosted() && !onchain.v1.confirmed },
"todo_second_parent_txid".takeIf { onchain.isBoosted() && onchain.v1.confirmed },
)
}

boostedParents.forEachIndexed { index, parent ->
onchain.v1.boostTxIds.forEachIndexed { index, parent ->
val isRbf = onchain.boostType() == BoostType.RBF
Section(
title = stringResource(
Expand All @@ -289,9 +275,11 @@ private fun ColumnScope.OnchainDetails(
}
},
modifier = Modifier
.clickableAlpha {
onClickParent(parent)
}
.clickableAlpha(
onClick = copyToClipboard(parent) {
onCopy(it)
}
)
.testTag(if (isRbf) "RBFBoosted" else "CPFPBoosted")
)
}
Expand Down
38 changes: 27 additions & 11 deletions app/src/main/java/to/bitkit/ui/sheets/BoostTransactionViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.lightningdevkit.ldknode.Txid
import to.bitkit.data.dto.PendingBoostActivity
import to.bitkit.ext.BoostType
import to.bitkit.ext.boostType
import to.bitkit.ext.nowMillis
import to.bitkit.ext.nowTimestamp
import to.bitkit.models.TransactionSpeed
import to.bitkit.repositories.ActivityRepo
Expand Down Expand Up @@ -203,6 +204,8 @@ class BoostTransactionViewModel @Inject constructor(
destinationAddress = walletRepo.getOnchainAddress(),
).fold(
onSuccess = { newTxId ->
// For CPFP, immediately update parent with child txId
Logger.debug("CPFP successful. Appending child txId $newTxId to parent's boostTxIds", context = TAG)
handleBoostSuccess(newTxId, isRBF = false)
},
onFailure = { error ->
Expand Down Expand Up @@ -283,7 +286,7 @@ class BoostTransactionViewModel @Inject constructor(
/**
* Updates activity based on boost type:
* - RBF: Updates current activity with boost data, then replaces with new transaction
* - CPFP: Simply updates the current activity
* - CPFP: Updates parent activity by appending child txId to boostTxIds
*/
private suspend fun updateActivity(newTxId: Txid, isRBF: Boolean): Result<Unit> {
Logger.debug("Updating activity for txId: $newTxId. isRBF: $isRBF", context = TAG)
Expand All @@ -294,24 +297,25 @@ class BoostTransactionViewModel @Inject constructor(
return if (isRBF) {
handleRBFUpdate(newTxId, currentActivity)
} else {
handleCPFPUpdate(currentActivity)
handleCPFPUpdate(currentActivity, newTxId)
}
}

/**
* Handles CPFP (Child Pays For Parent) update by simply updating the current activity
* Handles CPFP (Child Pays For Parent) update by appending child txId to parent's boostTxIds
*/
private suspend fun handleCPFPUpdate(currentActivity: OnchainActivity): Result<Unit> {
private suspend fun handleCPFPUpdate(currentActivity: OnchainActivity, childTxId: Txid): Result<Unit> {
val updatedActivity = Activity.Onchain(
v1 = currentActivity.copy(
isBoosted = true,
updatedAt = nowTimestamp().toEpochMilli().toULong()
boostTxIds = currentActivity.boostTxIds + childTxId,
updatedAt = nowMillis().toULong(),
)
)

return activityRepo.updateActivity(
id = updatedActivity.v1.id,
activity = updatedActivity
activity = updatedActivity,
)
}

Expand All @@ -328,13 +332,13 @@ class BoostTransactionViewModel @Inject constructor(
isBoosted = true,
feeRate = _uiState.value.feeRate,
fee = _uiState.value.totalFeeSats,
updatedAt = nowTimestamp().toEpochMilli().toULong()
updatedAt = nowMillis().toULong(),
)
)

activityRepo.updateActivity(
id = updatedCurrentActivity.v1.id,
activity = updatedCurrentActivity
activity = updatedCurrentActivity,
)

// Then find and replace with the new activity
Expand Down Expand Up @@ -379,7 +383,7 @@ class BoostTransactionViewModel @Inject constructor(
v1 = newOnChainActivity.v1.copy(
isBoosted = true,
feeRate = _uiState.value.feeRate,
updatedAt = nowTimestamp().toEpochMilli().toULong()
updatedAt = nowMillis().toULong(),
)
)

Expand Down Expand Up @@ -412,13 +416,25 @@ class BoostTransactionViewModel @Inject constructor(

/**
* Caches activity data for pending boost operation
* - For RBF: stores parent chain (existing boostTxIds + current txId)
* - For CPFP: stores empty list (child tx is added to parent's boostTxIds during sync)
*/
private suspend fun cachePendingBoostActivity(newTxId: Txid, activityToDelete: String?) {
val currentActivity = activity?.v1
val boostTxIds = if (activityToDelete != null && currentActivity != null) {
// RBF: Track full parent chain (existing boostTxIds + current txId being replaced)
currentActivity.boostTxIds + currentActivity.txId
} else {
// CPFP: No parent tracking needed
emptyList()
}

activityRepo.addActivityToPendingBoost(
PendingBoostActivity(
txId = newTxId,
updatedAt = nowTimestamp().toEpochMilli().toULong(),
activityToDelete = activityToDelete
updatedAt = nowMillis().toULong(),
activityToDelete = activityToDelete,
boostTxIds = boostTxIds,
)
)
}
Expand Down