Skip to content

Commit

Permalink
[#3929] Extract updating the symbol into new method (#3930)
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaozhan authored Sep 15, 2024
1 parent eb62295 commit e23dee2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class CalculatorViewModel(
Logger.d { "CalculatorViewModel observeBase $it" }
calculationStorage.currentBase = it
currentBaseChanged(it)
updateSymbol()
}
.launchIn(viewModelScope)

Expand Down Expand Up @@ -173,23 +174,25 @@ class CalculatorViewModel(
}
}

private fun currentBaseChanged(newBase: String) =
viewModelScope.launch {
data.conversion = null
val symbol = currencyDataSource.getCurrencyByCode(newBase)?.symbol.orEmpty()
setState {
copy(
base = newBase,
input = input,
symbol = symbol
)
}
private fun currentBaseChanged(newBase: String) {
data.conversion = null
setState {
copy(
base = newBase,
input = input
)
}

analyticsManager.trackEvent(Event.BaseChange(Param.Base(newBase)))
analyticsManager.setUserProperty(UserProperty.BaseCurrency(newBase))
analyticsManager.trackEvent(Event.BaseChange(Param.Base(newBase)))
analyticsManager.setUserProperty(UserProperty.BaseCurrency(newBase))

updateConversion()
}
updateConversion()
}

private suspend fun updateSymbol() {
val symbol = currencyDataSource.getCurrencyByCode(state.value.base)?.symbol.orEmpty()
setState { copy(symbol = symbol) }
}

// region Event
override fun onKeyPress(key: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ internal class CalculatorViewModelTest {
)
)
calculationStorage.currentBase = currency1.code
calculationStorage.lastInput = ""
currencyDataSource.getCurrencyByCode(currency1.code)
analyticsManager.trackEvent(Event.BaseChange(Param.Base(currency1.code)))
analyticsManager.setUserProperty(UserProperty.BaseCurrency(currency1.code))
currencyDataSource.getCurrencyByCode(currency1.code)
calculationStorage.lastInput = ""
calculationStorage.lastInput = input
}
}
Expand All @@ -354,9 +354,9 @@ internal class CalculatorViewModelTest {

verifySuspend(VerifyMode.order) {
calculationStorage.currentBase = currency2.code
currencyDataSource.getCurrencyByCode(currency2.code)
analyticsManager.trackEvent(Event.BaseChange(Param.Base(currency2.code)))
analyticsManager.setUserProperty(UserProperty.BaseCurrency(currency2.code))
currencyDataSource.getCurrencyByCode(currency2.code)
}
}
}
Expand Down

0 comments on commit e23dee2

Please sign in to comment.