Updated on 2026-08-14

This commit is contained in:
Tangem 2024-08-29 13:09:30 +05:00
parent 4f3d1f10c7
commit 0cea2545a7
28 changed files with 310 additions and 290 deletions

View file

@ -83,11 +83,10 @@ internal sealed class StakingStates {
val innerState: InnerConfirmationStakingState,
val feeState: FeeState,
val validatorState: ValidatorState,
val pendingActions: ImmutableList<PendingAction>,
val pendingAction: PendingAction?,
val notifications: ImmutableList<StakingNotification>,
val footerText: String,
val transactionDoneState: TransactionDoneState,
val pendingActionInProgress: PendingAction? = null,
val isApprovalNeeded: Boolean,
) : ConfirmationState()

View file

@ -0,0 +1,11 @@
package com.tangem.features.staking.impl.presentation.state.bottomsheet
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent
import com.tangem.core.ui.extensions.TextReference
import com.tangem.domain.staking.model.stakekit.PendingAction
internal data class StakingActionSelectionBottomSheetConfig(
val title: TextReference,
val actions: List<PendingAction>,
val onActionSelect: (PendingAction) -> Unit,
) : TangemBottomSheetConfigContent

View file

@ -9,9 +9,6 @@ import com.tangem.domain.appcurrency.model.AppCurrency
import com.tangem.domain.staking.model.stakekit.Yield
import com.tangem.features.staking.impl.R
import com.tangem.features.staking.impl.presentation.state.*
import com.tangem.features.staking.impl.presentation.state.StakingNotification
import com.tangem.features.staking.impl.presentation.state.StakingStates
import com.tangem.features.staking.impl.presentation.state.ValidatorState
import kotlinx.collections.immutable.persistentListOf
import java.math.BigDecimal
@ -90,7 +87,7 @@ internal object ConfirmationStatePreviewData {
),
),
transactionDoneState = TransactionDoneState.Empty,
pendingActions = persistentListOf(),
pendingAction = null,
isApprovalNeeded = false,
)
}

View file

@ -6,16 +6,15 @@ 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.bottomsheet.InfoType
import com.tangem.features.staking.impl.presentation.viewmodel.StakingClickIntents
import kotlinx.collections.immutable.ImmutableList
@Suppress("TooManyFunctions")
internal object StakingClickIntentsStub : StakingClickIntents {
override fun onBackClick() {}
override fun onNextClick(actionType: StakingActionCommonType?, pendingActions: ImmutableList<PendingAction>) {}
override fun onNextClick(actionType: StakingActionCommonType?, pendingAction: PendingAction?) {}
override fun onActionClick(pendingAction: PendingAction?) {}
override fun onActionClick() {}
override fun onPrevClick() {}

View file

@ -5,10 +5,9 @@ import com.tangem.common.ui.navigationButtons.NavigationButtonsState
import com.tangem.core.ui.R
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.domain.staking.model.stakekit.PendingAction
import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType
import com.tangem.domain.staking.model.stakekit.action.StakingActionType
import com.tangem.features.staking.impl.presentation.state.*
import com.tangem.features.staking.impl.presentation.state.utils.getPendingActionTitle
import com.tangem.utils.transformer.Transformer
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
@ -22,7 +21,6 @@ internal class SetButtonsStateTransformer : Transformer<StakingUiState> {
NavigationButtonsState.Data(
primaryButton = getPrimaryButton(prevState),
prevButton = getPrevButton(prevState),
secondaryButton = getSecondaryButton(prevState),
extraButtons = getExtraButtons(prevState),
txUrl = (confirmState?.transactionDoneState as? TransactionDoneState.Content)?.txUrl,
)
@ -37,48 +35,22 @@ internal class SetButtonsStateTransformer : Transformer<StakingUiState> {
val confirmState = prevState.confirmationState as? StakingStates.ConfirmationState.Data
val innerConfirmState = confirmState?.innerState
val isPrimaryInProgress =
confirmState?.pendingActions?.getPrimaryAction() == confirmState?.pendingActionInProgress
val isConfirmation = prevState.currentStep == StakingStep.Confirmation
val isInProgress = innerConfirmState == InnerConfirmationStakingState.IN_PROGRESS
val isCompleted = innerConfirmState == InnerConfirmationStakingState.COMPLETED
val isIconVisible = isConfirmation && !isCompleted
val isShowProgress = isInProgress && isPrimaryInProgress
return NavigationButton(
textReference = prevState.getButtonText(),
iconRes = R.drawable.ic_tangem_24,
isSecondary = false,
isIconVisible = isIconVisible,
showProgress = isShowProgress,
showProgress = isInProgress,
isEnabled = prevState.isButtonEnabled(),
onClick = { prevState.onPrimaryClick() },
)
}
private fun getSecondaryButton(prevState: StakingUiState): NavigationButton? {
val confirmState = prevState.confirmationState as? StakingStates.ConfirmationState.Data
val innerConfirmState = confirmState?.innerState
val isConfirmation = prevState.currentStep == StakingStep.Confirmation
val isInProgress = innerConfirmState == InnerConfirmationStakingState.IN_PROGRESS
val isCompleted = innerConfirmState == InnerConfirmationStakingState.COMPLETED
return confirmState?.pendingActions?.getSecondaryAction()?.let { pendingAction ->
val isSecondaryInProgress = pendingAction == confirmState.pendingActionInProgress
val isShowProgress = isInProgress && isSecondaryInProgress
NavigationButton(
textReference = getPendingActionTitle(pendingAction.type),
iconRes = R.drawable.ic_tangem_24,
isSecondary = true,
isIconVisible = true,
showProgress = isShowProgress,
isEnabled = prevState.isButtonEnabled(),
onClick = { prevState.clickIntents.onActionClick(pendingAction) },
).takeIf { isConfirmation && !isCompleted }
}
}
private fun getPrevButton(prevState: StakingUiState): NavigationButton? {
return NavigationButton(
textReference = TextReference.EMPTY,
@ -114,10 +86,6 @@ internal class SetButtonsStateTransformer : Transformer<StakingUiState> {
)
}
private fun List<PendingAction>.getPrimaryAction(): PendingAction? = getOrNull(0)
private fun List<PendingAction>.getSecondaryAction(): PendingAction? = getOrNull(1)
private fun StakingUiState.isButtonsVisible(): Boolean = when (currentStep) {
StakingStep.RewardsValidators -> false
else -> true
@ -158,7 +126,7 @@ internal class SetButtonsStateTransformer : Transformer<StakingUiState> {
StakingActionCommonType.EXIT -> resourceReference(R.string.common_unstake)
StakingActionCommonType.PENDING_OTHER,
StakingActionCommonType.PENDING_REWARDS,
-> getPendingActionTitle(confirmationState.pendingActions.firstOrNull()?.type)
-> confirmationState.pendingAction?.type.getPendingActionTitle()
}
}
} else {
@ -192,7 +160,7 @@ internal class SetButtonsStateTransformer : Transformer<StakingUiState> {
if (isEnterAction && isApproveNeeded) {
clickIntents.showApprovalBottomSheet()
} else {
clickIntents.onActionClick(confirmationState.pendingActions.firstOrNull())
clickIntents.onActionClick()
}
}
} else {
@ -219,25 +187,4 @@ internal class SetButtonsStateTransformer : Transformer<StakingUiState> {
StakingStep.Validators -> true
}
}
@Suppress("CyclomaticComplexMethod")
private fun getPendingActionTitle(type: StakingActionType?): TextReference = when (type) {
StakingActionType.CLAIM_REWARDS -> resourceReference(R.string.common_claim_rewards)
StakingActionType.RESTAKE_REWARDS -> resourceReference(R.string.staking_restake_rewards)
StakingActionType.WITHDRAW -> resourceReference(R.string.staking_withdraw)
StakingActionType.RESTAKE -> resourceReference(R.string.staking_restake)
StakingActionType.CLAIM_UNSTAKED -> resourceReference(R.string.staking_claim_unstaked)
StakingActionType.UNLOCK_LOCKED -> resourceReference(R.string.staking_unlocked_locked)
StakingActionType.STAKE_LOCKED -> resourceReference(R.string.staking_stake_locked)
StakingActionType.VOTE -> resourceReference(R.string.staking_vote)
StakingActionType.REVOKE -> resourceReference(R.string.staking_revoke)
StakingActionType.VOTE_LOCKED -> resourceReference(R.string.staking_vote_locked)
StakingActionType.REVOTE -> resourceReference(R.string.staking_revote)
StakingActionType.REBOND -> resourceReference(R.string.staking_rebond)
StakingActionType.MIGRATE -> resourceReference(R.string.staking_migrate)
StakingActionType.STAKE -> resourceReference(R.string.common_stake)
StakingActionType.UNSTAKE -> resourceReference(R.string.common_unstake)
StakingActionType.UNKNOWN -> TextReference.EMPTY
null -> TextReference.EMPTY
}
}

View file

@ -10,13 +10,12 @@ import com.tangem.features.staking.impl.presentation.state.StakingStates
import com.tangem.features.staking.impl.presentation.state.StakingUiState
import com.tangem.utils.Provider
import com.tangem.utils.transformer.Transformer
import kotlinx.collections.immutable.ImmutableList
internal class SetConfirmationStateAssentTransformer(
private val appCurrencyProvider: Provider<AppCurrency>,
private val feeCryptoCurrencyStatus: CryptoCurrencyStatus?,
private val fee: Fee,
private val pendingActionList: ImmutableList<PendingAction>,
private val action: PendingAction?,
) : Transformer<StakingUiState> {
override fun transform(prevState: StakingUiState): StakingUiState {
@ -38,7 +37,7 @@ internal class SetConfirmationStateAssentTransformer(
isFeeApproximate = false,
),
validatorState = validatorState.copySealed(isClickable = true),
pendingActions = pendingActionList,
pendingAction = action,
isPrimaryButtonEnabled = true,
isApprovalNeeded = false,
)

View file

@ -1,14 +1,11 @@
package com.tangem.features.staking.impl.presentation.state.transformers
import com.tangem.domain.staking.model.stakekit.PendingAction
import com.tangem.features.staking.impl.presentation.state.InnerConfirmationStakingState
import com.tangem.features.staking.impl.presentation.state.StakingStates
import com.tangem.features.staking.impl.presentation.state.StakingUiState
import com.tangem.utils.transformer.Transformer
internal class SetConfirmationStateInProgressTransformer(
private val pendingAction: PendingAction?,
) : Transformer<StakingUiState> {
internal class SetConfirmationStateInProgressTransformer : Transformer<StakingUiState> {
override fun transform(prevState: StakingUiState): StakingUiState {
return prevState.copy(
@ -22,7 +19,6 @@ internal class SetConfirmationStateInProgressTransformer(
isPrimaryButtonEnabled = false,
innerState = InnerConfirmationStakingState.IN_PROGRESS,
validatorState = validatorState.copySealed(isClickable = false),
pendingActionInProgress = pendingAction,
)
} else {
this

View file

@ -32,8 +32,7 @@ internal class SetConfirmationStateLoadingTransformer(
notifications = getNotifications(prevState),
footerText = "",
transactionDoneState = TransactionDoneState.Empty,
pendingActions = persistentListOf(),
pendingActionInProgress = null,
pendingAction = null,
isApprovalNeeded = false,
),
)

View file

@ -212,8 +212,7 @@ internal class SetInitialDataStateTransformer(
notifications = persistentListOf(),
footerText = "",
transactionDoneState = TransactionDoneState.Empty,
pendingActions = persistentListOf(),
pendingActionInProgress = null,
pendingAction = null,
isApprovalNeeded = isApprovalNeeded,
)
}

View file

@ -0,0 +1,30 @@
package com.tangem.features.staking.impl.presentation.state.transformers
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.domain.staking.model.stakekit.PendingAction
import com.tangem.features.staking.impl.R
import com.tangem.features.staking.impl.presentation.state.StakingUiState
import com.tangem.features.staking.impl.presentation.state.bottomsheet.StakingActionSelectionBottomSheetConfig
import com.tangem.utils.transformer.Transformer
import kotlinx.collections.immutable.ImmutableList
internal class ShowActionSelectorBottomSheetTransformer(
private val pendingActions: ImmutableList<PendingAction>,
private val onActionSelect: (PendingAction) -> Unit,
private val onDismiss: () -> Unit,
) : Transformer<StakingUiState> {
override fun transform(prevState: StakingUiState): StakingUiState {
return prevState.copy(
bottomSheetConfig = TangemBottomSheetConfig(
isShow = true,
content = StakingActionSelectionBottomSheetConfig(
title = resourceReference(R.string.common_choose_action),
actions = pendingActions,
onActionSelect = onActionSelect,
),
onDismissRequest = onDismiss,
),
)
}
}

View file

@ -0,0 +1,27 @@
package com.tangem.features.staking.impl.presentation.state.utils
import com.tangem.core.ui.R
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.domain.staking.model.stakekit.action.StakingActionType
@Suppress("CyclomaticComplexMethod")
internal fun StakingActionType?.getPendingActionTitle(): TextReference = when (this) {
StakingActionType.CLAIM_REWARDS -> resourceReference(R.string.common_claim_rewards)
StakingActionType.RESTAKE_REWARDS -> resourceReference(R.string.staking_restake_rewards)
StakingActionType.WITHDRAW -> resourceReference(R.string.staking_withdraw)
StakingActionType.RESTAKE -> resourceReference(R.string.staking_restake)
StakingActionType.CLAIM_UNSTAKED -> resourceReference(R.string.staking_claim_unstaked)
StakingActionType.UNLOCK_LOCKED -> resourceReference(R.string.staking_unlocked_locked)
StakingActionType.STAKE_LOCKED -> resourceReference(R.string.staking_stake_locked)
StakingActionType.VOTE -> resourceReference(R.string.staking_vote)
StakingActionType.REVOKE -> resourceReference(R.string.staking_revoke)
StakingActionType.VOTE_LOCKED -> resourceReference(R.string.staking_vote_locked)
StakingActionType.REVOTE -> resourceReference(R.string.staking_revote)
StakingActionType.REBOND -> resourceReference(R.string.staking_rebond)
StakingActionType.MIGRATE -> resourceReference(R.string.staking_migrate)
StakingActionType.STAKE -> resourceReference(R.string.common_stake)
StakingActionType.UNSTAKE -> resourceReference(R.string.common_unstake)
StakingActionType.UNKNOWN -> TextReference.EMPTY
null -> TextReference.EMPTY
}

View file

@ -24,7 +24,9 @@ import com.tangem.features.staking.impl.R
import com.tangem.features.staking.impl.presentation.state.StakingStates
import com.tangem.features.staking.impl.presentation.state.StakingStep
import com.tangem.features.staking.impl.presentation.state.StakingUiState
import com.tangem.features.staking.impl.presentation.state.bottomsheet.StakingActionSelectionBottomSheetConfig
import com.tangem.features.staking.impl.presentation.state.bottomsheet.StakingInfoBottomSheetConfig
import com.tangem.features.staking.impl.presentation.ui.bottomsheet.StakingActionSelectorBottomSheet
import com.tangem.features.staking.impl.presentation.ui.bottomsheet.StakingInfoBottomSheet
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.first
@ -74,6 +76,7 @@ fun StakingBottomSheet(bottomSheetConfig: TangemBottomSheetConfig?) {
when (bottomSheetConfig.content) {
is StakingInfoBottomSheetConfig -> StakingInfoBottomSheet(bottomSheetConfig)
is GiveTxPermissionBottomSheetConfig -> GiveTxPermissionBottomSheet(bottomSheetConfig)
is StakingActionSelectionBottomSheetConfig -> StakingActionSelectorBottomSheet(bottomSheetConfig)
}
}

View file

@ -58,7 +58,7 @@ internal fun StakingValidatorListContent(
InputRowImageSelector(
subtitle = stringReference(item.name),
caption = combinedReference(
resourceReference(R.string.staking_details_apr),
resourceReference(R.string.staking_details_annual_percentage_rate),
annotatedReference {
appendSpace()
appendColored(

View file

@ -0,0 +1,92 @@
package com.tangem.features.staking.impl.presentation.ui.bottomsheet
import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.tooling.preview.Preview
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheet
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfig
import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetTitle
import com.tangem.core.ui.components.inputrow.InputRowDefault
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.res.TangemTheme
import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.domain.staking.model.stakekit.PendingAction
import com.tangem.domain.staking.model.stakekit.action.StakingActionType
import com.tangem.features.staking.impl.R
import com.tangem.features.staking.impl.presentation.state.bottomsheet.StakingActionSelectionBottomSheetConfig
import com.tangem.features.staking.impl.presentation.state.utils.getPendingActionTitle
import kotlinx.collections.immutable.persistentListOf
@Composable
internal fun StakingActionSelectorBottomSheet(config: TangemBottomSheetConfig) {
TangemBottomSheet<StakingActionSelectionBottomSheetConfig>(
config = config,
title = { content ->
TangemBottomSheetTitle(title = content.title)
},
containerColor = TangemTheme.colors.background.tertiary,
) { content ->
Column(
modifier = Modifier
.padding(
start = TangemTheme.dimens.spacing16,
end = TangemTheme.dimens.spacing16,
bottom = TangemTheme.dimens.spacing32,
)
.clip(TangemTheme.shapes.roundedCornersXMedium)
.background(TangemTheme.colors.background.action),
) {
content.actions.forEachIndexed { index, action ->
InputRowDefault(
text = action.type.getPendingActionTitle(),
textColor = TangemTheme.colors.text.primary1,
showDivider = index != content.actions.lastIndex,
modifier = Modifier
.fillMaxWidth()
.clickable {
content.onActionSelect(action)
},
)
}
}
}
}
// region Preview
@Composable
@Preview(showBackground = true)
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
private fun Preview_StakingActionSelectorBottomSheet() {
TangemThemePreview {
StakingActionSelectorBottomSheet(
config = TangemBottomSheetConfig(
isShow = true,
onDismissRequest = {},
content = StakingActionSelectionBottomSheetConfig(
title = resourceReference(R.string.common_select_action),
actions = persistentListOf(
PendingAction(
type = StakingActionType.CLAIM_REWARDS,
passthrough = "",
args = null,
),
PendingAction(
type = StakingActionType.RESTAKE_REWARDS,
passthrough = "",
args = null,
),
),
onActionSelect = {},
),
),
)
}
}
// endregion Preview

View file

@ -6,19 +6,14 @@ 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.bottomsheet.InfoType
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
internal interface StakingClickIntents : AmountScreenClickIntents {
fun onBackClick()
fun onNextClick(
actionType: StakingActionCommonType? = null,
pendingActions: ImmutableList<PendingAction> = persistentListOf(),
)
fun onNextClick(actionType: StakingActionCommonType? = null, pendingAction: PendingAction? = null)
fun onActionClick(pendingAction: PendingAction?)
fun onActionClick()
fun onPrevClick()

View file

@ -63,7 +63,6 @@ import com.tangem.utils.Provider
import com.tangem.utils.coroutines.*
import com.tangem.utils.extensions.isSingleItem
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import timber.log.Timber
@ -157,25 +156,25 @@ internal class StakingViewModel @Inject constructor(
stakingStateRouter.onBackClick()
}
override fun onNextClick(actionType: StakingActionCommonType?, pendingActions: ImmutableList<PendingAction>) {
override fun onNextClick(actionType: StakingActionCommonType?, pendingAction: PendingAction?) {
if (actionType != null) {
stateController.update { it.copy(actionType = actionType) }
}
stakingStateRouter.onNextClick()
if (isAssentState()) {
getFee(pendingActions)
getFee(pendingAction)
}
}
override fun onActionClick(pendingAction: PendingAction?) {
handleOnNextConfirmationClick(pendingAction)
override fun onActionClick() {
handleOnNextConfirmationClick()
stakingStateRouter.onNextClick()
}
private fun handleOnNextConfirmationClick(pendingAction: PendingAction?) {
private fun handleOnNextConfirmationClick() {
if (isAssentState()) {
viewModelScope.launch {
stateController.update(SetConfirmationStateInProgressTransformer(pendingAction))
stateController.update(SetConfirmationStateInProgressTransformer())
val confirmationState =
value.confirmationState as? StakingStates.ConfirmationState.Data ?: error("No confirmation state")
@ -186,6 +185,7 @@ internal class StakingViewModel @Inject constructor(
val fee = (confirmationState.feeState as? FeeState.Content)?.fee ?: error("No fee provided")
val defaultAddress = cryptoCurrencyStatus.value.networkAddress?.defaultAddress?.value
?: error("No available address")
val pendingAction = confirmationState.pendingAction
val stakingTransactions = getStakingTransactionUseCase(
userWalletId = userWalletId,
@ -230,13 +230,13 @@ internal class StakingViewModel @Inject constructor(
sendStakingTransaction(
fullTransactionsData = fullTransactionsData,
fee = fee,
pendingActionList = confirmationState.pendingActions,
pendingAction = confirmationState.pendingAction,
)
}
}
}
private fun getFee(pendingActions: ImmutableList<PendingAction>) {
private fun getFee(pendingAction: PendingAction?) {
viewModelScope.launch {
stateController.update(
SetConfirmationStateLoadingTransformer(
@ -270,7 +270,7 @@ internal class StakingViewModel @Inject constructor(
)
} else {
estimateGas(
pendingActions = pendingActions,
pendingAction = pendingAction,
amount = amount,
sourceAddress = sourceAddress,
validatorAddress = validatorAddress,
@ -278,7 +278,7 @@ internal class StakingViewModel @Inject constructor(
}
} else {
estimateGas(
pendingActions = pendingActions,
pendingAction = pendingAction,
amount = amount,
sourceAddress = sourceAddress,
validatorAddress = validatorAddress,
@ -288,12 +288,11 @@ internal class StakingViewModel @Inject constructor(
}
private suspend fun estimateGas(
pendingActions: ImmutableList<PendingAction>,
pendingAction: PendingAction?,
amount: BigDecimal,
sourceAddress: String,
validatorAddress: String,
) {
val pendingAction = pendingActions.firstOrNull()
val gasEstimate = estimateGasUseCase(
userWalletId = userWalletId,
network = cryptoCurrencyStatus.currency.network,
@ -323,7 +322,7 @@ internal class StakingViewModel @Inject constructor(
decimals = gasEstimate.token.decimals,
),
),
pendingActionList = pendingActions,
action = pendingAction,
),
)
}
@ -397,14 +396,29 @@ internal class StakingViewModel @Inject constructor(
}
override fun onActiveStake(activeStake: BalanceState) {
val actionType = if (activeStake.pendingActions.isEmpty()) {
StakingActionCommonType.EXIT
if (activeStake.pendingActions.size > 1) {
stateController.update(
ShowActionSelectorBottomSheetTransformer(
pendingActions = activeStake.pendingActions,
onActionSelect = {
onNextClick(actionType = StakingActionCommonType.PENDING_OTHER, pendingAction = it)
stateController.update(DismissBottomSheetStateTransformer())
},
onDismiss = {
stateController.update(DismissBottomSheetStateTransformer())
},
),
)
} else {
StakingActionCommonType.PENDING_OTHER
val actionType = if (activeStake.pendingActions.isEmpty()) {
StakingActionCommonType.EXIT
} else {
StakingActionCommonType.PENDING_OTHER
}
stateController.update(ValidatorSelectChangeTransformer(activeStake.validator))
stateController.update(AmountChangeStateTransformer(cryptoCurrencyStatus, activeStake.cryptoValue, yield))
onNextClick(actionType, activeStake.pendingActions.firstOrNull())
}
stateController.update(ValidatorSelectChangeTransformer(activeStake.validator))
stateController.update(AmountChangeStateTransformer(cryptoCurrencyStatus, activeStake.cryptoValue, yield))
onNextClick(actionType, activeStake.pendingActions)
}
override fun showApprovalBottomSheet() {
@ -479,13 +493,13 @@ internal class StakingViewModel @Inject constructor(
ifRight = {
stateController.update(SetApprovalInProgressTransformer)
stateController.update(DismissBottomSheetStateTransformer())
awaitForAllowance(confirmationState.pendingActions)
awaitForAllowance(confirmationState.pendingAction)
},
)
}.saveIn(approvalJobHolder)
}
private fun awaitForAllowance(pendingActions: ImmutableList<PendingAction>) {
private fun awaitForAllowance(pendingAction: PendingAction?) {
val approval = stakingApproval as? StakingApproval.Needed ?: return
allowanceTaskScheduler.scheduleTask(
scope = viewModelScope,
@ -504,7 +518,7 @@ internal class StakingViewModel @Inject constructor(
val amount = (value.amountState as? AmountState.Data)?.amountTextField?.cryptoAmount?.value
?: error("No amount provided")
if (allowance >= amount) {
getFee(pendingActions)
getFee(pendingAction)
allowanceTaskScheduler.cancelTask()
}
},
@ -643,7 +657,7 @@ internal class StakingViewModel @Inject constructor(
private suspend fun sendStakingTransaction(
fullTransactionsData: List<FullTransactionData>,
fee: Fee,
pendingActionList: ImmutableList<PendingAction>,
pendingAction: PendingAction?,
) {
sendMultipleTransactionUseCase(
txsData = fullTransactionsData.map { it.tangemTransaction },
@ -657,7 +671,7 @@ internal class StakingViewModel @Inject constructor(
appCurrencyProvider = Provider { appCurrency },
feeCryptoCurrencyStatus = feeCryptoCurrencyStatus,
fee = fee,
pendingActionList = pendingActionList,
action = pendingAction,
),
)
stakingEventFactory.createSendTransactionErrorAlert(error)