Updated on 2026-08-14

This commit is contained in:
Tangem 2024-10-31 15:55:14 +05:00
parent f76dcdd658
commit b2f3753b17
3 changed files with 44 additions and 40 deletions

View file

@ -2,12 +2,13 @@ package com.tangem.features.staking.impl.presentation.state.converters
import com.tangem.common.extensions.isZero
import com.tangem.core.ui.format.bigdecimal.crypto
import com.tangem.core.ui.format.bigdecimal.fiat
import com.tangem.core.ui.format.bigdecimal.format
import com.tangem.core.ui.utils.BigDecimalFormatter
import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.staking.model.stakekit.*
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
import com.tangem.features.staking.impl.presentation.state.InnerYieldBalanceState
import com.tangem.lib.crypto.BlockchainUtils.isBSC
import com.tangem.lib.crypto.BlockchainUtils.isSolana
import com.tangem.utils.Provider
import com.tangem.utils.converter.Converter
@ -44,11 +45,12 @@ internal class YieldBalancesConverter(
val (type, isActionable) = getRewardBlockType()
InnerYieldBalanceState.Data(
rewardsCrypto = cryptoRewardsValue.format { crypto(cryptoCurrency) },
rewardsFiat = BigDecimalFormatter.formatFiatAmount(
fiatAmount = fiatRewardsValue,
fiatCurrencyCode = appCurrency.code,
fiatCurrencySymbol = appCurrency.symbol,
),
rewardsFiat = fiatRewardsValue.format {
fiat(
fiatCurrencyCode = appCurrency.code,
fiatCurrencySymbol = appCurrency.symbol,
)
},
rewardBlockType = type,
isActionable = isActionable,
balance = balanceToShowItems.mapBalances(),
@ -67,6 +69,7 @@ internal class YieldBalancesConverter(
private fun getRewardBlockType(): Pair<RewardBlockType, Boolean> {
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
val networkId = cryptoCurrencyStatus.currency.network.id.value
val yieldBalance = cryptoCurrencyStatus.value.yieldBalance as? YieldBalance.Data
val rewards = yieldBalance?.balance?.items
?.filter { it.type == BalanceType.REWARDS && !it.amount.isZero() }
@ -74,10 +77,8 @@ internal class YieldBalancesConverter(
val isActionable = rewards?.any { it.pendingActions.isNotEmpty() } == true
val isRewardsClaimable = rewards?.isNotEmpty() == true
val isSolana = isSolana(cryptoCurrencyStatus.currency.network.id.value)
return when {
isSolana -> RewardBlockType.RewardUnavailable to false
isSolana(networkId) || isBSC(networkId) -> RewardBlockType.RewardUnavailable to false
isRewardsClaimable -> RewardBlockType.Rewards to isActionable
else -> RewardBlockType.NoRewards to false
}