Skip to content

Commit

Permalink
[#3923] Read base from states whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan committed Sep 14, 2024
1 parent 0182cea commit 3a11099
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CalculatorViewModel(
data.conversion?.let {
calculateConversions(it, ConversionState.Cached(it.date))
} ?: viewModelScope.launch {
runCatching { backendApiService.getConversion(calculationStorage.currentBase) }
runCatching { backendApiService.getConversion(state.value.base) }
.onFailure(::updateConversionFailed)
.onSuccess(::updateConversionSuccess)
}
Expand All @@ -119,7 +119,7 @@ class CalculatorViewModel(
private fun updateConversionFailed(t: Throwable) = viewModelScope.launch {
Logger.w(t) { "CalculatorViewModel updateConversionFailed" }
conversionDataSource.getConversionByBase(
calculationStorage.currentBase
state.value.base
)?.let {
calculateConversions(it, ConversionState.Offline(it.date))
} ?: run {
Expand Down Expand Up @@ -231,7 +231,7 @@ class CalculatorViewModel(
sendEffect {
CalculatorEffect.ShowConversion(
currency.getConversionStringFromBase(
calculationStorage.currentBase,
state.value.base,
data.conversion
),
currency.code
Expand Down

0 comments on commit 3a11099

Please sign in to comment.