From f27ac5242e1942f7fe56ac06075b357e8ed8cfb3 Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 22 May 2025 13:52:48 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../StakingInfoNotificationsFactory.kt | 78 ++++++++++++------- 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/notifications/StakingInfoNotificationsFactory.kt b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/notifications/StakingInfoNotificationsFactory.kt index 067bb899a0..1b1aedb51d 100644 --- a/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/notifications/StakingInfoNotificationsFactory.kt +++ b/features/staking/impl/src/main/java/com/tangem/features/staking/impl/presentation/state/transformers/notifications/StakingInfoNotificationsFactory.kt @@ -55,39 +55,14 @@ internal class StakingInfoNotificationsFactory( is StakingActionCommonType.Pending -> { addCardanoRestakeMinimumAmountNotification(feeValue) addPendingInfoNotifications(prevState) + addTonHaveToUnstakeAllNotification(prevState) } } } private fun MutableList.addExitInfoNotifications(prevState: StakingUiState) { - val cooldownPeriodDays = yield.metadata.cooldownPeriod?.days - - val cryptoCurrencyNetworkIdValue = cryptoCurrencyStatusProvider().currency.network.id.value - if (cooldownPeriodDays != null) { - add( - StakingNotification.Info.Unstake( - cooldownPeriodDays = cooldownPeriodDays, - subtitleRes = if (isCosmos(cryptoCurrencyNetworkIdValue)) { - R.string.staking_notification_unstake_cosmos_text - } else { - R.string.staking_notification_unstake_text - }, - ), - ) - } - - val initialInfoState = prevState.initialInfoState as? StakingStates.InitialInfoState.Data - val stakingBalances = (initialInfoState?.yieldBalance as? InnerYieldBalanceState.Data)?.balances - val activeStakesCount = stakingBalances.orEmpty().filter { it.type == BalanceType.STAKED }.size - - if (isTon(cryptoCurrencyNetworkIdValue) && activeStakesCount > 1) { - add( - StakingNotification.Info.Ordinary( - title = resourceReference(R.string.staking_notification_ton_have_to_unstake_all_title), - text = resourceReference(R.string.staking_notification_ton_have_to_unstake_all_text), - ), - ) - } + addUnstakeInfoNotification() + addTonHaveToUnstakeAllNotification(prevState) } private fun MutableList.addEnterInfoNotifications( @@ -248,6 +223,53 @@ internal class StakingInfoNotificationsFactory( } } + private fun MutableList.addUnstakeInfoNotification() { + val cooldownPeriodDays = yield.metadata.cooldownPeriod?.days + + val cryptoCurrencyNetworkIdValue = cryptoCurrencyStatusProvider().currency.network.id.value + if (cooldownPeriodDays != null) { + add( + StakingNotification.Info.Unstake( + cooldownPeriodDays = cooldownPeriodDays, + subtitleRes = if (isCosmos(cryptoCurrencyNetworkIdValue)) { + R.string.staking_notification_unstake_cosmos_text + } else { + R.string.staking_notification_unstake_text + }, + ), + ) + } + } + + private fun MutableList.addTonHaveToUnstakeAllNotification(prevState: StakingUiState) { + val cryptoCurrencyNetworkIdValue = cryptoCurrencyStatusProvider().currency.network.id.value + + if (isTon(cryptoCurrencyNetworkIdValue)) { + val initialInfoState = prevState.initialInfoState as? StakingStates.InitialInfoState.Data + val stakingBalances = (initialInfoState?.yieldBalance as? InnerYieldBalanceState.Data)?.balances + + val validatorAddress = prevState.balanceState?.validator?.address ?: return + + val stakesCountWithCertainValidator = stakingBalances.orEmpty() + .filter { + it.type == BalanceType.STAKED || + it.type == BalanceType.PREPARING || + it.type == BalanceType.UNSTAKED + } + .filter { it.validator?.address == validatorAddress } + .size + + if (stakesCountWithCertainValidator > 1) { + add( + StakingNotification.Info.Ordinary( + title = resourceReference(R.string.staking_notification_ton_have_to_unstake_all_title), + text = resourceReference(R.string.staking_notification_ton_have_to_unstake_all_text), + ), + ) + } + } + } + private fun MutableList.addTonExtraFeeInfoNotification(tonBalanceExtraFeeThreshold: BigDecimal) { val amount = cryptoCurrencyStatusProvider().value.amount.orZero() val cryptoCurrencyNetworkIdValue = cryptoCurrencyStatusProvider().currency.network.id.value