Updated on 2026-08-14
This commit is contained in:
parent
dc5becd3c5
commit
557aae44ac
3 changed files with 16 additions and 5 deletions
|
|
@ -138,7 +138,7 @@ fun String.parseToBigDecimal(decimals: Int): BigDecimal {
|
|||
}
|
||||
}
|
||||
|
||||
fun BigDecimal.parseBigDecimal(decimals: Int, roundingMode: RoundingMode = RoundingMode.DOWN): String {
|
||||
fun BigDecimal.parseBigDecimal(decimals: Int, roundingMode: RoundingMode = RoundingMode.HALF_UP): String {
|
||||
val decimalFormat = DecimalFormat().apply {
|
||||
decimalFormatSymbols = DecimalFormatSymbols(Locale.getDefault())
|
||||
isParseBigDecimal = true
|
||||
|
|
|
|||
|
|
@ -7,7 +7,9 @@ import arrow.core.raise.either
|
|||
import arrow.core.raise.ensure
|
||||
import arrow.core.raise.ensureNotNull
|
||||
import arrow.core.toNonEmptyListOrNull
|
||||
import com.tangem.domain.staking.model.stakekit.YieldBalance
|
||||
import com.tangem.domain.tokens.model.*
|
||||
import com.tangem.utils.extensions.orZero
|
||||
import java.math.BigDecimal
|
||||
|
||||
internal class TokenListSortingOperations(
|
||||
|
|
@ -83,7 +85,7 @@ internal class TokenListSortingOperations(
|
|||
return if (isAnyTokenLoading) {
|
||||
tokens
|
||||
} else {
|
||||
tokens.sortedByDescending { it.value.fiatAmount ?: BigDecimal.ZERO }
|
||||
tokens.sortedByDescending { it.getTotalBalance() }
|
||||
.toNonEmptyListOrNull()
|
||||
?: error("Tokens can not be empty here")
|
||||
}
|
||||
|
|
@ -92,12 +94,20 @@ internal class TokenListSortingOperations(
|
|||
private fun sortGroupsByBalance(groupsWithSortedTokens: NonEmptyList<NetworkGroup>): NonEmptyList<NetworkGroup> {
|
||||
return groupsWithSortedTokens
|
||||
.sortedByDescending { group ->
|
||||
group.currencies.sumOf { it.value.fiatAmount ?: BigDecimal.ZERO }
|
||||
group.currencies.sumOf { it.getTotalBalance() }
|
||||
}
|
||||
.toNonEmptyListOrNull()
|
||||
?: error("Tokens can not be empty here")
|
||||
}
|
||||
|
||||
private fun CryptoCurrencyStatus.getTotalBalance(): BigDecimal {
|
||||
val yieldBalance = value.yieldBalance as? YieldBalance.Data
|
||||
val totalYieldBalance = yieldBalance?.getTotalWithRewardsStakingBalance().orZero()
|
||||
val totalFiatYieldBalance = totalYieldBalance.multiply(value.fiatRate.orZero())
|
||||
|
||||
return value.fiatAmount?.plus(totalFiatYieldBalance).orZero()
|
||||
}
|
||||
|
||||
sealed class Error {
|
||||
|
||||
object EmptyTokens : Error()
|
||||
|
|
|
|||
|
|
@ -153,8 +153,9 @@ internal class TokenDetailsLoadedBalanceConverter(
|
|||
StakingBlockUM.Error(iconState = iconState)
|
||||
}
|
||||
else -> {
|
||||
val stakingRewardAmount = yieldBalance?.getRewardStakingBalance()
|
||||
val stakingFiatAmount = stakingCryptoAmount?.let { status.value.fiatRate?.multiply(it) }
|
||||
val fiatRate = status.value.fiatRate
|
||||
val stakingRewardAmount = yieldBalance?.getRewardStakingBalance()?.let { fiatRate?.multiply(it) }
|
||||
val stakingFiatAmount = stakingCryptoAmount?.let { fiatRate?.multiply(it) }
|
||||
|
||||
getStakedState(
|
||||
status = status,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue