@@ -14,6 +14,7 @@ import com.getcode.network.repository.BalanceRepository
1414import com.getcode.network.repository.PrefRepository
1515import com.getcode.network.repository.replaceParam
1616import com.getcode.util.CurrencyUtils
17+ import com.getcode.util.Kin
1718import com.getcode.util.NumberInputHelper
1819import com.getcode.util.locale.LocaleHelper
1920import com.getcode.util.resources.ResourceHelper
@@ -27,10 +28,13 @@ import kotlinx.coroutines.Dispatchers
2728import kotlinx.coroutines.flow.combine
2829import kotlinx.coroutines.flow.distinctUntilChanged
2930import kotlinx.coroutines.flow.filterNotNull
31+ import kotlinx.coroutines.flow.flatMapLatest
32+ import kotlinx.coroutines.flow.flowOf
3033import kotlinx.coroutines.flow.flowOn
3134import kotlinx.coroutines.flow.launchIn
3235import kotlinx.coroutines.flow.map
3336import kotlinx.coroutines.flow.onEach
37+ import kotlinx.coroutines.reactive.asFlow
3438import kotlin.math.min
3539
3640sealed class CurrencyListItem {
@@ -81,6 +85,16 @@ abstract class BaseAmountCurrencyViewModel(
8185 open fun init () {
8286 numberInputHelper.reset()
8387
88+ flowOf(SessionManager .getKeyPair())
89+ .filterNotNull()
90+ .flatMapLatest {
91+ client.fetchTransactionLimits(it)
92+ .subscribeOn(Schedulers .io())
93+ .asFlow()
94+ }.onEach { sendLimits ->
95+ setCurrencyUiModel(getCurrencyUiModel().copy(sendLimitsMap = sendLimits))
96+ }.launchIn(viewModelScope)
97+
8498 combine(
8599 exchange.observeRates()
86100 .map { currencyUtils.getCurrenciesWithRates(it) },
@@ -106,16 +120,6 @@ abstract class BaseAmountCurrencyViewModel(
106120 setCurrencyUiModel(currencyModel)
107121 setAmountUiModel(amountModel)
108122 }.launchIn(viewModelScope)
109-
110- SessionManager .getKeyPair()?.let {
111- client.fetchTransactionLimits(it)
112- .subscribeOn(Schedulers .io())
113- .observeOn(AndroidSchedulers .mainThread())
114- .doOnNext { sendLimitsMap ->
115- setCurrencyUiModel(getCurrencyUiModel().copy(sendLimitsMap = sendLimitsMap))
116- }
117- .subscribe({}, ErrorUtils ::handleError)
118- }
119123 }
120124
121125 protected open fun onAmountChanged (
@@ -329,7 +333,11 @@ abstract class BaseAmountCurrencyViewModel(
329333 } else {
330334 return if (amountInput == 0.0 ) {
331335 val currencyValue = FormatUtils .format(amountAvailable)
332- val kinValue = " ${currency.symbol}$currencyValue "
336+ val kinValue = if (currency.code != currency.symbol) {
337+ " ${currency.symbol}$currencyValue "
338+ } else {
339+ currencyValue
340+ }
333341 " ${getString(R .string.subtitle_enterUpTo).replaceParam(kinValue)} " +
334342 getString(R .string.core_ofKin)
335343 } else {
@@ -338,7 +346,7 @@ abstract class BaseAmountCurrencyViewModel(
338346 }
339347 }
340348
341- protected fun isKin (selectedCurrency : Currency ): Boolean = selectedCurrency.code == " KIN "
349+ private fun isKin (selectedCurrency : Currency ): Boolean = selectedCurrency.code == Currency . Kin .code
342350
343351 private fun isCaptionConversion (selectedCurrency : Currency , amount : Double? ): Boolean =
344352 ! isKin(selectedCurrency) && amount != 0.0
0 commit comments