Updated on 2026-08-14
This commit is contained in:
parent
0cb0b03118
commit
b779403de4
4 changed files with 20 additions and 17 deletions
|
|
@ -15,6 +15,7 @@ internal sealed class InnerYieldBalanceState {
|
|||
val rewardsCrypto: String,
|
||||
val rewardsFiat: String,
|
||||
val rewardBlockType: RewardBlockType,
|
||||
val isActionable: Boolean,
|
||||
val balance: ImmutableList<BalanceState>,
|
||||
) : InnerYieldBalanceState()
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ internal class YieldBalancesConverter(
|
|||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val (type, isActionable) = getRewardBlockType()
|
||||
InnerYieldBalanceState.Data(
|
||||
rewardsCrypto = BigDecimalFormatter.formatCryptoAmount(
|
||||
cryptoAmount = cryptoRewardsValue,
|
||||
|
|
@ -50,7 +50,8 @@ internal class YieldBalancesConverter(
|
|||
fiatCurrencyCode = appCurrency.code,
|
||||
fiatCurrencySymbol = appCurrency.symbol,
|
||||
),
|
||||
rewardBlockType = getRewardBlockType(),
|
||||
rewardBlockType = type,
|
||||
isActionable = isActionable,
|
||||
balance = balanceToShowItems.mapBalances(),
|
||||
)
|
||||
} else {
|
||||
|
|
@ -65,20 +66,21 @@ internal class YieldBalancesConverter(
|
|||
.sortedBy { it.type.order }
|
||||
.toPersistentList()
|
||||
|
||||
private fun getRewardBlockType(): RewardBlockType {
|
||||
private fun getRewardBlockType(): Pair<RewardBlockType, Boolean> {
|
||||
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
|
||||
val yieldBalance = cryptoCurrencyStatus.value.yieldBalance as? YieldBalance.Data
|
||||
val isRewardsClaimable = yieldBalance?.balance?.items
|
||||
val rewards = yieldBalance?.balance?.items
|
||||
?.filter { it.type == BalanceType.REWARDS }
|
||||
?.any { it.pendingActions.isNotEmpty() }
|
||||
?: false
|
||||
|
||||
val isActionable = rewards?.all { it.pendingActions.isNotEmpty() } == true
|
||||
val isRewardsClaimable = rewards?.isNotEmpty() == true
|
||||
|
||||
val isSolana = isSolana(cryptoCurrencyStatus.currency.network.id.value)
|
||||
|
||||
return when {
|
||||
isSolana -> RewardBlockType.RewardUnavailable
|
||||
isRewardsClaimable -> RewardBlockType.Rewards
|
||||
else -> RewardBlockType.NoRewards
|
||||
isSolana -> RewardBlockType.RewardUnavailable to false
|
||||
isRewardsClaimable -> RewardBlockType.Rewards to isActionable
|
||||
else -> RewardBlockType.NoRewards to false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -67,6 +67,7 @@ internal object InitialStakingStatePreview {
|
|||
rewardsFiat = "100 $",
|
||||
rewardsCrypto = "100 SOL",
|
||||
rewardBlockType = RewardBlockType.RewardUnavailable,
|
||||
isActionable = true,
|
||||
balance = persistentListOf(
|
||||
BalanceState(
|
||||
groupId = "groupId",
|
||||
|
|
|
|||
|
|
@ -219,20 +219,18 @@ private fun BannerBlock(onClick: () -> Unit) {
|
|||
|
||||
@Composable
|
||||
private fun StakingRewardBlock(
|
||||
rewardCrypto: String,
|
||||
rewardFiat: String,
|
||||
rewardBlockType: RewardBlockType,
|
||||
yieldBalanceState: InnerYieldBalanceState.Data,
|
||||
onRewardsClick: () -> Unit,
|
||||
isBalanceHidden: Boolean,
|
||||
) {
|
||||
val (text, textColor) = when (rewardBlockType) {
|
||||
val (text, textColor) = when (yieldBalanceState.rewardBlockType) {
|
||||
RewardBlockType.Rewards -> {
|
||||
annotatedReference {
|
||||
append(rewardFiat.orMaskWithStars(isBalanceHidden))
|
||||
append(yieldBalanceState.rewardsFiat.orMaskWithStars(isBalanceHidden))
|
||||
appendSpace()
|
||||
append(DOT)
|
||||
appendSpace()
|
||||
append(rewardCrypto.orMaskWithStars(isBalanceHidden))
|
||||
append(yieldBalanceState.rewardsCrypto.orMaskWithStars(isBalanceHidden))
|
||||
} to TangemTheme.colors.text.primary1
|
||||
}
|
||||
RewardBlockType.RewardUnavailable -> {
|
||||
|
|
@ -243,10 +241,11 @@ private fun StakingRewardBlock(
|
|||
resourceReference(R.string.staking_details_no_rewards_to_claim) to TangemTheme.colors.text.tertiary
|
||||
}
|
||||
}
|
||||
val isShowIcon = yieldBalanceState.rewardBlockType == RewardBlockType.Rewards && yieldBalanceState.isActionable
|
||||
InputRowDefault(
|
||||
title = resourceReference(R.string.staking_rewards),
|
||||
text = text,
|
||||
iconRes = R.drawable.ic_chevron_right_24.takeIf { rewardBlockType == RewardBlockType.Rewards },
|
||||
iconRes = R.drawable.ic_chevron_right_24.takeIf { isShowIcon },
|
||||
textColor = textColor,
|
||||
modifier = Modifier
|
||||
.clip(TangemTheme.shapes.roundedCornersXMedium)
|
||||
|
|
@ -254,7 +253,7 @@ private fun StakingRewardBlock(
|
|||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = ripple(),
|
||||
enabled = rewardBlockType == RewardBlockType.Rewards,
|
||||
enabled = yieldBalanceState.isActionable,
|
||||
onClick = onRewardsClick,
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue