Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-02 18:09:43 +05:00
parent 6227d835b0
commit 7b085b4bfc
7 changed files with 40 additions and 24 deletions

View file

@ -583,7 +583,7 @@ internal class DefaultStakingRepository(
// Blockchain.Avalanche.toCoinId() to AVALANCHE_INTEGRATION_ID,
// Blockchain.Tron.toCoinId() to TRON_INTEGRATION_ID,
// Blockchain.Cronos.toCoinId() to CRONOS_INTEGRATION_ID,
// Blockchain.Binance.toCoinId() to BINANCE_INTEGRATION_ID,
// Blockchain.BSC.toCoinId() to BINANCE_INTEGRATION_ID,
// Blockchain.Kava.toCoinId() to KAVA_INTEGRATION_ID,
// Blockchain.Near.toCoinId() to NEAR_INTEGRATION_ID,
// Blockchain.Tezos.toCoinId() to TEZOS_INTEGRATION_ID,

View file

@ -2,6 +2,7 @@ package com.tangem.features.staking.impl.presentation.state.stub
import com.tangem.domain.staking.model.stakekit.PendingAction
import com.tangem.domain.staking.model.stakekit.Yield
import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType
import com.tangem.features.staking.impl.presentation.state.BalanceState
import com.tangem.features.staking.impl.presentation.state.transformers.InfoType
import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents
@ -11,7 +12,7 @@ object StakingClickIntentsStub : StakingClickIntents {
override fun onBackClick() {}
override fun onNextClick(pendingActions: ImmutableList<PendingAction>) {}
override fun onNextClick(actionType: StakingActionCommonType?, pendingActions: ImmutableList<PendingAction>) {}
override fun onActionClick(pendingAction: PendingAction?) {}

View file

@ -119,10 +119,7 @@ internal class SetButtonsStateTransformer : Transformer<StakingUiState> {
private fun List<PendingAction>.getSecondaryAction(): PendingAction? = getOrNull(1)
private fun StakingUiState.isButtonsVisible(): Boolean = when (currentStep) {
StakingStep.InitialInfo -> {
val initialState = initialInfoState as? StakingStates.InitialInfoState.Data
initialState?.isStakeMoreAvailable == true || initialState?.yieldBalance is InnerYieldBalanceState.Empty
}
StakingStep.InitialInfo -> isStakeMoreAvailable()
StakingStep.RewardsValidators -> false
else -> true
}
@ -164,7 +161,11 @@ internal class SetButtonsStateTransformer : Transformer<StakingUiState> {
private fun StakingUiState.onPrimaryClick() {
when (currentStep) {
StakingStep.InitialInfo,
StakingStep.InitialInfo -> {
val actionType = StakingActionCommonType.ENTER.takeIf { isStakeMoreAvailable() }
clickIntents.onAmountValueChange("") // reset amount state
clickIntents.onNextClick(actionType)
}
StakingStep.Validators,
StakingStep.Amount,
-> clickIntents.onNextClick()
@ -187,9 +188,9 @@ internal class SetButtonsStateTransformer : Transformer<StakingUiState> {
StakingStep.InitialInfo,
StakingStep.RewardsValidators,
StakingStep.Confirmation,
StakingStep.Validators,
-> false
StakingStep.Amount,
StakingStep.Validators,
-> true
}
@ -223,4 +224,9 @@ internal class SetButtonsStateTransformer : Transformer<StakingUiState> {
StakingActionType.UNKNOWN -> TextReference.EMPTY
null -> TextReference.EMPTY
}
private fun StakingUiState.isStakeMoreAvailable(): Boolean {
val initialState = initialInfoState as? StakingStates.InitialInfoState.Data
return initialState?.isStakeMoreAvailable == true || initialState?.yieldBalance is InnerYieldBalanceState.Empty
}
}

View file

@ -40,9 +40,8 @@ internal fun StakingConfirmationContent(
Column(
modifier = Modifier
.fillMaxSize()
.background(TangemTheme.colors.background.tertiary)
.padding(TangemTheme.dimens.spacing16)
.padding(horizontal = TangemTheme.dimens.spacing16)
.verticalScroll(rememberScrollState()),
verticalArrangement = Arrangement.spacedBy(TangemTheme.dimens.spacing16),
) {

View file

@ -33,7 +33,10 @@ 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.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.StakingStates
import com.tangem.features.staking.impl.presentation.state.previewdata.InitialStakingStatePreview
import com.tangem.features.staking.impl.presentation.state.stub.StakingClickIntentsStub
import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents
@ -56,8 +59,7 @@ internal fun StakingInitialInfoContent(state: StakingStates.InitialInfoState, cl
LazyColumn(
modifier = Modifier
.background(TangemTheme.colors.background.secondary)
.fillMaxSize(),
contentPadding = PaddingValues(TangemTheme.dimens.spacing16),
.padding(horizontal = TangemTheme.dimens.spacing16),
) {
// TODO staking metrics block is temporary disabled
// https://www.figma.com/design/Vs6SkVsFnUPsSCNwlnVf5U?node-id=12484-35755#876661319
@ -186,7 +188,7 @@ private fun StakingRewardBlock(
InputRowDefault(
title = resourceReference(R.string.staking_rewards),
text = text,
iconRes = R.drawable.ic_chevron_right_24,
iconRes = R.drawable.ic_chevron_right_24.takeIf { isRewardsToClaim },
textColor = textColor,
modifier = Modifier
.clip(TangemTheme.shapes.roundedCornersXMedium)

View file

@ -3,6 +3,7 @@ package com.tangem.features.staking.impl.presentation.viewmodel
import com.tangem.common.ui.amountScreen.AmountScreenClickIntents
import com.tangem.domain.staking.model.stakekit.PendingAction
import com.tangem.domain.staking.model.stakekit.Yield
import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType
import com.tangem.features.staking.impl.presentation.state.BalanceState
import com.tangem.features.staking.impl.presentation.state.transformers.InfoType
import kotlinx.collections.immutable.ImmutableList
@ -12,7 +13,10 @@ internal interface StakingClickIntents : AmountScreenClickIntents {
fun onBackClick()
fun onNextClick(pendingActions: ImmutableList<PendingAction> = persistentListOf())
fun onNextClick(
actionType: StakingActionCommonType? = null,
pendingActions: ImmutableList<PendingAction> = persistentListOf(),
)
fun onActionClick(pendingAction: PendingAction?)
@ -20,7 +24,7 @@ internal interface StakingClickIntents : AmountScreenClickIntents {
fun onInfoClick(infoType: InfoType)
override fun onAmountNext() = onNextClick()
override fun onAmountNext() = onNextClick(actionType = null)
fun openValidators()

View file

@ -102,7 +102,10 @@ internal class StakingViewModel @Inject constructor(
stakingStateRouter.onBackClick()
}
override fun onNextClick(pendingActions: ImmutableList<PendingAction>) {
override fun onNextClick(actionType: StakingActionCommonType?, pendingActions: ImmutableList<PendingAction>) {
if (actionType != null) {
stateController.update { it.copy(actionType = actionType) }
}
stakingStateRouter.onNextClick()
if (isAssentState()) {
estimateGas(pendingActions)
@ -163,6 +166,10 @@ internal class StakingViewModel @Inject constructor(
),
)
val cryptoCurrencyValue = cryptoCurrencyStatus.value
val confirmationState = value.confirmationState as? StakingStates.ConfirmationState.Data
?: error("No confirmation state")
val validatorState = confirmationState.validatorState as? ValidatorState.Content
?: error("No validator provided")
val pendingAction = pendingActions.firstOrNull()
val stakingGasEstimate = estimateGasUseCase(
@ -175,7 +182,7 @@ internal class StakingViewModel @Inject constructor(
?: error("No amount provided"),
address = cryptoCurrencyValue.networkAddress?.defaultAddress?.value
?: error("No available address"),
validatorAddress = yield.validators.getOrNull(0)?.address ?: error("No available validator"),
validatorAddress = validatorState.chosenValidator.address,
token = yield.token,
passthrough = pendingAction?.passthrough,
type = pendingAction?.type,
@ -230,10 +237,7 @@ internal class StakingViewModel @Inject constructor(
stateController.update(ValidatorSelectChangeTransformer(validator))
}
override fun openRewardsValidators() {
stateController.update { it.copy(actionType = StakingActionCommonType.PENDING_REWARDS) }
onNextClick()
}
override fun openRewardsValidators() = onNextClick(actionType = StakingActionCommonType.PENDING_REWARDS)
override fun onActiveStake(activeStake: BalanceState) {
val actionType = if (activeStake.pendingActions.isEmpty()) {
@ -241,9 +245,9 @@ internal class StakingViewModel @Inject constructor(
} else {
StakingActionCommonType.PENDING_OTHER
}
stateController.update { it.copy(actionType = actionType) }
stateController.update(ValidatorSelectChangeTransformer(activeStake.validator))
stateController.update(AmountChangeStateTransformer(cryptoCurrencyStatus, yield, activeStake.cryptoValue))
onNextClick(activeStake.pendingActions)
onNextClick(actionType, activeStake.pendingActions)
}
override fun onExploreClick() {