From dda836274c3d2a38cb140bc682a4b2068a69b664 Mon Sep 17 00:00:00 2001 From: Terry Yiu Date: Wed, 9 Sep 2026 08:56:24 +0300 Subject: [PATCH] Simplify Manual source UI to just the default currency The manual rate source only ever prices the default currency, so the currency selector, additional currency rows, and the "updated" part of the status line no longer make sense for it. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01FXcrACM5sok3M1KQJ8kByy --- iosApp/iosApp/ContentView.swift | 36 +++++++++++-------- .../satsprice/ui/ConverterUiStateDisplay.kt | 1 + .../xyz/tyiu/satsprice/ui/PriceScreen.kt | 27 ++++++++------ 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/iosApp/iosApp/ContentView.swift b/iosApp/iosApp/ContentView.swift index 89d81da..8c44246 100644 --- a/iosApp/iosApp/ContentView.swift +++ b/iosApp/iosApp/ContentView.swift @@ -111,18 +111,24 @@ struct ContentView: View { } Section(IosLocalizationKt.localizedString(resource: MR.strings.shared.currencies_section_title)) { - Button( - state.selectedCurrencyCodes.count <= 1 - ? IosLocalizationKt.localizedString(resource: MR.strings.shared.add_currency) - : IosLocalizationKt.localizedFormattedString( - resource: MR.strings.shared.currencies_selected_count, - args: [state.selectedCurrencyCodes.count] - ) - ) { - showCurrencyPicker = true + if !state.isManualSource { + Button( + state.selectedCurrencyCodes.count <= 1 + ? IosLocalizationKt.localizedString(resource: MR.strings.shared.add_currency) + : IosLocalizationKt.localizedFormattedString( + resource: MR.strings.shared.currencies_selected_count, + args: [state.selectedCurrencyCodes.count] + ) + ) { + showCurrencyPicker = true + } } - ForEach(Array(state.fiatRows.enumerated()), id: \.element.code) { index, row in + let displayedRows = state.isManualSource + ? state.fiatRows.filter { $0.code == state.defaultCurrencyCode } + : state.fiatRows + + ForEach(Array(displayedRows.enumerated()), id: \.element.code) { index, row in amountRow( label: currencyFieldLabel(for: row.code), value: row.amount, @@ -132,12 +138,12 @@ struct ContentView: View { isPriced: state.pricedCurrencyCodes.contains(row.code), sourceName: state.sourceName, onMoveUp: index > 0 ? { - var codes = state.fiatRows.map(\.code) + var codes = displayedRows.map(\.code) codes.move(fromOffsets: [index], toOffset: index - 1) viewModel.onFiatCurrenciesReordered(codes) } : nil, - onMoveDown: index < state.fiatRows.count - 1 ? { - var codes = state.fiatRows.map(\.code) + onMoveDown: index < displayedRows.count - 1 ? { + var codes = displayedRows.map(\.code) codes.move(fromOffsets: [index], toOffset: index + 2) viewModel.onFiatCurrenciesReordered(codes) } : nil @@ -145,14 +151,14 @@ struct ContentView: View { .deleteDisabled(row.code == state.defaultCurrencyCode) } .onMove { indices, newOffset in - var codes = state.fiatRows.map(\.code) + var codes = displayedRows.map(\.code) codes.move(fromOffsets: indices, toOffset: newOffset) viewModel.onFiatCurrenciesReordered(codes) } #if os(iOS) .onDelete { indexSet in for index in indexSet { - viewModel.onFiatCurrencyToggled(state.fiatRows[index].code) + viewModel.onFiatCurrencyToggled(displayedRows[index].code) } } #endif diff --git a/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/ConverterUiStateDisplay.kt b/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/ConverterUiStateDisplay.kt index fcf1a64..7c79f55 100644 --- a/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/ConverterUiStateDisplay.kt +++ b/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/ConverterUiStateDisplay.kt @@ -10,6 +10,7 @@ import kotlin.time.Instant /** Derived display strings/flags shared between the Compose UI and the iOS SwiftUI bridge. */ fun ConverterUiState.statusLine(): String { + if (isManualSource) return if (sourceName.isEmpty()) "" else "via $sourceName" val updated = lastUpdated?.let { "updated ${it.toDateTimeString()}" } ?: "loading rates…" return if (sourceName.isEmpty()) updated else "via $sourceName, $updated" } diff --git a/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/PriceScreen.kt b/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/PriceScreen.kt index 07f2cd2..d25a985 100644 --- a/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/PriceScreen.kt +++ b/shared/src/commonMain/kotlin/xyz/tyiu/satsprice/ui/PriceScreen.kt @@ -311,18 +311,25 @@ fun PriceScreen( verticalAlignment = Alignment.CenterVertically, ) { Text(stringResource(MR.strings.currencies_section_title), style = MaterialTheme.typography.titleMedium) - OutlinedButton(onClick = { showCurrencyPicker = true }) { - Text( - if (state.selectedFiatCurrencies.size <= 1) { - stringResource(MR.strings.add_currency) - } else { - stringResource(MR.strings.currencies_selected_count, state.selectedFiatCurrencies.size) - }, - ) + if (!state.isManualSource) { + OutlinedButton(onClick = { showCurrencyPicker = true }) { + Text( + if (state.selectedFiatCurrencies.size <= 1) { + stringResource(MR.strings.add_currency) + } else { + stringResource(MR.strings.currencies_selected_count, state.selectedFiatCurrencies.size) + }, + ) + } } } - state.selectedFiatCurrencies.forEachIndexed { index, code -> + val displayedCurrencies = if (state.isManualSource) { + listOf(state.defaultCurrencyCode) + } else { + state.selectedFiatCurrencies + } + displayedCurrencies.forEachIndexed { index, code -> key(code) { Row( modifier = Modifier.fillMaxWidth(), @@ -350,7 +357,7 @@ fun PriceScreen( CurrencyRowMenu( code = code, canMoveUp = index > 0, - canMoveDown = index < state.selectedFiatCurrencies.lastIndex, + canMoveDown = index < displayedCurrencies.lastIndex, canRemove = code != state.defaultCurrencyCode, onMoveUp = { viewModel.onFiatCurrenciesReordered(