Updated on 2026-08-14
This commit is contained in:
parent
eb9e376d40
commit
0c4097a205
7 changed files with 189 additions and 48 deletions
|
|
@ -4,6 +4,7 @@ import androidx.compose.runtime.Immutable
|
|||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.domain.staking.model.stakekit.BalanceType
|
||||
import com.tangem.domain.staking.model.stakekit.PendingAction
|
||||
import com.tangem.domain.staking.model.stakekit.RewardBlockType
|
||||
import com.tangem.domain.staking.model.stakekit.Yield
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import java.math.BigDecimal
|
||||
|
|
@ -12,8 +13,7 @@ sealed class InnerYieldBalanceState {
|
|||
data class Data(
|
||||
val rewardsCrypto: String,
|
||||
val rewardsFiat: String,
|
||||
val isRewardsToClaim: Boolean,
|
||||
val isRewardsClaimable: Boolean,
|
||||
val rewardBlockType: RewardBlockType,
|
||||
val balance: ImmutableList<BalanceGroupedState>,
|
||||
) : InnerYieldBalanceState()
|
||||
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ import com.tangem.features.staking.impl.R
|
|||
import com.tangem.features.staking.impl.presentation.state.BalanceGroupedState
|
||||
import com.tangem.features.staking.impl.presentation.state.BalanceState
|
||||
import com.tangem.features.staking.impl.presentation.state.InnerYieldBalanceState
|
||||
import com.tangem.lib.crypto.BlockchainUtils.isSolana
|
||||
import com.tangem.utils.Provider
|
||||
import com.tangem.utils.converter.Converter
|
||||
import com.tangem.utils.isNullOrZero
|
||||
import kotlinx.collections.immutable.toPersistentList
|
||||
import org.joda.time.DateTime
|
||||
import java.util.Calendar
|
||||
|
|
@ -35,9 +35,7 @@ internal class YieldBalancesConverter(
|
|||
val cryptoRewardsValue = yieldBalance.getRewardStakingBalance()
|
||||
val fiatRewardsValue = cryptoCurrencyStatus.value.fiatRate?.times(cryptoRewardsValue)
|
||||
val groupedBalances = getGroupedBalance(yieldBalance.balance)
|
||||
val isRewardsClaimable = yieldBalance.balance.items
|
||||
.filter { it.type == BalanceType.REWARDS }
|
||||
.any { it.pendingActions.isNotEmpty() }
|
||||
|
||||
InnerYieldBalanceState.Data(
|
||||
rewardsCrypto = BigDecimalFormatter.formatCryptoAmount(
|
||||
cryptoAmount = cryptoRewardsValue,
|
||||
|
|
@ -48,8 +46,7 @@ internal class YieldBalancesConverter(
|
|||
fiatCurrencyCode = appCurrency.code,
|
||||
fiatCurrencySymbol = appCurrency.symbol,
|
||||
),
|
||||
isRewardsToClaim = !cryptoRewardsValue.isNullOrZero(),
|
||||
isRewardsClaimable = isRewardsClaimable,
|
||||
rewardBlockType = getRewardBlockType(),
|
||||
balance = groupedBalances,
|
||||
)
|
||||
} else {
|
||||
|
|
@ -165,6 +162,23 @@ internal class YieldBalancesConverter(
|
|||
}
|
||||
}
|
||||
|
||||
private fun getRewardBlockType(): RewardBlockType {
|
||||
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
|
||||
val yieldBalance = cryptoCurrencyStatus.value.yieldBalance as? YieldBalance.Data
|
||||
val isRewardsClaimable = yieldBalance?.balance?.items
|
||||
?.filter { it.type == BalanceType.REWARDS }
|
||||
?.any { it.pendingActions.isNotEmpty() }
|
||||
?: false
|
||||
|
||||
val isSolana = isSolana(cryptoCurrencyStatus.currency.network.id.value)
|
||||
|
||||
return when {
|
||||
isSolana -> RewardBlockType.RewardUnavailable
|
||||
isRewardsClaimable -> RewardBlockType.Rewards
|
||||
else -> RewardBlockType.NoRewards
|
||||
}
|
||||
}
|
||||
|
||||
private fun Calendar.resetHours() {
|
||||
this[Calendar.HOUR_OF_DAY] = 0
|
||||
this[Calendar.MINUTE] = 0
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ import com.tangem.core.ui.components.list.RoundedListWithDividersItemData
|
|||
import com.tangem.core.ui.extensions.TextReference
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
import com.tangem.domain.staking.model.stakekit.BalanceType
|
||||
import com.tangem.domain.staking.model.stakekit.RewardBlockType
|
||||
import com.tangem.domain.staking.model.stakekit.Yield
|
||||
import com.tangem.features.staking.impl.R
|
||||
import com.tangem.features.staking.impl.presentation.state.BalanceGroupedState
|
||||
import com.tangem.features.staking.impl.presentation.state.BalanceState
|
||||
import com.tangem.features.staking.impl.presentation.state.InnerYieldBalanceState
|
||||
import com.tangem.features.staking.impl.presentation.state.*
|
||||
import com.tangem.features.staking.impl.presentation.state.StakingStates
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
||||
|
|
@ -61,8 +60,7 @@ internal object InitialStakingStatePreview {
|
|||
yieldBalance = InnerYieldBalanceState.Data(
|
||||
rewardsFiat = "100 $",
|
||||
rewardsCrypto = "100 SOL",
|
||||
isRewardsToClaim = false,
|
||||
isRewardsClaimable = false,
|
||||
rewardBlockType = RewardBlockType.RewardUnavailable,
|
||||
balance = persistentListOf(
|
||||
BalanceGroupedState(
|
||||
title = stringReference("Staked"),
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import com.tangem.core.ui.res.TangemTheme
|
|||
import com.tangem.core.ui.res.TangemThemePreview
|
||||
import com.tangem.core.ui.utils.BigDecimalFormatter
|
||||
import com.tangem.domain.staking.model.stakekit.BalanceType
|
||||
import com.tangem.domain.staking.model.stakekit.RewardBlockType
|
||||
import com.tangem.features.staking.impl.R
|
||||
import com.tangem.features.staking.impl.presentation.state.BalanceGroupedState
|
||||
import com.tangem.features.staking.impl.presentation.state.BalanceState
|
||||
|
|
@ -88,8 +89,7 @@ internal fun StakingInitialInfoContent(state: StakingStates.InitialInfoState, cl
|
|||
StakingRewardBlock(
|
||||
rewardCrypto = state.yieldBalance.rewardsCrypto,
|
||||
rewardFiat = state.yieldBalance.rewardsFiat,
|
||||
isRewardsToClaim = state.yieldBalance.isRewardsToClaim,
|
||||
isRewardsClaimable = state.yieldBalance.isRewardsClaimable,
|
||||
rewardBlockType = state.yieldBalance.rewardBlockType,
|
||||
onRewardsClick = clickIntents::openRewardsValidators,
|
||||
)
|
||||
SpacerH12()
|
||||
|
|
@ -143,27 +143,33 @@ private fun BannerBlock(onClick: () -> Unit) {
|
|||
private fun StakingRewardBlock(
|
||||
rewardCrypto: String,
|
||||
rewardFiat: String,
|
||||
isRewardsToClaim: Boolean,
|
||||
isRewardsClaimable: Boolean,
|
||||
rewardBlockType: RewardBlockType,
|
||||
onRewardsClick: () -> Unit,
|
||||
) {
|
||||
val (text, textColor) = if (isRewardsToClaim) {
|
||||
annotatedReference {
|
||||
append(PLUS)
|
||||
appendSpace()
|
||||
append(rewardFiat)
|
||||
appendSpace()
|
||||
append(DOT)
|
||||
appendSpace()
|
||||
append(rewardCrypto)
|
||||
} to TangemTheme.colors.text.primary1
|
||||
} else {
|
||||
resourceReference(R.string.staking_details_no_rewards_to_claim) to TangemTheme.colors.text.tertiary
|
||||
val (text, textColor) = when (rewardBlockType) {
|
||||
RewardBlockType.Rewards -> {
|
||||
annotatedReference {
|
||||
append(PLUS)
|
||||
appendSpace()
|
||||
append(rewardFiat)
|
||||
appendSpace()
|
||||
append(DOT)
|
||||
appendSpace()
|
||||
append(rewardCrypto)
|
||||
} to TangemTheme.colors.text.primary1
|
||||
}
|
||||
RewardBlockType.RewardUnavailable -> {
|
||||
resourceReference(R.string.staking_details_auto_claiming_rewards_daily_text) to
|
||||
TangemTheme.colors.text.tertiary
|
||||
}
|
||||
RewardBlockType.NoRewards -> {
|
||||
resourceReference(R.string.staking_details_no_rewards_to_claim) to TangemTheme.colors.text.tertiary
|
||||
}
|
||||
}
|
||||
InputRowDefault(
|
||||
title = resourceReference(R.string.staking_rewards),
|
||||
text = text,
|
||||
iconRes = R.drawable.ic_chevron_right_24.takeIf { isRewardsToClaim && isRewardsClaimable },
|
||||
iconRes = R.drawable.ic_chevron_right_24.takeIf { rewardBlockType == RewardBlockType.Rewards },
|
||||
textColor = textColor,
|
||||
modifier = Modifier
|
||||
.clip(TangemTheme.shapes.roundedCornersXMedium)
|
||||
|
|
@ -171,7 +177,7 @@ private fun StakingRewardBlock(
|
|||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = rememberRipple(),
|
||||
enabled = isRewardsToClaim && isRewardsClaimable,
|
||||
enabled = rewardBlockType == RewardBlockType.Rewards,
|
||||
onClick = onRewardsClick,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue