Updated on 2026-08-14

This commit is contained in:
Tangem 2025-12-25 16:43:42 +02:00
parent 3767ae01b2
commit ee0e649e6a
9 changed files with 63 additions and 33 deletions

View file

@ -0,0 +1,8 @@
package com.tangem.domain.staking.model
sealed class CooldownPeriod {
data class Fixed(val days: Int) : CooldownPeriod()
data class Range(val minDays: Int, val maxDays: Int) : CooldownPeriod()
}

View file

@ -64,7 +64,10 @@ class P2PEthPoolIntegration(
override val warmupPeriodDays: Int = 0
override val cooldownPeriodDays: Int = DEFAULT_COOLDOWN_DAYS
override val cooldownPeriod: CooldownPeriod = CooldownPeriod.Range(
minDays = MIN_COOLDOWN_DAYS,
maxDays = MAX_COOLDOWN_DAYS,
)
override val rewardSchedule: RewardSchedule = RewardSchedule.DAY
@ -73,7 +76,8 @@ class P2PEthPoolIntegration(
override fun getCurrentToken(rawCurrencyId: CryptoCurrency.RawID?): YieldToken = token
companion object {
private const val DEFAULT_COOLDOWN_DAYS = 7
private const val MIN_COOLDOWN_DAYS = 1
private const val MAX_COOLDOWN_DAYS = 4
private val DEFAULT_MINIMUM_STAKE = BigDecimal("0.01")
}
}

View file

@ -51,7 +51,9 @@ class StakeKitIntegration(
override val warmupPeriodDays: Int = yield.metadata.warmupPeriod.days
override val cooldownPeriodDays: Int? = yield.metadata.cooldownPeriod?.days
override val cooldownPeriod: CooldownPeriod? = yield.metadata.cooldownPeriod?.days?.let {
CooldownPeriod.Fixed(it)
}
override val rewardSchedule: RewardSchedule = yield.metadata.rewardSchedule.toRewardSchedule()

View file

@ -45,7 +45,7 @@ sealed interface StakingIntegration {
val warmupPeriodDays: Int
val cooldownPeriodDays: Int?
val cooldownPeriod: CooldownPeriod?
val rewardSchedule: RewardSchedule

View file

@ -4,7 +4,9 @@ import androidx.annotation.StringRes
import com.tangem.common.ui.notifications.NotificationUM
import com.tangem.core.ui.components.notifications.NotificationConfig
import com.tangem.core.ui.extensions.*
import com.tangem.domain.staking.model.CooldownPeriod
import com.tangem.features.staking.impl.R
import com.tangem.features.staking.impl.presentation.state.utils.toTextReference
internal object StakingNotification {
@ -106,19 +108,13 @@ internal object StakingNotification {
)
data class Unstake(
val cooldownPeriodDays: Int,
val cooldownPeriod: CooldownPeriod,
@StringRes val subtitleRes: Int,
) : Info(
title = resourceReference(R.string.common_unstake),
subtitle = resourceReference(
subtitleRes,
wrappedList(
pluralReference(
id = R.plurals.common_days,
count = cooldownPeriodDays,
formatArgs = wrappedList(cooldownPeriodDays),
),
),
wrappedList(cooldownPeriod.toTextReference()),
),
)

View file

@ -22,6 +22,7 @@ import com.tangem.domain.staking.model.StakingIntegration
import com.tangem.domain.staking.model.StakingTarget
import com.tangem.features.staking.impl.R
import com.tangem.features.staking.impl.presentation.state.BalanceState
import com.tangem.features.staking.impl.presentation.state.utils.toTextReference
import com.tangem.lib.crypto.BlockchainUtils
import com.tangem.lib.crypto.BlockchainUtils.isTon
import com.tangem.utils.Provider
@ -143,13 +144,13 @@ internal class StakingBalanceEntryConverter(
}
private fun getUnbondingDate(date: Instant?): TextReference? {
val unbondingPeriod = integration.cooldownPeriodDays ?: return null
val cooldownPeriod = integration.cooldownPeriod ?: return null
if (date == null) {
return TextReference.Combined(
wrappedList(
resourceReference(R.string.staking_details_unbonding_period),
stringReference(" "),
pluralReference(R.plurals.common_days, unbondingPeriod, wrappedList(unbondingPeriod)),
cooldownPeriod.toTextReference(),
),
)
}

View file

@ -33,6 +33,7 @@ import com.tangem.features.staking.impl.presentation.state.bottomsheet.InfoType
import com.tangem.features.staking.impl.presentation.state.converters.RewardsValidatorStateConverter
import com.tangem.features.staking.impl.presentation.state.converters.YieldBalancesConverter
import com.tangem.features.staking.impl.presentation.state.utils.getRewardScheduleText
import com.tangem.features.staking.impl.presentation.state.utils.toTextReference
import com.tangem.utils.Provider
import com.tangem.utils.StringsSigns.DASH_SIGN
import com.tangem.utils.isNullOrZero
@ -156,15 +157,11 @@ internal class SetInitialDataStateTransformer(
}
private fun createUnbondingPeriodItem(): RoundedListWithDividersItemData? {
val cooldownPeriodDays = integration.cooldownPeriodDays ?: return null
val cooldownPeriod = integration.cooldownPeriod ?: return null
return RoundedListWithDividersItemData(
id = R.string.staking_details_unbonding_period,
startText = TextReference.Res(R.string.staking_details_unbonding_period),
endText = pluralReference(
id = R.plurals.common_days,
count = cooldownPeriodDays,
formatArgs = wrappedList(cooldownPeriodDays),
),
endText = cooldownPeriod.toTextReference(),
iconClick = { clickIntents.onInfoClick(InfoType.UNBONDING_PERIOD) },
)
}

View file

@ -2,7 +2,6 @@ package com.tangem.features.staking.impl.presentation.state.transformers.notific
import com.tangem.blockchain.common.Amount
import com.tangem.common.ui.notifications.NotificationUM
import com.tangem.core.ui.extensions.pluralReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.core.ui.format.bigdecimal.crypto
@ -19,6 +18,7 @@ import com.tangem.features.staking.impl.presentation.state.InnerYieldBalanceStat
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.StakingUiState
import com.tangem.features.staking.impl.presentation.state.utils.toTextReference
import com.tangem.lib.crypto.BlockchainUtils.isCardano
import com.tangem.lib.crypto.BlockchainUtils.isCosmos
import com.tangem.lib.crypto.BlockchainUtils.isTon
@ -115,17 +115,11 @@ internal class StakingInfoNotificationsFactory(
resourceReference(R.string.staking_notification_withdraw_text)
}
StakingActionType.UNLOCK_LOCKED -> {
val cooldownPeriodDays = integration.cooldownPeriodDays
if (cooldownPeriodDays != null) {
val cooldownPeriod = integration.cooldownPeriod
if (cooldownPeriod != null) {
resourceReference(R.string.staking_unlocked_locked) to resourceReference(
R.string.staking_notification_unlock_text,
wrappedList(
pluralReference(
id = R.plurals.common_days,
count = cooldownPeriodDays,
formatArgs = wrappedList(cooldownPeriodDays),
),
),
wrappedList(cooldownPeriod.toTextReference()),
)
} else {
null to null
@ -276,13 +270,13 @@ internal class StakingInfoNotificationsFactory(
}
private fun MutableList<NotificationUM>.addUnstakeInfoNotification() {
val cooldownPeriodDays = integration.cooldownPeriodDays
val cooldownPeriod = integration.cooldownPeriod
val cryptoCurrencyNetworkIdValue = cryptoCurrencyStatusProvider().currency.network.rawId
if (cooldownPeriodDays != null) {
if (cooldownPeriod != null) {
add(
StakingNotification.Info.Unstake(
cooldownPeriodDays = cooldownPeriodDays,
cooldownPeriod = cooldownPeriod,
subtitleRes = if (isCosmos(cryptoCurrencyNetworkIdValue)) {
R.string.staking_notification_unstake_cosmos_text
} else {

View file

@ -0,0 +1,28 @@
package com.tangem.features.staking.impl.presentation.state.utils
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.combinedReference
import com.tangem.core.ui.extensions.pluralReference
import com.tangem.core.ui.extensions.stringReference
import com.tangem.core.ui.extensions.wrappedList
import com.tangem.domain.staking.model.CooldownPeriod
import com.tangem.features.staking.impl.R
import com.tangem.utils.StringsSigns.MINUS
import com.tangem.utils.StringsSigns.NON_BREAKING_SPACE
internal fun CooldownPeriod.toTextReference(): TextReference {
return when (this) {
is CooldownPeriod.Fixed -> pluralReference(
id = R.plurals.common_days,
count = days,
formatArgs = wrappedList(days),
)
is CooldownPeriod.Range -> combinedReference(
stringReference("$minDays$MINUS$maxDays$NON_BREAKING_SPACE"),
pluralReference(
id = R.plurals.common_days_no_param,
count = maxDays,
),
)
}
}