Keep "currency to Sats" empty when the BTC rate is, and whole-Sats only
Clearing the Manual rate cleared pricedCurrencyCodes but left rateDisplays stale, so "currency to Sats" kept showing a value computed from the old rate even after "BTC to currency" went empty. refresh()'s early-return path now clears rateDisplays too. oneCurrencyToSats() also now derives from defaultCurrencyRate() directly instead of re-reading rateDisplays independently, so the two rates structurally can't disagree about whether a rate is known, and formats to a whole number of Sats (0 decimals) instead of 2 — fractional Sats aren't a meaningful unit to show. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy
This commit is contained in:
@@ -26,10 +26,14 @@ fun ConverterUiState.exceedsMaxSupply(): Boolean {
|
||||
fun ConverterUiState.defaultCurrencyRate(): String =
|
||||
rateDisplays[defaultCurrencyCode]?.takeIf { it.isNotEmpty() } ?: ""
|
||||
|
||||
/** The current "1 [ConverterUiState.defaultCurrencyCode] = ? Sats" rate, as a plain number. */
|
||||
/**
|
||||
* The current "1 [ConverterUiState.defaultCurrencyCode] = ? Sats" rate, as a whole (never
|
||||
* fractional) number of Sats — empty whenever [defaultCurrencyRate] is, so the two rates never
|
||||
* disagree about whether a rate is currently known.
|
||||
*/
|
||||
fun ConverterUiState.oneCurrencyToSats(): String {
|
||||
val rate = rateDisplays[defaultCurrencyCode]?.toBigDecimalOrNull() ?: return ""
|
||||
return CurrencyConverter.satsPerCurrencyUnit(rate)?.let { formatAmount(it, 2) } ?: ""
|
||||
val rate = defaultCurrencyRate().toBigDecimalOrNull() ?: return ""
|
||||
return CurrencyConverter.satsPerCurrencyUnit(rate)?.let { formatAmount(it, 0) } ?: ""
|
||||
}
|
||||
|
||||
/** The pinned, non-removable "Current Currency" shown in the currency picker's own section. */
|
||||
|
||||
@@ -143,10 +143,16 @@ class PriceViewModel(
|
||||
fun refresh() {
|
||||
if (currentSource === manualSource && manualSource.rate == null) {
|
||||
// No rate typed in (yet): nothing to price fiat currencies with, so clear any stale
|
||||
// rate this might otherwise still compute fiat amounts from.
|
||||
// rate this might otherwise still compute fiat amounts (or the derived "currency to
|
||||
// Sats" rate) from.
|
||||
rates = null
|
||||
_uiState.update {
|
||||
it.copy(isLoading = false, errorMessage = null, pricedCurrencyCodes = emptySet())
|
||||
it.copy(
|
||||
isLoading = false,
|
||||
errorMessage = null,
|
||||
pricedCurrencyCodes = emptySet(),
|
||||
rateDisplays = emptyMap(),
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user