@@ -46,6 +46,7 @@ class CalculatorViewModel @Inject constructor(
4646 val uiState: StateFlow <CalculatorUiState > = _uiState .asStateFlow()
4747 private var pendingValues: CalculatorValues ? = null
4848 private var lastCurrencyKey: CalculatorCurrencyKey ? = null
49+ private var lastRates: ImmutableList <FxRate >? = null
4950 private var activeInput: MoneyType ? = null
5051
5152 val isCalculatorWidgetEnabled: StateFlow <Boolean > = widgetsRepo.widgetsDataFlow
@@ -164,14 +165,17 @@ class CalculatorViewModel @Inject constructor(
164165 val currencyKey = CalculatorCurrencyKey (
165166 selectedCurrency = currencyState.selectedCurrency,
166167 displayUnit = currencyState.displayUnit,
167- rates = currencyState.rates,
168168 )
169169 val previousCurrencyKey = lastCurrencyKey
170+ val previousRates = lastRates
170171 lastCurrencyKey = currencyKey
172+ lastRates = currencyState.rates
171173
172- val currencyChanged = previousCurrencyKey != null && previousCurrencyKey != currencyKey
174+ val currencyChanged = previousCurrencyKey != null &&
175+ previousCurrencyKey.selectedCurrency != currencyKey.selectedCurrency
173176 val displayUnitChanged = previousCurrencyKey != null &&
174177 previousCurrencyKey.displayUnit != currencyKey.displayUnit
178+ val ratesChanged = previousRates != null && previousRates != currencyState.rates
175179 val isInitialSync = previousCurrencyKey == null
176180 val nextActiveValues = deriveActiveValues(
177181 activeValues = activeValues,
@@ -188,7 +192,7 @@ class CalculatorViewModel @Inject constructor(
188192 )
189193 }
190194
191- val shouldRefreshFiat = isInitialSync || currencyChanged || shouldHydrateFiatFromStoredBtc(
195+ val shouldRefreshFiat = isInitialSync || currencyChanged || ratesChanged || shouldHydrateFiatFromStoredBtc(
192196 storedBtcValue = storedValues.btcValue,
193197 storedFiatValue = storedValues.fiatValue,
194198 currentFiatValue = nextActiveValues.fiatValue,
@@ -219,7 +223,10 @@ class CalculatorViewModel @Inject constructor(
219223 if (convertedFiat.isEmpty()) return persistCanonicalValues(activeValues, nextActiveValues)
220224
221225 val updatedValues = nextActiveValues.copy(fiatValue = convertedFiat)
222- updateCalculatorValues(updatedValues)
226+ persistCanonicalValuesIfNeeded(
227+ activeValues = activeValues,
228+ nextActiveValues = updatedValues,
229+ )
223230 return updatedValues
224231 }
225232
@@ -371,7 +378,6 @@ data class CalculatorUiState(
371378private data class CalculatorCurrencyKey (
372379 val selectedCurrency : String ,
373380 val displayUnit : BitcoinDisplayUnit ,
374- val rates : ImmutableList <FxRate >,
375381)
376382
377383internal fun shouldHydrateFiatFromStoredBtc (
0 commit comments