Skip to content

Commit 9ea4367

Browse files
committed
feat: fiat conversion
1 parent 33b43b7 commit 9ea4367

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

app/src/main/java/to/bitkit/ui/components/NumberPadTextField.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,15 @@ fun NumberPadTextField(
6464
val fraction = input.split(".").getOrNull(1).orEmpty().removeSpaces()
6565

6666
if (primaryDisplay == PrimaryDisplay.FIAT) {
67-
//todo replace the integer part with the whole fiat formated one like value = value.replace(whole, whole.formatted)
68-
value = whole
67+
//todo replace the integer part with the whole formated one
68+
value = whole //TODO FORMAT FIAT
6969
}
7070

7171
if (input.contains(".")) {
72-
placeholder = placeholder.substring(2 + fraction.length)
72+
placeholder = fraction //TODO GET FRACTIONAL LENGTH
7373

7474
if (primaryDisplay == PrimaryDisplay.FIAT) {
75-
// truncate to 2 decimals for fiat
76-
value = "$whole.${fraction.substring(0, 2)}"
75+
value = "$whole.$fraction" //TODO FORMAT MONEY
7776
}
7877
} else {
7978
if (displayUnit == BitcoinDisplayUnit.MODERN && primaryDisplay == PrimaryDisplay.BITCOIN) {

app/src/main/java/to/bitkit/ui/screens/wallets/send/SendAmountScreen.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.padding
1010
import androidx.compose.foundation.layout.width
1111
import androidx.compose.material3.HorizontalDivider
1212
import androidx.compose.runtime.Composable
13+
import androidx.compose.runtime.LaunchedEffect
1314
import androidx.compose.runtime.getValue
1415
import androidx.compose.runtime.mutableStateOf
1516
import androidx.compose.runtime.remember
@@ -19,6 +20,7 @@ import androidx.compose.ui.Modifier
1920
import androidx.compose.ui.res.stringResource
2021
import androidx.compose.ui.tooling.preview.Preview
2122
import androidx.compose.ui.unit.dp
23+
import okhttp3.internal.toLongOrDefault
2224
import to.bitkit.R
2325
import to.bitkit.models.NodeLifecycleState
2426
import to.bitkit.models.PrimaryDisplay
@@ -32,6 +34,7 @@ import to.bitkit.ui.components.PrimaryButton
3234
import to.bitkit.ui.components.SyncNodeView
3335
import to.bitkit.ui.components.Text13Up
3436
import to.bitkit.ui.components.UnitButton
37+
import to.bitkit.ui.currencyViewModel
3538
import to.bitkit.ui.scaffold.SheetTopBar
3639
import to.bitkit.ui.shared.util.gradientBackground
3740
import to.bitkit.ui.theme.AppThemeSurface
@@ -50,8 +53,22 @@ fun SendAmountScreen(
5053
onBack: () -> Unit,
5154
onEvent: (SendEvent) -> Unit,
5255
) {
56+
val currencyVM = currencyViewModel ?: return
57+
5358
var input: String by remember { mutableStateOf("") }
5459

60+
LaunchedEffect(currencyUiState.primaryDisplay) {
61+
input = when(currencyUiState.primaryDisplay) {
62+
PrimaryDisplay.BITCOIN -> {
63+
currencyVM.convertFiatToSats(input.toDoubleOrNull() ?: 0.0).toString()
64+
}
65+
66+
PrimaryDisplay.FIAT -> {
67+
currencyVM.convert(input.toLongOrDefault(0L))?.formatted.toString().replace(".00", "")
68+
}
69+
}
70+
}
71+
5572
Column(
5673
modifier = Modifier
5774
.fillMaxSize()

0 commit comments

Comments
 (0)