Skip to content

Commit f1847ea

Browse files
authored
Merge pull request #171 from code-payments/chore/currencies-no-symbol
chore: more handling of currencies when no symbol available
2 parents d06714d + 1169c95 commit f1847ea

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

app/src/main/java/com/getcode/util/Currency.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ fun formatAmountString(resources: ResourceHelper, currency: Currency, amount: Do
106106
}"
107107
} else {
108108
when {
109-
currency.code != currency.symbol -> {
110-
"$${FormatUtils.format(amount)} ${resources.getString(R.string.core_ofKin)}"
109+
currency.code == currency.symbol -> {
110+
"${FormatUtils.format(amount)} ${resources.getString(R.string.core_ofKin)}"
111111
}
112112
else -> {
113113
"${currency.symbol}${FormatUtils.format(amount)} ${resources.getString(R.string.core_ofKin)}"

app/src/main/java/com/getcode/view/main/giveKin/BaseAmountCurrencyViewModel.kt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.getcode.network.repository.BalanceRepository
1414
import com.getcode.network.repository.PrefRepository
1515
import com.getcode.network.repository.replaceParam
1616
import com.getcode.util.CurrencyUtils
17+
import com.getcode.util.Kin
1718
import com.getcode.util.NumberInputHelper
1819
import com.getcode.util.locale.LocaleHelper
1920
import com.getcode.util.resources.ResourceHelper
@@ -27,10 +28,13 @@ import kotlinx.coroutines.Dispatchers
2728
import kotlinx.coroutines.flow.combine
2829
import kotlinx.coroutines.flow.distinctUntilChanged
2930
import kotlinx.coroutines.flow.filterNotNull
31+
import kotlinx.coroutines.flow.flatMapLatest
32+
import kotlinx.coroutines.flow.flowOf
3033
import kotlinx.coroutines.flow.flowOn
3134
import kotlinx.coroutines.flow.launchIn
3235
import kotlinx.coroutines.flow.map
3336
import kotlinx.coroutines.flow.onEach
37+
import kotlinx.coroutines.reactive.asFlow
3438
import kotlin.math.min
3539

3640
sealed 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

Comments
 (0)