Updated on 2026-08-14

This commit is contained in:
Tangem 2025-05-22 13:52:48 +03:00
parent 415e1d1b43
commit f27ac5242e

View file

@ -55,39 +55,14 @@ internal class StakingInfoNotificationsFactory(
is StakingActionCommonType.Pending -> {
addCardanoRestakeMinimumAmountNotification(feeValue)
addPendingInfoNotifications(prevState)
addTonHaveToUnstakeAllNotification(prevState)
}
}
}
private fun MutableList<NotificationUM>.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<NotificationUM>.addEnterInfoNotifications(
@ -248,6 +223,53 @@ internal class StakingInfoNotificationsFactory(
}
}
private fun MutableList<NotificationUM>.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<NotificationUM>.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<NotificationUM>.addTonExtraFeeInfoNotification(tonBalanceExtraFeeThreshold: BigDecimal) {
val amount = cryptoCurrencyStatusProvider().value.amount.orZero()
val cryptoCurrencyNetworkIdValue = cryptoCurrencyStatusProvider().currency.network.id.value