Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/java/com/getcode/util/Currency.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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) },
Expand All @@ -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(
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down