Reject decimal input in the manual "currency to Sats" field
It was using the decimal sanitizer/keyboard, same as the rate field next to it — but Sats are indivisible, so this one should behave like the existing Sats amount field: integers only, numeric keypad. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy
This commit is contained in:
@@ -115,8 +115,8 @@ struct ContentView: View {
|
|||||||
NumericField(
|
NumericField(
|
||||||
placeholder: "",
|
placeholder: "",
|
||||||
value: state.manualSatsPerCurrencyInput,
|
value: state.manualSatsPerCurrencyInput,
|
||||||
keyboardType: .decimalPad,
|
keyboardType: .numberPad,
|
||||||
sanitize: sanitizeDecimalInput,
|
sanitize: sanitizeIntegerInput,
|
||||||
onChange: { viewModel.onManualSatsPerCurrencyChanged($0) },
|
onChange: { viewModel.onManualSatsPerCurrencyChanged($0) },
|
||||||
alignment: .trailing
|
alignment: .trailing
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ fun PriceScreen(
|
|||||||
value = state.manualSatsPerCurrencyInput,
|
value = state.manualSatsPerCurrencyInput,
|
||||||
onValueChange = viewModel::onManualSatsPerCurrencyChanged,
|
onValueChange = viewModel::onManualSatsPerCurrencyChanged,
|
||||||
label = { Text(stringResource(MR.strings.currency_to_sats, state.defaultCurrencyCode)) },
|
label = { Text(stringResource(MR.strings.currency_to_sats, state.defaultCurrencyCode)) },
|
||||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Decimal),
|
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
visualTransformation = DigitGroupingTransformation,
|
visualTransformation = DigitGroupingTransformation,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
|||||||
@@ -294,7 +294,8 @@ class PriceViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onManualSatsPerCurrencyChanged(value: String) {
|
fun onManualSatsPerCurrencyChanged(value: String) {
|
||||||
val sanitized = sanitizeDecimalInput(value)
|
// Sats are indivisible — unlike the rate field, this one takes whole numbers only.
|
||||||
|
val sanitized = sanitizeIntegerInput(value)
|
||||||
val parsedSats = sanitized.toBigDecimalOrNull()
|
val parsedSats = sanitized.toBigDecimalOrNull()
|
||||||
val rate = parsedSats?.let { sats -> CurrencyConverter.satsPerCurrencyUnit(sats) }
|
val rate = parsedSats?.let { sats -> CurrencyConverter.satsPerCurrencyUnit(sats) }
|
||||||
manualSource.rate = rate
|
manualSource.rate = rate
|
||||||
|
|||||||
Reference in New Issue
Block a user