Updated on 2026-08-14
This commit is contained in:
parent
9de7841edd
commit
88021b8169
13 changed files with 61 additions and 39 deletions
|
|
@ -32,7 +32,8 @@ data class BalanceGroupedState(
|
|||
|
||||
@Immutable
|
||||
data class BalanceState(
|
||||
val validator: Yield.Validator,
|
||||
val validator: Yield.Validator?,
|
||||
val title: TextReference,
|
||||
val cryptoValue: String,
|
||||
val cryptoDecimal: BigDecimal,
|
||||
val cryptoAmount: TextReference,
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ internal class RewardsValidatorStateConverter(
|
|||
|
||||
return BalanceState(
|
||||
validator = this,
|
||||
title = stringReference(this.name),
|
||||
cryptoValue = cryptoValue.parseBigDecimal(cryptoCurrency.decimals),
|
||||
cryptoDecimal = cryptoValue,
|
||||
cryptoAmount = cryptoAmount,
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ internal class YieldBalancesConverter(
|
|||
val isClickable = item.key.isClickable()
|
||||
title?.let {
|
||||
BalanceGroupedState(
|
||||
items = item.value.mapBalances().toPersistentList(),
|
||||
items = item.value.mapBalances(item.key).toPersistentList(),
|
||||
footer = footer,
|
||||
title = it,
|
||||
type = item.key,
|
||||
|
|
@ -76,23 +76,33 @@ internal class YieldBalancesConverter(
|
|||
.filterNot { it.items.isEmpty() }
|
||||
.toPersistentList()
|
||||
|
||||
private fun List<BalanceItem>.mapBalances(): List<BalanceState> {
|
||||
private fun List<BalanceItem>.mapBalances(balanceType: BalanceType): List<BalanceState> {
|
||||
val cryptoCurrencyStatus = cryptoCurrencyStatusProvider()
|
||||
val appCurrency = appCurrencyProvider()
|
||||
val cryptoCurrency = cryptoCurrencyStatus.currency
|
||||
var incrementingIndex = 1
|
||||
return this
|
||||
.filterNot { it.amount.isZero() }
|
||||
.mapNotNull { balance ->
|
||||
val validator = yield.validators.firstOrNull {
|
||||
balance.validatorAddress?.contains(it.address, ignoreCase = true) == true
|
||||
} ?: mockedValidator
|
||||
}
|
||||
|
||||
val cryptoAmount = balance.amount
|
||||
val fiatAmount = cryptoCurrencyStatus.value.fiatRate?.times(cryptoAmount)
|
||||
val unbonding = getUnbondingDate(balance.date)
|
||||
val warmupPeriod = yield.metadata.warmupPeriod.days
|
||||
validator?.let {
|
||||
val title = when {
|
||||
validator != null -> stringReference(validator.name)
|
||||
balanceType == BalanceType.UNSTAKING -> {
|
||||
resourceReference(R.string.staking_unstaking_item_name, wrappedList(incrementingIndex++))
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
title?.let {
|
||||
BalanceState(
|
||||
validator = validator,
|
||||
title = title,
|
||||
cryptoValue = cryptoAmount.parseBigDecimal(cryptoCurrency.decimals),
|
||||
cryptoDecimal = cryptoAmount,
|
||||
cryptoAmount = stringReference(
|
||||
|
|
@ -164,12 +174,5 @@ internal class YieldBalancesConverter(
|
|||
|
||||
private companion object {
|
||||
const val DAY_IN_MILLIS = 24 * 60 * 60 * 1000
|
||||
|
||||
private val mockedValidator = Yield.Validator(
|
||||
address = "",
|
||||
status = "",
|
||||
name = "Mocked validator",
|
||||
preferred = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -71,6 +71,7 @@ internal object InitialStakingStatePreview {
|
|||
isClickable = true,
|
||||
items = persistentListOf(
|
||||
BalanceState(
|
||||
title = stringReference("Binance"),
|
||||
cryptoValue = "100",
|
||||
cryptoAmount = stringReference("100 SOL"),
|
||||
cryptoDecimal = "100".toBigDecimal(),
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@ import com.tangem.features.staking.impl.presentation.state.ValidatorState
|
|||
import com.tangem.utils.transformer.Transformer
|
||||
|
||||
internal class ValidatorSelectChangeTransformer(
|
||||
private val selectedValidator: Yield.Validator,
|
||||
private val selectedValidator: Yield.Validator?,
|
||||
) : Transformer<StakingUiState> {
|
||||
|
||||
override fun transform(prevState: StakingUiState): StakingUiState {
|
||||
val confirmationState = prevState.confirmationState as? StakingStates.ConfirmationState.Data ?: return prevState
|
||||
selectedValidator ?: return prevState
|
||||
val validatorState = (confirmationState.validatorState as? ValidatorState.Content)?.copy(
|
||||
chosenValidator = selectedValidator,
|
||||
) ?: ValidatorState.Content(
|
||||
|
|
|
|||
|
|
@ -33,16 +33,16 @@ internal fun StakingClaimRewardsValidatorContent(
|
|||
.verticalScroll(rememberScrollState()),
|
||||
) {
|
||||
state.rewards.forEachIndexed { index, item ->
|
||||
key(item.validator.address) {
|
||||
key(item.title.resolveReference() + index) {
|
||||
InputRowImageInfo(
|
||||
subtitle = stringReference(item.validator.name),
|
||||
subtitle = item.title,
|
||||
caption = combinedReference(
|
||||
resourceReference(R.string.staking_details_apr),
|
||||
annotatedReference {
|
||||
appendSpace()
|
||||
appendColored(
|
||||
text = BigDecimalFormatter.formatPercent(
|
||||
percent = item.validator.apr.orZero(),
|
||||
percent = item.validator?.apr.orZero(),
|
||||
useAbsoluteValue = true,
|
||||
),
|
||||
color = TangemTheme.colors.text.accent,
|
||||
|
|
@ -51,7 +51,7 @@ internal fun StakingClaimRewardsValidatorContent(
|
|||
),
|
||||
infoTitle = item.fiatAmount,
|
||||
infoSubtitle = item.cryptoAmount,
|
||||
imageUrl = item.validator.image.orEmpty(),
|
||||
imageUrl = item.validator?.image.orEmpty(),
|
||||
modifier = modifier
|
||||
.roundedShapeItemDecoration(index, state.rewards.lastIndex, false)
|
||||
.background(TangemTheme.colors.background.action)
|
||||
|
|
|
|||
|
|
@ -204,15 +204,15 @@ private fun ActiveStakingBlock(groups: ImmutableList<BalanceGroupedState>, onCli
|
|||
end = TangemTheme.dimens.spacing12,
|
||||
),
|
||||
)
|
||||
group.items.forEach { balance ->
|
||||
key(balance.validator.address) {
|
||||
group.items.forEachIndexed { index, balance ->
|
||||
key(balance.title.resolveReference() + index) {
|
||||
InputRowImageInfo(
|
||||
subtitle = stringReference(balance.validator.name),
|
||||
subtitle = balance.title,
|
||||
caption = getCaption(group.type, balance),
|
||||
isGrayscaleImage = !group.isClickable,
|
||||
infoTitle = balance.fiatAmount,
|
||||
infoSubtitle = balance.cryptoAmount,
|
||||
imageUrl = balance.validator.image.orEmpty(),
|
||||
imageUrl = balance.validator?.image,
|
||||
iconEndRes = R.drawable.ic_chevron_right_24.takeIf { group.isClickable },
|
||||
modifier = Modifier.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
|
|
@ -267,7 +267,7 @@ private fun getCaption(balanceType: BalanceType, balance: BalanceState): TextRef
|
|||
appendSpace()
|
||||
appendColored(
|
||||
text = BigDecimalFormatter.formatPercent(
|
||||
percent = balance.validator.apr.orZero(),
|
||||
percent = balance.validator?.apr.orZero(),
|
||||
useAbsoluteValue = true,
|
||||
),
|
||||
color = TangemTheme.colors.text.accent,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue