Updated on 2026-08-14
This commit is contained in:
parent
c2ef661a16
commit
72d9b99348
7 changed files with 26 additions and 27 deletions
|
|
@ -46,6 +46,14 @@ data class Yield(
|
|||
val address: AddressArgument,
|
||||
val additionalAddresses: Map<ArgType, AddressArgument>? = null,
|
||||
)
|
||||
|
||||
val isPartialAmountDisabled: Boolean
|
||||
get() {
|
||||
val enterAmount = args[ArgType.AMOUNT] ?: return false
|
||||
val min = enterAmount.minimum ?: return false
|
||||
val max = enterAmount.maximum ?: return false
|
||||
return min.signum() == -1 && max.signum() == -1
|
||||
}
|
||||
}
|
||||
|
||||
enum class ArgType {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ sealed class StakingActionCommonType {
|
|||
data class Enter(val skipEnterAmount: Boolean) : StakingActionCommonType()
|
||||
data class Exit(val partiallyUnstakeDisabled: Boolean) : StakingActionCommonType()
|
||||
sealed class Pending : StakingActionCommonType() {
|
||||
data class Stake(val skipEnterAmount: Boolean) : Pending()
|
||||
data object Restake : Pending()
|
||||
data object Rewards : Pending()
|
||||
data object Other : Pending()
|
||||
|
|
|
|||
|
|
@ -66,7 +66,6 @@ import com.tangem.features.staking.impl.presentation.state.transformers.validato
|
|||
import com.tangem.features.staking.impl.presentation.state.utils.checkAndCalculateSubtractedAmount
|
||||
import com.tangem.features.staking.impl.presentation.state.utils.isSingleAction
|
||||
import com.tangem.features.staking.impl.presentation.state.utils.withStubUnstakeAction
|
||||
import com.tangem.lib.crypto.BlockchainUtils
|
||||
import com.tangem.utils.Provider
|
||||
import com.tangem.utils.coroutines.*
|
||||
import com.tangem.utils.extensions.isSingleItem
|
||||
|
|
@ -250,7 +249,7 @@ internal class StakingModel @Inject constructor(
|
|||
stakingAllowance = stakingAllowance,
|
||||
yieldArgs = yield.args,
|
||||
).let(::add)
|
||||
if (BlockchainUtils.isSkipAmountEnter(uiState.value.cryptoCurrencyBlockchainId)) {
|
||||
if (yield.args.enter.isPartialAmountDisabled) {
|
||||
ValidatorSelectChangeTransformer(
|
||||
selectedValidator = yield.preferredValidators.firstOrNull(),
|
||||
yield = yield,
|
||||
|
|
@ -859,7 +858,7 @@ internal class StakingModel @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun setupIsAnyTokenStaked() {
|
||||
isAnyTokenStaked = isAnyTokenStakedUseCase(userWalletId).getOrNull() ?: false
|
||||
isAnyTokenStaked = isAnyTokenStakedUseCase(userWalletId).getOrNull() == true
|
||||
}
|
||||
|
||||
private fun subscribeOnCurrencyStatusUpdates() {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ internal class StakingStateRouter(
|
|||
StakingActionCommonType.Pending.Other,
|
||||
StakingActionCommonType.Pending.Rewards,
|
||||
-> showConfirmation()
|
||||
StakingActionCommonType.Pending.Restake -> showRestakeValidators()
|
||||
is StakingActionCommonType.Pending.Stake,
|
||||
StakingActionCommonType.Pending.Restake,
|
||||
-> showRestakeValidators()
|
||||
}
|
||||
StakingStep.RestakeValidator,
|
||||
StakingStep.RewardsValidators,
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@ import com.tangem.features.staking.impl.presentation.state.*
|
|||
import com.tangem.features.staking.impl.presentation.state.utils.isCompositePendingActions
|
||||
import com.tangem.features.staking.impl.presentation.state.utils.isTronStakedBalance
|
||||
import com.tangem.lib.crypto.BlockchainUtils
|
||||
import com.tangem.lib.crypto.BlockchainUtils.isSkipAmountEnter
|
||||
import com.tangem.utils.extensions.isPositive
|
||||
import com.tangem.utils.transformer.Transformer
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
|
|
@ -46,12 +44,12 @@ internal class SetConfirmationStateInitTransformer(
|
|||
override fun transform(prevState: StakingUiState): StakingUiState {
|
||||
val actionType = when {
|
||||
isEnter -> StakingActionCommonType.Enter(
|
||||
skipEnterAmount = isSkipAmountEnter(prevState.cryptoCurrencyBlockchainId),
|
||||
skipEnterAmount = yieldArgs.enter.isPartialAmountDisabled,
|
||||
)
|
||||
isImplicitExit || isExplicitExit -> StakingActionCommonType.Exit(isPartiallyUnstakeDisabled(prevState))
|
||||
else -> when (pendingAction?.type) {
|
||||
StakingActionType.STAKE -> StakingActionCommonType.Enter(
|
||||
skipEnterAmount = isSkipAmountEnter(prevState.cryptoCurrencyBlockchainId),
|
||||
StakingActionType.STAKE -> StakingActionCommonType.Pending.Stake(
|
||||
skipEnterAmount = yieldArgs.enter.isPartialAmountDisabled,
|
||||
)
|
||||
StakingActionType.UNSTAKE -> StakingActionCommonType.Exit(
|
||||
partiallyUnstakeDisabled = isPartiallyUnstakeDisabled(prevState),
|
||||
|
|
@ -80,9 +78,8 @@ internal class SetConfirmationStateInitTransformer(
|
|||
transactionDoneState = TransactionDoneState.Empty,
|
||||
isApprovalNeeded = stakingApproval is StakingApproval.Needed,
|
||||
allowance = stakingAllowance,
|
||||
isAmountEditable = actionType is StakingActionCommonType.Enter ||
|
||||
actionType is StakingActionCommonType.Exit &&
|
||||
!actionType.partiallyUnstakeDisabled,
|
||||
isAmountEditable = actionType is StakingActionCommonType.Enter && !actionType.skipEnterAmount ||
|
||||
actionType is StakingActionCommonType.Exit && !actionType.partiallyUnstakeDisabled,
|
||||
reduceAmountBy = null,
|
||||
pendingAction = pendingAction,
|
||||
pendingActions = pendingActions.takeIf { isComposePendingActions },
|
||||
|
|
@ -93,14 +90,11 @@ internal class SetConfirmationStateInitTransformer(
|
|||
private fun isPartiallyUnstakeDisabled(state: StakingUiState): Boolean {
|
||||
val isSolana = BlockchainUtils.isSolana(state.cryptoCurrencyBlockchainId)
|
||||
val isValidatorPreferred = balanceState?.validator?.preferred == true
|
||||
if (isSolana && !isValidatorPreferred) {
|
||||
return true
|
||||
}
|
||||
|
||||
val exitArgs = yieldArgs.exit ?: return false
|
||||
val exitAmount = exitArgs.args[Yield.Args.ArgType.AMOUNT] ?: return false
|
||||
val min = exitAmount.minimum ?: return false
|
||||
val max = exitAmount.maximum ?: return false
|
||||
return !min.isPositive() && !max.isPositive()
|
||||
return if (isSolana && !isValidatorPreferred) {
|
||||
true
|
||||
} else {
|
||||
yieldArgs.exit?.isPartialAmountDisabled == true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,8 @@ internal class ValidatorSelectChangeTransformer(
|
|||
val validatorState = prevState.validatorState as? StakingStates.ValidatorState.Data
|
||||
val confirmationState = prevState.confirmationState as? StakingStates.ConfirmationState.Data
|
||||
|
||||
val isRestake = prevState.actionType == StakingActionCommonType.Pending.Restake
|
||||
val isRestake = prevState.actionType == StakingActionCommonType.Pending.Restake ||
|
||||
prevState.actionType is StakingActionCommonType.Pending.Stake
|
||||
val isEnter = prevState.actionType is StakingActionCommonType.Enter
|
||||
val isFromInfoScreen = prevState.currentStep == StakingStep.InitialInfo
|
||||
val isVoteLocked = confirmationState?.pendingAction?.type == StakingActionType.VOTE_LOCKED
|
||||
|
|
|
|||
|
|
@ -144,12 +144,6 @@ object BlockchainUtils {
|
|||
return blockchain != Blockchain.Cardano
|
||||
}
|
||||
|
||||
fun isSkipAmountEnter(blockchainId: String): Boolean {
|
||||
val blockchain = Blockchain.fromId(blockchainId)
|
||||
|
||||
return blockchain == Blockchain.Cardano
|
||||
}
|
||||
|
||||
private fun getNetworkStandardName(blockchain: Blockchain): String {
|
||||
return when (blockchain) {
|
||||
Blockchain.Ethereum, Blockchain.EthereumTestnet -> "ERC20"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue