Updated on 2026-08-14

This commit is contained in:
Tangem 2025-03-31 15:30:48 +05:00
parent e4477a2402
commit 57684bfeef
18 changed files with 105 additions and 120 deletions

View file

@ -35,6 +35,7 @@ dependencies {
implementation(projects.domain.models)
implementation(projects.domain.legacy)
implementation(projects.domain.staking.models)
implementation(projects.domain.staking)
implementation(projects.domain.tokens.models)
implementation(projects.domain.transaction.models)
implementation(projects.domain.wallets.models)

View file

@ -14,8 +14,8 @@ import com.tangem.core.ui.format.bigdecimal.percent
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.StatusSource
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.staking.utils.getTotalWithRewardsStakingBalance
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.lib.crypto.BlockchainUtils
import com.tangem.utils.StringsSigns.DASH_SIGN
import com.tangem.utils.converter.Converter
import com.tangem.utils.extensions.isZero
@ -121,36 +121,27 @@ class TokenItemStateConverter(
companion object {
fun CryptoCurrencyStatus.getFormattedFiatAmount(appCurrency: AppCurrency, includeStaking: Boolean): String {
fun CryptoCurrencyStatus.getFormattedFiatAmount(appCurrency: AppCurrency): String {
val fiatAmount = value.fiatAmount ?: return DASH_SIGN
val totalAmount = if (includeStaking) {
val fiatYieldBalance = value.fiatRate?.times(getStakedBalance()).orZero()
fiatAmount.plus(fiatYieldBalance)
} else {
fiatAmount
}
val fiatYieldBalance = value.fiatRate?.times(getStakedBalance()).orZero()
val totalAmount = fiatAmount.plus(fiatYieldBalance)
return totalAmount.format {
fiat(fiatCurrencyCode = appCurrency.code, fiatCurrencySymbol = appCurrency.symbol)
}
}
fun CryptoCurrencyStatus.getFormattedCryptoAmount(includeStaking: Boolean): String {
fun CryptoCurrencyStatus.getFormattedCryptoAmount(): String {
val cryptoAmount = value.amount ?: return DASH_SIGN
val totalAmount = if (includeStaking) {
cryptoAmount.plus(getStakedBalance())
} else {
cryptoAmount
}
val totalAmount = cryptoAmount.plus(getStakedBalance())
return totalAmount.format { crypto(currency) }
}
private fun CryptoCurrencyStatus.getStakedBalance() =
(value.yieldBalance as? YieldBalance.Data)?.getTotalWithRewardsStakingBalance().orZero()
private fun CryptoCurrencyStatus.getStakedBalance() = (value.yieldBalance as? YieldBalance.Data)
?.getTotalWithRewardsStakingBalance(blockchainId = currency.network.id.value).orZero()
private fun createTitleState(currencyStatus: CryptoCurrencyStatus): TokenItemState.TitleState {
return when (val value = currencyStatus.value) {
@ -200,11 +191,7 @@ class TokenItemStateConverter(
is CryptoCurrencyStatus.NoAccount,
-> {
TokenItemState.Subtitle2State.TextContent(
text = status.getFormattedCryptoAmount(
includeStaking = BlockchainUtils.isIncludeStakingTotalBalance(
status.currency.network.id.value,
),
),
text = status.getFormattedCryptoAmount(),
isFlickering = status.value.isFlickering(),
)
}
@ -227,12 +214,7 @@ class TokenItemStateConverter(
is CryptoCurrencyStatus.NoAccount,
-> {
TokenItemState.FiatAmountState.Content(
text = status.getFormattedFiatAmount(
appCurrency = appCurrency,
includeStaking = BlockchainUtils.isIncludeStakingTotalBalance(
status.currency.network.id.value,
),
),
text = status.getFormattedFiatAmount(appCurrency = appCurrency),
isFlickering = status.value.isFlickering(),
icons = buildList {
if (!status.getStakedBalance().isZero()) {

View file

@ -23,6 +23,7 @@ dependencies {
implementation(projects.domain.txhistory.models)
implementation(projects.domain.wallets.models)
implementation(projects.domain.staking.models)
implementation(projects.domain.staking)
/** Project - Data */
implementation(projects.core.datasource)

View file

@ -7,6 +7,7 @@ import com.tangem.blockchain.common.ReserveAmountProvider
import com.tangem.blockchain.common.UtxoAmountLimitProvider
import com.tangem.data.tokens.converters.UtxoConverter
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.staking.utils.getTotalStakingBalance
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.CurrencyAmount
@ -18,6 +19,7 @@ import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.domain.wallets.models.UserWalletId
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
import com.tangem.utils.extensions.isZero
import com.tangem.utils.extensions.orZero
import kotlinx.coroutines.withContext
import java.math.BigDecimal
@ -132,8 +134,10 @@ internal class DefaultCurrencyChecksRepository(
): CryptoCurrencyWarning.Rent? {
val rentData = walletManagersFacade.getRentInfo(userWalletId, currencyStatus.currency.network) ?: return null
val balanceValue = currencyStatus.value as? CryptoCurrencyStatus.Loaded ?: return null
val stakingTotalBalance =
(balanceValue.yieldBalance as? YieldBalance.Data)?.getTotalStakingBalance() ?: BigDecimal.ZERO
val stakingBalance = balanceValue.yieldBalance as? YieldBalance.Data
val stakingTotalBalance = stakingBalance?.getTotalStakingBalance(
blockchainId = currencyStatus.currency.network.id.value,
).orZero()
return when {
balanceValue.amount.isZero() && stakingTotalBalance.isZero() -> null
balanceValue.amount < rentData.exemptionAmount && stakingTotalBalance.isZero() -> {

View file

@ -27,4 +27,5 @@ dependencies {
implementation(tangemDeps.blockchain) {
exclude(module = "joda-time")
}
implementation(projects.libs.crypto)
}

View file

@ -15,30 +15,7 @@ sealed class YieldBalance {
override val address: String,
val balance: YieldBalanceItem,
val source: StatusSource,
) : YieldBalance() {
fun getTotalWithRewardsStakingBalance(): BigDecimal {
return balance.items.sumOf { it.amount }
}
fun getTotalStakingBalance(): BigDecimal {
return balance.items
.filterNot { it.type == BalanceType.REWARDS }
.sumOf { it.amount }
}
fun getRewardStakingBalance(): BigDecimal {
return balance.items
.filter { it.type == BalanceType.REWARDS }
.sumOf { it.amount }
}
fun getValidatorsCount(): Int {
return balance.items
.filterNot { it.validatorAddress.isNullOrBlank() }
.distinctBy { it.validatorAddress }
.size
}
}
) : YieldBalance()
data class Empty(
override val integrationId: String?,

View file

@ -0,0 +1,39 @@
package com.tangem.domain.staking.utils
import com.tangem.domain.staking.model.stakekit.BalanceType
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.lib.crypto.BlockchainUtils
import java.math.BigDecimal
fun YieldBalance.Data.getTotalWithRewardsStakingBalance(blockchainId: String): BigDecimal {
return if (BlockchainUtils.isIncludeStakingTotalBalance(blockchainId = blockchainId)) {
balance.items.sumOf { it.amount }
} else {
getRewardStakingBalance()
}
}
fun YieldBalance.Data.getTotalStakingBalance(blockchainId: String): BigDecimal {
return if (BlockchainUtils.isIncludeStakingTotalBalance(blockchainId = blockchainId)) {
balance.items
.filterNot { it.type == BalanceType.REWARDS }
.sumOf { it.amount }
} else {
balance.items
.filterNot { it.type == BalanceType.REWARDS }
.sumOf { it.amount } - getRewardStakingBalance()
}
}
fun YieldBalance.Data.getRewardStakingBalance(): BigDecimal {
return balance.items
.filter { it.type == BalanceType.REWARDS }
.sumOf { it.amount }
}
fun YieldBalance.Data.getValidatorsCount(): Int {
return balance.items
.filterNot { it.validatorAddress.isNullOrBlank() }
.distinctBy { it.validatorAddress }
.size
}

View file

@ -4,10 +4,10 @@ import arrow.core.NonEmptyList
import com.tangem.domain.models.StatusSource
import com.tangem.domain.models.getResultStatusSource
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.staking.utils.getTotalWithRewardsStakingBalance
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.domain.tokens.model.TotalFiatBalance
import com.tangem.lib.crypto.BlockchainUtils
import com.tangem.lib.crypto.BlockchainUtils.isIncludeStakingTotalBalance
import com.tangem.utils.extensions.orZero
import java.math.BigDecimal
@ -22,8 +22,7 @@ internal class TokenListFiatBalanceOperations(
if (isAnyTokenLoading) return fiatBalance
for (token in currencies) {
val networkId = token.currency.network.id.value
val includeStakingBalance = isIncludeStakingTotalBalance(networkId)
val blockchainId = token.currency.network.id.value
when (val status = token.value) {
is CryptoCurrencyStatus.Loading -> {
fiatBalance = TotalFiatBalance.Loading
@ -38,7 +37,7 @@ internal class TokenListFiatBalanceOperations(
is CryptoCurrencyStatus.Unreachable,
is CryptoCurrencyStatus.NoAmount,
-> {
if (BlockchainUtils.isIncludeToBalanceOnError(networkId)) {
if (BlockchainUtils.isIncludeToBalanceOnError(blockchainId)) {
fiatBalance = recalculateNoAccountBalance(status, fiatBalance)
} else {
fiatBalance = TotalFiatBalance.Failed
@ -49,10 +48,10 @@ internal class TokenListFiatBalanceOperations(
fiatBalance = recalculateNoAccountBalance(status, fiatBalance)
}
is CryptoCurrencyStatus.Loaded -> {
fiatBalance = recalculateBalance(status, fiatBalance, includeStakingBalance)
fiatBalance = recalculateBalance(status, fiatBalance, blockchainId)
}
is CryptoCurrencyStatus.Custom -> {
fiatBalance = recalculateBalance(status, fiatBalance, includeStakingBalance)
fiatBalance = recalculateBalance(status, fiatBalance, blockchainId)
}
}
}
@ -77,16 +76,12 @@ internal class TokenListFiatBalanceOperations(
private fun recalculateBalance(
status: CryptoCurrencyStatus.Loaded,
currentBalance: TotalFiatBalance,
includeStakingBalance: Boolean,
blockchainId: String,
): TotalFiatBalance {
return with(currentBalance) {
val yieldBalance = status.yieldBalance as? YieldBalance.Data
val stakingBalance = yieldBalance?.getTotalWithRewardsStakingBalance().orZero()
val fiatStakingBalance = if (includeStakingBalance) {
status.fiatRate.times(stakingBalance)
} else {
BigDecimal.ZERO
}
val stakingBalance = yieldBalance?.getTotalWithRewardsStakingBalance(blockchainId).orZero()
val fiatStakingBalance = status.fiatRate.times(stakingBalance)
(this as? TotalFiatBalance.Loaded)?.copy(
amount = this.amount + status.fiatAmount + fiatStakingBalance,
) ?: TotalFiatBalance.Loaded(
@ -100,16 +95,13 @@ internal class TokenListFiatBalanceOperations(
private fun recalculateBalance(
status: CryptoCurrencyStatus.Custom,
currentBalance: TotalFiatBalance,
includeStakingBalance: Boolean,
blockchainId: String,
): TotalFiatBalance {
return with(currentBalance) {
val isTokenAmountCanBeSummarized = status.fiatAmount != null
val yieldBalance = (status.yieldBalance as? YieldBalance.Data)?.getTotalWithRewardsStakingBalance().orZero()
val fiatYieldBalance = if (includeStakingBalance) {
status.fiatRate?.times(yieldBalance).orZero()
} else {
BigDecimal.ZERO
}
val yieldBalance = (status.yieldBalance as? YieldBalance.Data)
?.getTotalWithRewardsStakingBalance(blockchainId).orZero()
val fiatYieldBalance = status.fiatRate?.times(yieldBalance).orZero()
(this as? TotalFiatBalance.Loaded)?.copy(
amount = this.amount + status.fiatAmount.orZero() + fiatYieldBalance,
isAllAmountsSummarized = isTokenAmountCanBeSummarized,

View file

@ -8,8 +8,8 @@ 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.staking.utils.getTotalWithRewardsStakingBalance
import com.tangem.domain.tokens.model.*
import com.tangem.lib.crypto.BlockchainUtils
import com.tangem.utils.extensions.orZero
import java.math.BigDecimal
@ -99,13 +99,8 @@ internal class TokenListSortingOperations(
private fun CryptoCurrencyStatus.getTotalBalance(): BigDecimal {
val yieldBalance = value.yieldBalance as? YieldBalance.Data
val totalYieldBalance = yieldBalance?.getTotalWithRewardsStakingBalance().orZero()
val totalFiatYieldBalance = if (BlockchainUtils.isIncludeStakingTotalBalance(currency.network.id.value)) {
totalYieldBalance.multiply(value.fiatRate.orZero())
} else {
BigDecimal.ZERO
}
val totalYieldBalance = yieldBalance?.getTotalWithRewardsStakingBalance(currency.network.id.value).orZero()
val totalFiatYieldBalance = totalYieldBalance.multiply(value.fiatRate.orZero())
return value.fiatAmount?.plus(totalFiatYieldBalance).orZero()
}

View file

@ -68,7 +68,7 @@ internal object OnrampTokenItemStateConverterFactory {
is CryptoCurrencyStatus.NoAccount,
-> {
TokenItemState.Subtitle2State.TextContent(
text = status.getFormattedCryptoAmount(includeStaking = false),
text = status.getFormattedCryptoAmount(),
isFlickering = status.value.isFlickering(),
)
}
@ -92,7 +92,7 @@ internal object OnrampTokenItemStateConverterFactory {
is CryptoCurrencyStatus.NoAccount,
-> {
TokenItemState.FiatAmountState.TextContent(
text = status.getFormattedFiatAmount(appCurrency = appCurrency, includeStaking = false),
text = status.getFormattedFiatAmount(appCurrency = appCurrency),
isAvailable = isAvailable,
isFlickering = status.value.isFlickering(),
)

View file

@ -36,6 +36,7 @@ import com.tangem.domain.staking.model.stakekit.*
import com.tangem.domain.staking.model.stakekit.action.StakingAction
import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType
import com.tangem.domain.staking.model.stakekit.transaction.StakingTransaction
import com.tangem.domain.staking.utils.getValidatorsCount
import com.tangem.domain.tokens.*
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.model.CryptoCurrencyStatus

View file

@ -7,6 +7,7 @@ import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.staking.model.stakekit.*
import com.tangem.domain.staking.model.stakekit.action.StakingActionType
import com.tangem.domain.staking.utils.getRewardStakingBalance
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.features.staking.impl.presentation.state.InnerYieldBalanceState
import com.tangem.features.staking.impl.presentation.state.YieldReward
@ -31,11 +32,10 @@ internal class YieldBalancesConverter(
val appCurrency = appCurrencyProvider()
val cryptoCurrency = cryptoCurrencyStatus.currency
val yieldBalance = cryptoCurrencyStatus.value.yieldBalance
val yieldBalance = cryptoCurrencyStatus.value.yieldBalance as? YieldBalance.Data
val balanceToShowItems = balancesToShowProvider()
return if (yieldBalance is YieldBalance.Data || balanceToShowItems.any { it.isPending }) {
val yieldBalance = yieldBalance as? YieldBalance.Data
return if (yieldBalance != null || balanceToShowItems.any { it.isPending }) {
val cryptoRewardsValue = yieldBalance?.getRewardStakingBalance()
val fiatRate = cryptoCurrencyStatus.value.fiatRate

View file

@ -5,10 +5,10 @@ import com.tangem.core.ui.format.bigdecimal.fiat
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.staking.utils.getTotalWithRewardsStakingBalance
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.feature.tokendetails.presentation.tokendetails.state.*
import com.tangem.feature.tokendetails.presentation.tokendetails.state.utils.getBalance
import com.tangem.lib.crypto.BlockchainUtils
import com.tangem.utils.Provider
import com.tangem.utils.converter.Converter
import java.math.BigDecimal
@ -30,10 +30,10 @@ internal class TokenDetailsBalanceSelectStateConverter(
}
val yieldBalance = cryptoCurrencyStatus.value.yieldBalance as? YieldBalance.Data
val stakingCryptoAmount = yieldBalance?.getTotalWithRewardsStakingBalance()
val stakingCryptoAmount = yieldBalance?.getTotalWithRewardsStakingBalance(
cryptoCurrencyStatus.currency.network.id.value,
)
val stakingFiatAmount = stakingCryptoAmount?.let { cryptoCurrencyStatus.value.fiatRate?.multiply(it) }
val includeStakingTotalBalance =
BlockchainUtils.isIncludeStakingTotalBalance(cryptoCurrencyStatus.currency.network.id.value)
copy(
tokenBalanceBlockState = if (tokenBalanceBlockState is TokenDetailsBalanceBlockState.Content) {
tokenBalanceBlockState.copy(
@ -43,13 +43,11 @@ internal class TokenDetailsBalanceSelectStateConverter(
stakingFiatAmount = stakingFiatAmount,
selectedBalanceType = value.type,
appCurrency = appCurrencyProvider(),
includeStaking = includeStakingTotalBalance,
),
displayCryptoBalance = formatCryptoAmount(
status = cryptoCurrencyStatus,
stakingCryptoAmount = stakingCryptoAmount,
selectedBalanceType = value.type,
includeStaking = includeStakingTotalBalance,
),
)
} else {
@ -64,9 +62,8 @@ internal class TokenDetailsBalanceSelectStateConverter(
stakingFiatAmount: BigDecimal?,
selectedBalanceType: BalanceType,
appCurrency: AppCurrency,
includeStaking: Boolean,
): String {
val fiatAmount = status.fiatAmount?.getBalance(selectedBalanceType, stakingFiatAmount, includeStaking)
val fiatAmount = status.fiatAmount?.getBalance(selectedBalanceType, stakingFiatAmount)
return fiatAmount.format {
fiat(
@ -80,9 +77,8 @@ internal class TokenDetailsBalanceSelectStateConverter(
status: CryptoCurrencyStatus,
stakingCryptoAmount: BigDecimal?,
selectedBalanceType: BalanceType,
includeStaking: Boolean,
): String {
val amount = status.value.amount?.getBalance(selectedBalanceType, stakingCryptoAmount, includeStaking)
val amount = status.value.amount?.getBalance(selectedBalanceType, stakingCryptoAmount)
return amount.format { crypto(status.currency) }
}

View file

@ -10,14 +10,16 @@ import com.tangem.core.ui.format.bigdecimal.*
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.models.StatusSource
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.staking.utils.getTotalWithRewardsStakingBalance
import com.tangem.domain.tokens.error.CurrencyStatusError
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
import com.tangem.feature.tokendetails.presentation.tokendetails.state.*
import com.tangem.feature.tokendetails.presentation.tokendetails.state.BalanceType
import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsBalanceBlockState
import com.tangem.feature.tokendetails.presentation.tokendetails.state.TokenDetailsState
import com.tangem.feature.tokendetails.presentation.tokendetails.state.components.TokenDetailsNotification
import com.tangem.feature.tokendetails.presentation.tokendetails.state.factory.txhistory.TokenDetailsTxHistoryTransactionStateConverter
import com.tangem.feature.tokendetails.presentation.tokendetails.state.utils.getBalance
import com.tangem.lib.crypto.BlockchainUtils.isIncludeStakingTotalBalance
import com.tangem.utils.Provider
import com.tangem.utils.StringsSigns.DASH_SIGN
import com.tangem.utils.converter.Converter
@ -84,10 +86,12 @@ internal class TokenDetailsLoadedBalanceConverter(
currentState: TokenDetailsBalanceBlockState,
status: CryptoCurrencyStatus,
): TokenDetailsBalanceBlockState {
val stakingCryptoAmount = (status.value.yieldBalance as? YieldBalance.Data)?.getTotalWithRewardsStakingBalance()
val stakingCryptoAmount =
(status.value.yieldBalance as? YieldBalance.Data)?.getTotalWithRewardsStakingBalance(
status.currency.network.id.value,
)
val stakingFiatAmount = stakingCryptoAmount?.let { status.value.fiatRate?.multiply(it) }
val isBalanceSelectorEnabled = !stakingCryptoAmount.isNullOrZero()
val includeStakingTotalBalance = isIncludeStakingTotalBalance(status.currency.network.id.value)
return when (status.value) {
is CryptoCurrencyStatus.NoQuote,
is CryptoCurrencyStatus.Loaded,
@ -102,13 +106,11 @@ internal class TokenDetailsLoadedBalanceConverter(
stakingFiatAmount,
currentState.selectedBalanceType,
appCurrencyProvider(),
includeStakingTotalBalance,
),
displayCryptoBalance = formatCryptoAmount(
status,
stakingCryptoAmount,
currentState.selectedBalanceType,
includeStakingTotalBalance,
),
balanceSegmentedButtonConfig = currentState.balanceSegmentedButtonConfig,
onBalanceSelect = clickIntents::onBalanceSelect,
@ -192,10 +194,9 @@ internal class TokenDetailsLoadedBalanceConverter(
stakingFiatAmount: BigDecimal?,
selectedBalanceType: BalanceType,
appCurrency: AppCurrency,
includeStaking: Boolean,
): String {
val fiatAmount = status.fiatAmount ?: return DASH_SIGN
val totalAmount = fiatAmount.getBalance(selectedBalanceType, stakingFiatAmount, includeStaking)
val totalAmount = fiatAmount.getBalance(selectedBalanceType, stakingFiatAmount)
return totalAmount.format {
fiat(
@ -209,10 +210,9 @@ internal class TokenDetailsLoadedBalanceConverter(
status: CryptoCurrencyStatus,
stakingCryptoAmount: BigDecimal?,
selectedBalanceType: BalanceType,
includeStaking: Boolean,
): String {
val amount = status.value.amount ?: return DASH_SIGN
val totalAmount = amount.getBalance(selectedBalanceType, stakingCryptoAmount, includeStaking)
val totalAmount = amount.getBalance(selectedBalanceType, stakingCryptoAmount)
return totalAmount.format { crypto(status.currency) }
}

View file

@ -13,6 +13,8 @@ import com.tangem.domain.staking.model.StakingAvailability
import com.tangem.domain.staking.model.StakingEntryInfo
import com.tangem.domain.staking.model.stakekit.RewardBlockType
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.staking.utils.getRewardStakingBalance
import com.tangem.domain.staking.utils.getTotalStakingBalance
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.feature.tokendetails.presentation.tokendetails.model.TokenDetailsClickIntents
import com.tangem.feature.tokendetails.presentation.tokendetails.state.IconState
@ -55,7 +57,7 @@ internal class TokenDetailsStakingInfoConverter(
private fun getStakingInfoBlock(status: CryptoCurrencyStatus, state: TokenDetailsState): StakingBlockUM? {
val yieldBalance = status.value.yieldBalance as? YieldBalance.Data
val stakingCryptoAmount = yieldBalance?.getTotalStakingBalance()
val stakingCryptoAmount = yieldBalance?.getTotalStakingBalance(status.currency.network.id.value)
val pendingBalances = yieldBalance?.balance?.items ?: emptyList()
val iconState = state.tokenInfoBlockState.iconState

View file

@ -3,12 +3,8 @@ package com.tangem.feature.tokendetails.presentation.tokendetails.state.utils
import com.tangem.feature.tokendetails.presentation.tokendetails.state.BalanceType
import java.math.BigDecimal
internal fun BigDecimal.getBalance(
selectedBalanceType: BalanceType,
stakingAmount: BigDecimal?,
includeStaking: Boolean,
): BigDecimal {
return if (selectedBalanceType == BalanceType.ALL && stakingAmount != null && includeStaking) {
internal fun BigDecimal.getBalance(selectedBalanceType: BalanceType, stakingAmount: BigDecimal?): BigDecimal {
return if (selectedBalanceType == BalanceType.ALL && stakingAmount != null) {
this.plus(stakingAmount)
} else {
this

View file

@ -84,6 +84,7 @@ dependencies {
implementation(projects.domain.analytics)
implementation(projects.domain.visa)
implementation(projects.domain.staking.models)
implementation(projects.domain.staking)
implementation(projects.domain.markets.models)
implementation(projects.domain.feedback)
implementation(projects.domain.onramp.models)

View file

@ -8,11 +8,11 @@ import com.tangem.core.ui.format.bigdecimal.fiat
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.staking.model.stakekit.YieldBalance
import com.tangem.domain.staking.utils.getTotalWithRewardsStakingBalance
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.feature.wallet.presentation.organizetokens.model.DraggableItem
import com.tangem.feature.wallet.presentation.organizetokens.utils.common.getGroupHeaderId
import com.tangem.feature.wallet.presentation.organizetokens.utils.common.getTokenItemId
import com.tangem.lib.crypto.BlockchainUtils
import com.tangem.utils.Provider
import com.tangem.utils.converter.Converter
import com.tangem.utils.extensions.orZero
@ -65,11 +65,8 @@ internal class CryptoCurrencyToDraggableItemConverter(
private fun getFormattedFiatAmount(currency: CryptoCurrencyStatus, appCurrency: AppCurrency): String {
val yieldBalance = currency.value.yieldBalance as? YieldBalance.Data
val fiatRate = currency.value.fiatRate ?: BigDecimal.ZERO
val fiatYieldBalance = if (BlockchainUtils.isIncludeStakingTotalBalance(currency.currency.network.id.value)) {
yieldBalance?.getTotalWithRewardsStakingBalance()?.multiply(fiatRate).orZero()
} else {
BigDecimal.ZERO
}
val fiatYieldBalance = yieldBalance?.getTotalWithRewardsStakingBalance(currency.currency.network.id.value)
?.multiply(fiatRate).orZero()
val fiatAmount = currency.value.fiatAmount ?: return BigDecimalFormatConstants.EMPTY_BALANCE_SIGN
return (fiatAmount + fiatYieldBalance).format { fiat(appCurrency.code, appCurrency.symbol) }