Skip to content

Commit 5cb3750

Browse files
committed
feat: Set custom fee average tx text
1 parent fb4d1a7 commit 5cb3750

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

app/src/main/java/to/bitkit/ui/settings/transactionSpeed/CustomFeeSettingsScreen.kt

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.height
77
import androidx.compose.foundation.layout.navigationBarsPadding
88
import androidx.compose.foundation.layout.padding
99
import androidx.compose.runtime.Composable
10+
import androidx.compose.runtime.LaunchedEffect
1011
import androidx.compose.runtime.getValue
1112
import androidx.compose.runtime.mutableStateOf
1213
import androidx.compose.runtime.remember
@@ -18,14 +19,18 @@ import androidx.compose.ui.unit.dp
1819
import androidx.lifecycle.compose.collectAsStateWithLifecycle
1920
import androidx.navigation.NavController
2021
import to.bitkit.R
22+
import to.bitkit.env.Env
2123
import to.bitkit.models.BITCOIN_SYMBOL
24+
import to.bitkit.models.ConvertedAmount
2225
import to.bitkit.models.TransactionSpeed
2326
import to.bitkit.ui.appViewModel
27+
import to.bitkit.ui.components.BodyM
2428
import to.bitkit.ui.components.Caption13Up
2529
import to.bitkit.ui.components.KEY_DELETE
2630
import to.bitkit.ui.components.LargeRow
2731
import to.bitkit.ui.components.PinNumberPad
2832
import to.bitkit.ui.components.PrimaryButton
33+
import to.bitkit.ui.currencyViewModel
2934
import to.bitkit.ui.scaffold.AppTopBar
3035
import to.bitkit.ui.scaffold.CloseNavIcon
3136
import to.bitkit.ui.scaffold.ScreenColumn
@@ -41,9 +46,32 @@ fun CustomFeeSettingsScreen(
4146
var input by remember {
4247
mutableStateOf((customFeeRate.value as? TransactionSpeed.Custom)?.satsPerVByte?.toString() ?: "")
4348
}
49+
val currency = currencyViewModel ?: return
50+
val totalFee = Env.TransactionDefaults.recommendedBaseFee * (input.toUIntOrNull() ?: 0u)
51+
var converted: ConvertedAmount? by remember { mutableStateOf(null) }
52+
53+
LaunchedEffect(input) {
54+
val inputNum = input.toLongOrNull() ?: 0
55+
converted = if (inputNum == 0L) {
56+
null
57+
} else {
58+
currency.convert(totalFee.toLong())
59+
}
60+
}
61+
62+
val totalFeeText = converted
63+
?.let {
64+
stringResource(R.string.settings__general__speed_fee_total_fiat)
65+
.replace("{feeSats}", "$totalFee")
66+
.replace("{fiatSymbol}", it.symbol)
67+
.replace("{fiatFormatted}", it.formatted)
68+
}
69+
?: stringResource(R.string.settings__general__speed_fee_total)
70+
.replace("{feeSats}", "$totalFee")
4471

4572
CustomFeeSettingsContent(
4673
input = input,
74+
totalFeeText = totalFeeText,
4775
onKeyPress = { key ->
4876
when (key) {
4977
KEY_DELETE -> input = if (input.isNotEmpty()) input.dropLast(1) else ""
@@ -63,12 +91,15 @@ fun CustomFeeSettingsScreen(
6391
@Composable
6492
private fun CustomFeeSettingsContent(
6593
input: String,
94+
totalFeeText: String,
6695
onKeyPress: (String) -> Unit = {},
6796
onContinue: () -> Unit = {},
6897
onBackClick: () -> Unit = {},
6998
onCloseClick: () -> Unit = {},
7099
) {
71100
val feeRate = input.toUIntOrNull() ?: 0u
101+
val isValid = feeRate != 0u
102+
72103
ScreenColumn(
73104
modifier = Modifier.navigationBarsPadding()
74105
) {
@@ -83,14 +114,19 @@ private fun CustomFeeSettingsContent(
83114
.fillMaxSize()
84115
) {
85116
Caption13Up(text = stringResource(R.string.common__sat_vbyte), color = Colors.White64)
117+
86118
Spacer(modifier = Modifier.height(16.dp))
87119
LargeRow(
88120
prefix = null,
89121
text = if (input.isEmpty()) "0" else input,
90122
symbol = BITCOIN_SYMBOL,
91123
showSymbol = true,
92124
)
93-
// TODO add subtitle text (B 250 for average transaction ($10.2)
125+
126+
if (isValid) {
127+
Spacer(modifier = Modifier.height(8.dp))
128+
BodyM(totalFeeText, color = Colors.White64)
129+
}
94130

95131
Spacer(modifier = Modifier.weight(1f))
96132

@@ -100,7 +136,7 @@ private fun CustomFeeSettingsContent(
100136
)
101137
PrimaryButton(
102138
onClick = onContinue,
103-
enabled = feeRate != 0u,
139+
enabled = isValid,
104140
text = stringResource(R.string.common__continue),
105141
)
106142
Spacer(modifier = Modifier.height(16.dp))
@@ -114,6 +150,7 @@ private fun Preview() {
114150
AppThemeSurface {
115151
CustomFeeSettingsContent(
116152
input = "5",
153+
totalFeeText = "₿ 256 for average transaction ($0.25)"
117154
)
118155
}
119156
}

0 commit comments

Comments
 (0)