Skip to content

Commit d0f45ca

Browse files
committed
feat: display time estimation
1 parent efc6409 commit d0f45ca

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

app/src/main/java/to/bitkit/models/FeeRate.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package to.bitkit.models
22

33
import androidx.annotation.DrawableRes
44
import androidx.annotation.StringRes
5+
import androidx.compose.runtime.Composable
56
import androidx.compose.ui.graphics.Color
7+
import androidx.compose.ui.res.stringResource
68
import com.synonym.bitkitcore.FeeRates
79
import to.bitkit.R
810
import to.bitkit.ui.theme.Colors
@@ -69,7 +71,6 @@ enum class FeeRate(
6971
}
7072
}
7173

72-
// TODO use for confirmsIn text in ActivityRow.kt:125
7374
fun fromSatsPerVByte(satsPerVByte: ULong, feeRates: FeeRates): FeeRate {
7475
val value = satsPerVByte.toUInt()
7576
return when {
@@ -79,5 +80,17 @@ enum class FeeRate(
7980
else -> MINIMUM
8081
}
8182
}
83+
84+
@Composable
85+
fun getFeeDescription(
86+
feeRate: ULong,
87+
feeEstimates: FeeRates?,
88+
): String {
89+
val feeRateEnum = feeEstimates?.let {
90+
fromSatsPerVByte(feeRate, it)
91+
} ?: NORMAL
92+
93+
return stringResource(feeRateEnum.shortDescription)
94+
}
8295
}
8396
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ import to.bitkit.ext.rawId
3737
import to.bitkit.ext.timestamp
3838
import to.bitkit.ext.totalValue
3939
import to.bitkit.ext.txType
40+
import to.bitkit.models.FeeRate
4041
import to.bitkit.models.PrimaryDisplay
4142
import to.bitkit.models.formatToModernDisplay
4243
import to.bitkit.ui.LocalCurrencies
4344
import to.bitkit.ui.activityListViewModel
45+
import to.bitkit.ui.blocktankViewModel
4446
import to.bitkit.ui.components.BodyMSB
4547
import to.bitkit.ui.components.CaptionB
4648
import to.bitkit.ui.currencyViewModel
@@ -62,6 +64,11 @@ fun ActivityRow(
6264
onClick: (String) -> Unit,
6365
testTag: String,
6466
) {
67+
val blocktankInfo by blocktankViewModel?.info?.collectAsStateWithLifecycle() ?: remember {
68+
mutableStateOf(null)
69+
}
70+
val feeRates = blocktankInfo?.onchain?.feeRates
71+
6572
val status: PaymentState? = when (item) {
6673
is Activity.Lightning -> item.v1.status
6774
is Activity.Onchain -> null
@@ -121,24 +128,26 @@ fun ActivityRow(
121128
isTransfer && isSent -> if (item.v1.confirmed) {
122129
stringResource(R.string.wallet__activity_transfer_spending_done)
123130
} else {
131+
val duration = FeeRate.getFeeDescription(item.v1.feeRate, feeRates)
124132
stringResource(R.string.wallet__activity_transfer_spending_pending)
125-
.replace("{duration}", "1h") // TODO: calculate confirmsIn text
133+
.replace("{duration}", duration.removeEstimationSymbol())
126134
}
127135

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

135144
confirmed == true -> formattedTime(timestamp)
136145

137146
else -> {
138-
// TODO: calculate confirmsIn text
147+
val feeDescription = FeeRate.getFeeDescription(item.v1.feeRate, feeRates)
139148
stringResource(R.string.wallet__activity_confirms_in).replace(
140149
"{feeRateDescription}",
141-
"± 1h"
150+
feeDescription
142151
)
143152
}
144153
}
@@ -314,6 +323,10 @@ private fun formattedTime(timestamp: ULong): String {
314323
}
315324
}
316325

326+
// TODO remove this method after transifex update
327+
private fun String.removeEstimationSymbol() = this.replace("±", "")
328+
329+
317330
private class ActivityItemsPreviewProvider : PreviewParameterProvider<Activity> {
318331
override val values: Sequence<Activity> get() = previewActivityItems.asSequence()
319332
}

0 commit comments

Comments
 (0)