From 1169c95f01b3b688293eb9edf1aeb801b8c933c8 Mon Sep 17 00:00:00 2001 From: Brandon McAnsh Date: Sun, 11 Feb 2024 16:43:27 -0500 Subject: [PATCH] chore: more handling of currencies when no symbol available Signed-off-by: Brandon McAnsh --- .../main/java/com/getcode/util/Currency.kt | 4 +-- .../giveKin/BaseAmountCurrencyViewModel.kt | 32 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/getcode/util/Currency.kt b/app/src/main/java/com/getcode/util/Currency.kt index cb36963de..01d4e147e 100644 --- a/app/src/main/java/com/getcode/util/Currency.kt +++ b/app/src/main/java/com/getcode/util/Currency.kt @@ -106,8 +106,8 @@ fun formatAmountString(resources: ResourceHelper, currency: Currency, amount: Do }" } else { when { - currency.code != currency.symbol -> { - "$${FormatUtils.format(amount)} ${resources.getString(R.string.core_ofKin)}" + currency.code == currency.symbol -> { + "${FormatUtils.format(amount)} ${resources.getString(R.string.core_ofKin)}" } else -> { "${currency.symbol}${FormatUtils.format(amount)} ${resources.getString(R.string.core_ofKin)}" diff --git a/app/src/main/java/com/getcode/view/main/giveKin/BaseAmountCurrencyViewModel.kt b/app/src/main/java/com/getcode/view/main/giveKin/BaseAmountCurrencyViewModel.kt index 62a71bf1e..b471ee892 100644 --- a/app/src/main/java/com/getcode/view/main/giveKin/BaseAmountCurrencyViewModel.kt +++ b/app/src/main/java/com/getcode/view/main/giveKin/BaseAmountCurrencyViewModel.kt @@ -14,6 +14,7 @@ import com.getcode.network.repository.BalanceRepository import com.getcode.network.repository.PrefRepository import com.getcode.network.repository.replaceParam import com.getcode.util.CurrencyUtils +import com.getcode.util.Kin import com.getcode.util.NumberInputHelper import com.getcode.util.locale.LocaleHelper import com.getcode.util.resources.ResourceHelper @@ -27,10 +28,13 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filterNotNull +import kotlinx.coroutines.flow.flatMapLatest +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.reactive.asFlow import kotlin.math.min sealed class CurrencyListItem { @@ -81,6 +85,16 @@ abstract class BaseAmountCurrencyViewModel( open fun init() { numberInputHelper.reset() + flowOf(SessionManager.getKeyPair()) + .filterNotNull() + .flatMapLatest { + client.fetchTransactionLimits(it) + .subscribeOn(Schedulers.io()) + .asFlow() + }.onEach { sendLimits -> + setCurrencyUiModel(getCurrencyUiModel().copy(sendLimitsMap = sendLimits)) + }.launchIn(viewModelScope) + combine( exchange.observeRates() .map { currencyUtils.getCurrenciesWithRates(it) }, @@ -106,16 +120,6 @@ abstract class BaseAmountCurrencyViewModel( setCurrencyUiModel(currencyModel) setAmountUiModel(amountModel) }.launchIn(viewModelScope) - - SessionManager.getKeyPair()?.let { - client.fetchTransactionLimits(it) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .doOnNext { sendLimitsMap -> - setCurrencyUiModel(getCurrencyUiModel().copy(sendLimitsMap = sendLimitsMap)) - } - .subscribe({}, ErrorUtils::handleError) - } } protected open fun onAmountChanged( @@ -329,7 +333,11 @@ abstract class BaseAmountCurrencyViewModel( } else { return if (amountInput == 0.0) { val currencyValue = FormatUtils.format(amountAvailable) - val kinValue = "${currency.symbol}$currencyValue" + val kinValue = if (currency.code != currency.symbol) { + "${currency.symbol}$currencyValue" + } else { + currencyValue + } "${getString(R.string.subtitle_enterUpTo).replaceParam(kinValue)} " + getString(R.string.core_ofKin) } else { @@ -338,7 +346,7 @@ abstract class BaseAmountCurrencyViewModel( } } - protected fun isKin(selectedCurrency: Currency): Boolean = selectedCurrency.code == "KIN" + private fun isKin(selectedCurrency: Currency): Boolean = selectedCurrency.code == Currency.Kin.code private fun isCaptionConversion(selectedCurrency: Currency, amount: Double?): Boolean = !isKin(selectedCurrency) && amount != 0.0