Updated on 2026-08-14
This commit is contained in:
parent
dcc3bb6c97
commit
d42a9d5b46
5 changed files with 51 additions and 40 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.features.staking.impl.presentation.state
|
||||
|
||||
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.Yield
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
|
|
@ -21,7 +22,8 @@ data class BalanceGroupedState(
|
|||
val items: ImmutableList<BalanceState>,
|
||||
val footer: TextReference?,
|
||||
val title: TextReference,
|
||||
val type: BalanceGroupType,
|
||||
val type: BalanceType,
|
||||
val isClickable: Boolean,
|
||||
)
|
||||
|
||||
data class BalanceState(
|
||||
|
|
@ -33,10 +35,4 @@ data class BalanceState(
|
|||
val rawCurrencyId: String?,
|
||||
val unbondingPeriod: TextReference,
|
||||
val pendingActions: ImmutableList<PendingAction>,
|
||||
)
|
||||
|
||||
enum class BalanceGroupType {
|
||||
ACTIVE,
|
||||
UNSTAKED,
|
||||
UNKNOWN,
|
||||
}
|
||||
)
|
||||
|
|
@ -10,7 +10,6 @@ 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.R
|
||||
import com.tangem.features.staking.impl.presentation.state.BalanceGroupType
|
||||
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
|
||||
|
|
@ -59,12 +58,14 @@ internal class YieldBalancesConverter(
|
|||
.groupBy { it.type.toGroup() }
|
||||
.mapNotNull { item ->
|
||||
val (title, footer) = getGroupTitle(item.key)
|
||||
val isClickable = getClickableType(item.key)
|
||||
title?.let {
|
||||
BalanceGroupedState(
|
||||
items = item.value.mapBalances().toPersistentList(),
|
||||
footer = footer,
|
||||
title = it,
|
||||
type = item.key,
|
||||
isClickable = isClickable,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -111,31 +112,25 @@ internal class YieldBalancesConverter(
|
|||
}
|
||||
|
||||
private fun BalanceType.toGroup() = when (this) {
|
||||
BalanceType.PREPARING,
|
||||
BalanceType.STAKED,
|
||||
BalanceType.AVAILABLE,
|
||||
BalanceType.LOCKED,
|
||||
-> BalanceGroupType.ACTIVE
|
||||
BalanceType.UNSTAKING,
|
||||
BalanceType.UNLOCKING,
|
||||
BalanceType.UNSTAKED,
|
||||
-> BalanceGroupType.UNSTAKED
|
||||
BalanceType.REWARDS,
|
||||
BalanceType.UNKNOWN,
|
||||
-> BalanceGroupType.UNKNOWN
|
||||
-> BalanceType.UNKNOWN
|
||||
else -> this
|
||||
}
|
||||
|
||||
private fun getGroupTitle(type: BalanceGroupType) = when (type) {
|
||||
BalanceGroupType.ACTIVE -> resourceReference(
|
||||
R.string.staking_active,
|
||||
) to resourceReference(
|
||||
R.string.staking_active_footer,
|
||||
)
|
||||
BalanceGroupType.UNSTAKED -> resourceReference(
|
||||
R.string.staking_unstaked,
|
||||
) to resourceReference(
|
||||
R.string.staking_unstaked_footer,
|
||||
)
|
||||
BalanceGroupType.UNKNOWN -> null to null
|
||||
private fun getGroupTitle(type: BalanceType) = when (type) {
|
||||
BalanceType.STAKED -> resourceReference(R.string.staking_active) to
|
||||
resourceReference(R.string.staking_active_footer)
|
||||
BalanceType.UNSTAKED -> resourceReference(R.string.staking_unstaked) to
|
||||
resourceReference(R.string.staking_unstaked_footer)
|
||||
BalanceType.UNSTAKING -> resourceReference(R.string.staking_unstaking) to null
|
||||
else -> null to null
|
||||
}
|
||||
|
||||
private fun getClickableType(type: BalanceType) = when (type) {
|
||||
BalanceType.STAKED,
|
||||
BalanceType.UNSTAKED,
|
||||
-> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package com.tangem.features.staking.impl.presentation.state.previewdata
|
|||
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.Yield
|
||||
import com.tangem.features.staking.impl.R
|
||||
import com.tangem.features.staking.impl.presentation.state.*
|
||||
|
|
@ -68,7 +69,8 @@ internal object InitialStakingStatePreview {
|
|||
BalanceGroupedState(
|
||||
title = stringReference("Staked"),
|
||||
footer = null,
|
||||
type = BalanceGroupType.ACTIVE,
|
||||
type = BalanceType.STAKED,
|
||||
isClickable = true,
|
||||
items = persistentListOf(
|
||||
BalanceState(
|
||||
cryptoValue = "100",
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import com.tangem.core.ui.extensions.*
|
|||
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.features.staking.impl.R
|
||||
import com.tangem.features.staking.impl.presentation.state.*
|
||||
import com.tangem.features.staking.impl.presentation.state.previewdata.InitialStakingStatePreview
|
||||
|
|
@ -210,7 +211,7 @@ private fun ActiveStakingBlock(groups: List<BalanceGroupedState>, onClick: (Bala
|
|||
) {
|
||||
group.items.forEachIndexed { index, balance ->
|
||||
key(balance.validator.address) {
|
||||
val caption = if (group.type == BalanceGroupType.UNSTAKED) {
|
||||
val caption = if (group.type == BalanceType.UNSTAKING) {
|
||||
combinedReference(
|
||||
resourceReference(R.string.staking_details_unbonding_period),
|
||||
annotatedReference {
|
||||
|
|
@ -240,13 +241,14 @@ private fun ActiveStakingBlock(groups: List<BalanceGroupedState>, onClick: (Bala
|
|||
title = group.title.takeIf { index == 0 },
|
||||
subtitle = stringReference(balance.validator.name),
|
||||
caption = caption,
|
||||
isGrayscaleImage = group.type == BalanceGroupType.UNSTAKED,
|
||||
isGrayscaleImage = group.type == BalanceType.UNSTAKING,
|
||||
infoTitle = balance.fiatAmount,
|
||||
infoSubtitle = balance.cryptoAmount,
|
||||
imageUrl = balance.validator.image.orEmpty(),
|
||||
modifier = Modifier.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = rememberRipple(),
|
||||
enabled = group.isClickable,
|
||||
onClick = { onClick(balance) },
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue