Skip to content
Merged
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
8 changes: 8 additions & 0 deletions app/src/main/java/to/bitkit/ext/Activities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ fun Activity.Onchain.boostType() = when (this.v1.txType) {
PaymentType.RECEIVED -> BoostType.CPFP
}

fun Activity.timestamp() = when (this) {
is Activity.Lightning -> v1.timestamp
is Activity.Onchain -> when (v1.confirmed) {
true -> v1.confirmTimestamp ?: v1.timestamp
else -> v1.timestamp
}
}

enum class BoostType { RBF, CPFP }

@Suppress("LongParameterList")
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/to/bitkit/models/FeeRate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package to.bitkit.models

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import com.synonym.bitkitcore.FeeRates
import to.bitkit.R
import to.bitkit.ui.theme.Colors
Expand Down Expand Up @@ -69,7 +71,6 @@ enum class FeeRate(
}
}

// TODO use for confirmsIn text in ActivityRow.kt:125
fun fromSatsPerVByte(satsPerVByte: ULong, feeRates: FeeRates): FeeRate {
val value = satsPerVByte.toUInt()
return when {
Expand All @@ -79,5 +80,17 @@ enum class FeeRate(
else -> MINIMUM
}
}

@Composable
fun getFeeDescription(
feeRate: ULong,
feeEstimates: FeeRates?,
): String {
val feeRateEnum = feeEstimates?.let {
fromSatsPerVByte(feeRate, it)
} ?: NORMAL

Comment thread
jvsena42 marked this conversation as resolved.
return stringResource(feeRateEnum.shortDescription)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.synonym.bitkitcore.Activity
import com.synonym.bitkitcore.FeeRates
import com.synonym.bitkitcore.LightningActivity
import com.synonym.bitkitcore.OnchainActivity
import com.synonym.bitkitcore.PaymentState
Expand All @@ -52,12 +53,15 @@ import to.bitkit.ext.ellipsisMiddle
import to.bitkit.ext.isSent
import to.bitkit.ext.isTransfer
import to.bitkit.ext.rawId
import to.bitkit.ext.timestamp
import to.bitkit.ext.toActivityItemDate
import to.bitkit.ext.toActivityItemTime
import to.bitkit.ext.totalValue
import to.bitkit.models.FeeRate
import to.bitkit.models.Toast
import to.bitkit.ui.Routes
import to.bitkit.ui.appViewModel
import to.bitkit.ui.blocktankViewModel
import to.bitkit.ui.components.BalanceHeaderView
import to.bitkit.ui.components.BodySSB
import to.bitkit.ui.components.BottomSheetPreview
Expand Down Expand Up @@ -188,6 +192,10 @@ fun ActivityDetailScreen(
}

val context = LocalContext.current
val blocktankInfo by blocktankViewModel?.info?.collectAsStateWithLifecycle() ?: remember {
mutableStateOf(null)
}
Comment thread
jvsena42 marked this conversation as resolved.
val feeRates = blocktankInfo?.onchain?.feeRates

Column(
modifier = Modifier.background(Colors.Black)
Expand Down Expand Up @@ -220,7 +228,8 @@ fun ActivityDetailScreen(
title = copyToastTitle,
description = text.ellipsisMiddle(40)
)
}
},
feeRates = feeRates,
)
if (showAddTagSheet) {
ActivityAddTagSheet(
Expand Down Expand Up @@ -289,6 +298,7 @@ private fun ActivityDetailContent(
isCpfpChild: Boolean = false,
boostTxDoesExist: Map<String, Boolean> = emptyMap(),
onCopy: (String) -> Unit,
feeRates: FeeRates? = null,
) {
val isLightning = item is Activity.Lightning
val isSent = item.isSent()
Expand All @@ -303,13 +313,7 @@ private fun ActivityDetailContent(
}

val amountPrefix = if (isSent) "-" else "+"
val timestamp = when (item) {
is Activity.Lightning -> item.v1.timestamp
is Activity.Onchain -> when (item.v1.confirmed) {
true -> item.v1.confirmTimestamp ?: item.v1.timestamp
else -> item.v1.timestamp
}
}
val timestamp = item.timestamp()
val paymentValue = when (item) {
is Activity.Lightning -> item.v1.value
is Activity.Onchain -> item.v1.value
Expand Down Expand Up @@ -369,7 +373,7 @@ private fun ActivityDetailContent(
}

Spacer(modifier = Modifier.height(16.dp))
StatusSection(item, accentColor)
StatusSection(item, accentColor, feeRates)
HorizontalDivider(modifier = Modifier.padding(top = 16.dp))

// Timestamp section: date and time
Expand Down Expand Up @@ -686,7 +690,11 @@ private fun ActivityDetailContent(
}

@Composable
private fun StatusSection(item: Activity, accentColor: Color) {
private fun StatusSection(
item: Activity,
accentColor: Color,
feeRates: FeeRates? = null,
) {
Column(modifier = Modifier.fillMaxWidth()) {
Caption13Up(
text = stringResource(R.string.wallet__activity_status),
Expand Down Expand Up @@ -731,9 +739,10 @@ private fun StatusSection(item: Activity, accentColor: Color) {
var statusTestTag: String? = null

if (item.v1.isTransfer) {
val duration = 0 // TODO get transfer duration
val duration = FeeRate.getFeeDescription(item.v1.feeRate, feeRates)
.removeEstimationSymbol()
statusText = stringResource(R.string.wallet__activity_transfer_pending)
.replace("{duration}", "$duration")
.replace("{duration}", duration)
statusTestTag = "StatusTransfer"
}

Expand Down Expand Up @@ -951,3 +960,6 @@ private fun isBoostCompleted(

return false
}

// TODO remove this method after transifex update
private fun String.removeEstimationSymbol() = this.replace("±", "")
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ import to.bitkit.ext.formatted
import to.bitkit.ext.isSent
import to.bitkit.ext.isTransfer
import to.bitkit.ext.rawId
import to.bitkit.ext.timestamp
import to.bitkit.ext.totalValue
import to.bitkit.ext.txType
import to.bitkit.models.FeeRate
import to.bitkit.models.PrimaryDisplay
import to.bitkit.models.formatToModernDisplay
import to.bitkit.ui.LocalCurrencies
import to.bitkit.ui.activityListViewModel
import to.bitkit.ui.blocktankViewModel
import to.bitkit.ui.components.BodyMSB
import to.bitkit.ui.components.CaptionB
import to.bitkit.ui.currencyViewModel
Expand All @@ -61,15 +64,17 @@ fun ActivityRow(
onClick: (String) -> Unit,
testTag: String,
) {
val blocktankInfo by blocktankViewModel?.info?.collectAsStateWithLifecycle() ?: remember {
mutableStateOf(null)
Comment thread
jvsena42 marked this conversation as resolved.
}
val feeRates = blocktankInfo?.onchain?.feeRates

val status: PaymentState? = when (item) {
is Activity.Lightning -> item.v1.status
is Activity.Onchain -> null
}
val isLightning = item is Activity.Lightning
val timestamp = when (item) {
is Activity.Lightning -> item.v1.timestamp
is Activity.Onchain -> item.v1.timestamp
}
val timestamp = item.timestamp()
val txType: PaymentType = item.txType()
val isSent = item.isSent()
val amountPrefix = if (isSent) "-" else "+"
Expand Down Expand Up @@ -123,24 +128,26 @@ fun ActivityRow(
isTransfer && isSent -> if (item.v1.confirmed) {
stringResource(R.string.wallet__activity_transfer_spending_done)
} else {
val duration = FeeRate.getFeeDescription(item.v1.feeRate, feeRates)
stringResource(R.string.wallet__activity_transfer_spending_pending)
.replace("{duration}", "1h") // TODO: calculate confirmsIn text
.replace("{duration}", duration.removeEstimationSymbol())
}

isTransfer && !isSent -> if (item.v1.confirmed) {
stringResource(R.string.wallet__activity_transfer_savings_done)
} else {
val duration = FeeRate.getFeeDescription(item.v1.feeRate, feeRates)
stringResource(R.string.wallet__activity_transfer_savings_pending)
.replace("{duration}", "1h") // TODO: calculate confirmsIn text
.replace("{duration}", duration.removeEstimationSymbol())
}

confirmed == true -> formattedTime(timestamp)

else -> {
// TODO: calculate confirmsIn text
val feeDescription = FeeRate.getFeeDescription(item.v1.feeRate, feeRates)
stringResource(R.string.wallet__activity_confirms_in).replace(
"{feeRateDescription}",
"± 1h"
feeDescription
)
}
}
Expand Down Expand Up @@ -316,6 +323,9 @@ private fun formattedTime(timestamp: ULong): String {
}
}

// TODO remove this method after transifex update
private fun String.removeEstimationSymbol() = this.replace("±", "")
Comment thread
jvsena42 marked this conversation as resolved.

private class ActivityItemsPreviewProvider : PreviewParameterProvider<Activity> {
override val values: Sequence<Activity> get() = previewActivityItems.asSequence()
}
Expand Down
Loading