Skip to content

Commit 4858aee

Browse files
authored
Merge pull request #56 from synonymdev/fix/send_btc_input_layout
Send BTC screen Polishing
2 parents 8f824ce + 732e621 commit 4858aee

File tree

3 files changed

+33
-19
lines changed

3 files changed

+33
-19
lines changed

app/src/main/java/to/bitkit/ext/String.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ fun String.truncate(length: Int): String {
1717
this
1818
}.trim()
1919
}
20+
21+
fun String.removeSpaces() = this.filterNot { it.isWhitespace() }

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

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ import androidx.compose.ui.Modifier
1616
import androidx.compose.ui.focus.FocusRequester
1717
import androidx.compose.ui.focus.focusRequester
1818
import androidx.compose.ui.res.stringResource
19-
import androidx.compose.ui.text.font.FontWeight
19+
import androidx.compose.ui.tooling.preview.Preview
2020
import androidx.compose.ui.unit.dp
2121
import to.bitkit.R
22-
import to.bitkit.viewmodels.SendEvent
23-
import to.bitkit.viewmodels.SendUiState
22+
import to.bitkit.ui.components.Caption13Up
2423
import to.bitkit.ui.components.PrimaryButton
2524
import to.bitkit.ui.scaffold.SheetTopBar
26-
import to.bitkit.ui.shared.util.DarkModePreview
27-
import to.bitkit.ui.shared.util.LightModePreview
2825
import to.bitkit.ui.theme.AppTextFieldDefaults
2926
import to.bitkit.ui.theme.AppThemeSurface
27+
import to.bitkit.viewmodels.SendEvent
28+
import to.bitkit.viewmodels.SendUiState
3029

3130
@Composable
3231
fun SendAddressScreen(
@@ -47,25 +46,21 @@ fun SendAddressScreen(
4746
val focusRequester = remember { FocusRequester() }
4847
LaunchedEffect(Unit) { focusRequester.requestFocus() }
4948

50-
Text(
51-
text = stringResource(R.string.wallet__send_to),
52-
style = MaterialTheme.typography.labelSmall,
53-
fontWeight = FontWeight.Normal,
54-
)
55-
Spacer(modifier = Modifier.height(4.dp))
49+
Caption13Up(text = stringResource(R.string.wallet__send_to))
50+
Spacer(modifier = Modifier.height(16.dp))
5651
TextField(
5752
placeholder = { Text(stringResource(R.string.address_placeholder)) },
5853
value = uiState.addressInput,
5954
onValueChange = { onEvent(SendEvent.AddressChange(it)) },
6055
minLines = 12,
61-
maxLines = 12,
6256
colors = AppTextFieldDefaults.noIndicatorColors,
63-
shape = MaterialTheme.shapes.medium,
57+
shape = MaterialTheme.shapes.small,
6458
modifier = Modifier
6559
.fillMaxWidth()
60+
.weight(1f)
6661
.focusRequester(focusRequester),
6762
)
68-
Spacer(modifier = Modifier.weight(1f))
63+
Spacer(modifier = Modifier.height(16.dp))
6964
PrimaryButton(
7065
text = stringResource(R.string.continue_button),
7166
enabled = uiState.isAddressInputValid,
@@ -77,10 +72,9 @@ fun SendAddressScreen(
7772

7873
}
7974

80-
@LightModePreview
81-
@DarkModePreview
75+
@Preview(showSystemUi = true)
8276
@Composable
83-
private fun SendEnterManuallyScreenPreview() {
77+
private fun Preview() {
8478
AppThemeSurface {
8579
SendAddressScreen(
8680
uiState = SendUiState(),
@@ -89,3 +83,19 @@ private fun SendEnterManuallyScreenPreview() {
8983
)
9084
}
9185
}
86+
87+
@Preview(showSystemUi = true)
88+
@Composable
89+
private fun Preview2() {
90+
AppThemeSurface {
91+
SendAddressScreen(
92+
uiState = SendUiState(
93+
address = "bc1q5f29hzkgp6hqla63m32pa0jyfqq32c20837cz4",
94+
addressInput = "bc1q5f29hzkgp6hqla63m32pa0jyfqq32c20837cz4",
95+
isAddressInputValid = true
96+
),
97+
onBack = {},
98+
onEvent = {},
99+
)
100+
}
101+
}

app/src/main/java/to/bitkit/viewmodels/AppViewModel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.lightningdevkit.ldknode.PaymentId
2424
import org.lightningdevkit.ldknode.Txid
2525
import to.bitkit.data.SettingsStore
2626
import to.bitkit.data.keychain.Keychain
27+
import to.bitkit.ext.removeSpaces
2728
import to.bitkit.models.NewTransactionSheetDetails
2829
import to.bitkit.models.NewTransactionSheetDirection
2930
import to.bitkit.models.NewTransactionSheetType
@@ -221,11 +222,12 @@ class AppViewModel @Inject constructor(
221222
}
222223

223224
private fun onAddressChange(value: String) {
225+
val valueWithoutSpaces = value.removeSpaces()
224226
viewModelScope.launch {
225-
val result = runCatching { scannerService.decode(value) }
227+
val result = runCatching { scannerService.decode(valueWithoutSpaces) }
226228
_sendUiState.update {
227229
it.copy(
228-
addressInput = value,
230+
addressInput = valueWithoutSpaces,
229231
isAddressInputValid = result.isSuccess,
230232
)
231233
}

0 commit comments

Comments
 (0)