Skip to content

Commit

Permalink
Do not recalculate after swap, round off immediately after calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrlzy committed Jan 30, 2025
1 parent f070f82 commit c38cdff
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import dev.arkbuilders.rate.core.domain.CurrUtils
import dev.arkbuilders.rate.core.domain.model.AmountStr
import dev.arkbuilders.rate.core.domain.model.CurrencyCode
import dev.arkbuilders.rate.core.domain.model.toAmount
import dev.arkbuilders.rate.core.domain.model.toStrAmount
import dev.arkbuilders.rate.core.domain.repo.AnalyticsManager
import dev.arkbuilders.rate.core.domain.repo.CodeUseStatRepo
import dev.arkbuilders.rate.core.domain.toBigDecimalArk
Expand Down Expand Up @@ -143,24 +142,15 @@ class AddQuickViewModel(
if (state.currencies.size < 2)
return@intent

val newFrom =
state.currencies.last().let { amount ->
if (amount.value.isEmpty())
return@let amount

val withoutCommas = amount.value.replace(",", "")
amount.copy(value = CurrUtils.roundOff(withoutCommas.toBigDecimalArk()))
}
val newList =
val newFrom = state.currencies.last()
val newCurrencies =
state.currencies.toMutableList().apply {
removeLast()
add(0, newFrom)
}

val calc = calcToResult(newList)

reduce {
state.copy(currencies = calc)
state.copy(currencies = newCurrencies)
}
}

Expand Down Expand Up @@ -215,7 +205,8 @@ class AddQuickViewModel(
it.copy(value = "")
} else {
val (amount, _) = convertUseCase.invoke(from.toAmount(), it.code)
amount.toStrAmount()
val roundValue = CurrUtils.roundOff(amount.value)
AmountStr(it.code, roundValue)
}
}
return listOf(from) + new
Expand Down

0 comments on commit c38cdff

Please sign in to comment.