Updated on 2026-08-14
This commit is contained in:
parent
a8cd6f1d8b
commit
6f47c78b23
11 changed files with 62 additions and 2 deletions
|
|
@ -224,4 +224,12 @@ internal object StakingDomainModule {
|
|||
): CheckAccountInitializedUseCase {
|
||||
return CheckAccountInitializedUseCase(walletManagersFacade)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideGetActionRequirementAmountUseCase(
|
||||
stakingRepository: StakingRepository,
|
||||
): GetActionRequirementAmountUseCase {
|
||||
return GetActionRequirementAmountUseCase(stakingRepository)
|
||||
}
|
||||
}
|
||||
|
|
@ -72,6 +72,7 @@ import kotlinx.coroutines.launch
|
|||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import timber.log.Timber
|
||||
import java.math.BigDecimal
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
@Suppress("LargeClass", "LongParameterList", "TooManyFunctions")
|
||||
|
|
@ -662,6 +663,14 @@ internal class DefaultStakingRepository(
|
|||
}
|
||||
}
|
||||
|
||||
override fun getActionRequirementAmount(integrationId: String, stakingActionType: StakingActionType): BigDecimal? {
|
||||
return when {
|
||||
stakingIdFactory.isPolygonIntegrationId(integrationId) &&
|
||||
stakingActionType == StakingActionType.CLAIM_REWARDS -> BigDecimal.ONE
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun createActionRequestBody(
|
||||
userWalletId: UserWalletId,
|
||||
network: Network,
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ internal class StakingIdFactory @Inject constructor(
|
|||
return integrationIdMap[integrationKey]
|
||||
}
|
||||
|
||||
fun isPolygonIntegrationId(integrationId: String): Boolean = integrationId == ETHEREUM_POLYGON_INTEGRATION_ID
|
||||
|
||||
@Suppress("UnusedPrivateMember", "unused")
|
||||
companion object {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package com.tangem.domain.staking
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.staking.model.stakekit.action.StakingActionType
|
||||
import com.tangem.domain.staking.repositories.StakingRepository
|
||||
import java.math.BigDecimal
|
||||
|
||||
class GetActionRequirementAmountUseCase(
|
||||
private val stakingRepository: StakingRepository,
|
||||
) {
|
||||
|
||||
operator fun invoke(integrationId: String, actionType: StakingActionType): Either<Throwable, BigDecimal?> =
|
||||
Either.catch {
|
||||
stakingRepository.getActionRequirementAmount(integrationId, actionType)
|
||||
}
|
||||
}
|
||||
|
|
@ -14,11 +14,13 @@ import com.tangem.domain.staking.model.stakekit.YieldBalance
|
|||
import com.tangem.domain.staking.model.stakekit.YieldBalanceList
|
||||
import com.tangem.domain.staking.model.stakekit.action.StakingAction
|
||||
import com.tangem.domain.staking.model.stakekit.action.StakingActionStatus
|
||||
import com.tangem.domain.staking.model.stakekit.action.StakingActionType
|
||||
import com.tangem.domain.staking.model.stakekit.transaction.ActionParams
|
||||
import com.tangem.domain.staking.model.stakekit.transaction.StakingGasEstimate
|
||||
import com.tangem.domain.staking.model.stakekit.transaction.StakingTransaction
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import java.math.BigDecimal
|
||||
|
||||
@Suppress("TooManyFunctions")
|
||||
interface StakingRepository {
|
||||
|
|
@ -100,4 +102,9 @@ interface StakingRepository {
|
|||
fun getStakingApproval(cryptoCurrency: CryptoCurrency): StakingApproval
|
||||
|
||||
suspend fun isAnyTokenStaked(userWalletId: UserWalletId): Boolean
|
||||
|
||||
/**
|
||||
* Return action requirement amount
|
||||
*/
|
||||
fun getActionRequirementAmount(integrationId: String, stakingActionType: StakingActionType): BigDecimal?
|
||||
}
|
||||
|
|
@ -188,6 +188,8 @@ class MockStakingRepository : StakingRepository {
|
|||
override fun getStakingApproval(cryptoCurrency: CryptoCurrency): StakingApproval = StakingApproval.Empty
|
||||
|
||||
override suspend fun isAnyTokenStaked(userWalletId: UserWalletId): Boolean = false
|
||||
override fun getActionRequirementAmount(integrationId: String, stakingActionType: StakingActionType): BigDecimal? =
|
||||
null
|
||||
|
||||
private companion object {
|
||||
val yield = Yield(
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import com.tangem.domain.staking.model.StakingApproval
|
|||
import com.tangem.domain.staking.model.stakekit.*
|
||||
import com.tangem.domain.staking.model.stakekit.action.StakingAction
|
||||
import com.tangem.domain.staking.model.stakekit.action.StakingActionCommonType
|
||||
import com.tangem.domain.staking.model.stakekit.action.StakingActionType
|
||||
import com.tangem.domain.staking.model.stakekit.transaction.StakingTransaction
|
||||
import com.tangem.domain.staking.utils.getValidatorsCount
|
||||
import com.tangem.domain.tokens.*
|
||||
|
|
@ -120,6 +121,7 @@ internal class StakingModel @Inject constructor(
|
|||
private val getActionsUseCase: GetActionsUseCase,
|
||||
private val getYieldUseCase: GetYieldUseCase,
|
||||
private val checkAccountInitializedUseCase: CheckAccountInitializedUseCase,
|
||||
private val getActionRequirementAmountUseCase: GetActionRequirementAmountUseCase,
|
||||
private val paramsInterceptorHolder: ParamsInterceptorHolder,
|
||||
private val shareManager: ShareManager,
|
||||
@DelayedWork private val coroutineScope: CoroutineScope,
|
||||
|
|
@ -527,9 +529,20 @@ internal class StakingModel @Inject constructor(
|
|||
val rewardPendingActionConstraints = yieldBalance?.reward?.rewardConstraints
|
||||
|
||||
if (rewardBlockType == RewardBlockType.RewardsRequirementsError) {
|
||||
val minimumAmount = rewardPendingActionConstraints?.amountArg?.minimum
|
||||
// Temporary fix, until StakeKit adds minimum requirement amount to balance response
|
||||
val minimumAmountValue = if (minimumAmount == null && yieldBalance.integrationId != null) {
|
||||
getActionRequirementAmountUseCase.invoke(
|
||||
integrationId = yieldBalance.integrationId,
|
||||
actionType = StakingActionType.CLAIM_REWARDS,
|
||||
).getOrNull()
|
||||
} else {
|
||||
minimumAmount
|
||||
}
|
||||
|
||||
stakingEventFactory.createStakingRewardsMinimumRequirementsErrorAlert(
|
||||
cryptoCurrencyName = cryptoCurrencyStatus.currency.name,
|
||||
cryptoAmountValue = rewardPendingActionConstraints?.amountArg?.minimum?.format {
|
||||
cryptoAmountValue = minimumAmountValue?.format {
|
||||
crypto(cryptoCurrencyStatus.currency)
|
||||
}.orEmpty(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import java.math.BigDecimal
|
|||
@Immutable
|
||||
internal sealed class InnerYieldBalanceState {
|
||||
data class Data(
|
||||
val integrationId: String?,
|
||||
val reward: YieldReward,
|
||||
val isActionable: Boolean,
|
||||
val balances: ImmutableList<BalanceState>,
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ internal class YieldBalancesConverter(
|
|||
?.firstOrNull { it.type == StakingActionType.CLAIM_REWARDS }
|
||||
|
||||
InnerYieldBalanceState.Data(
|
||||
integrationId = yieldBalance?.integrationId,
|
||||
reward = YieldReward(
|
||||
rewardsCrypto = cryptoRewardsValue.format { crypto(cryptoCurrency) },
|
||||
rewardsFiat = fiatRewardsValue.format {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ internal object InitialStakingStatePreview {
|
|||
|
||||
val stateWithYield = defaultState.copy(
|
||||
yieldBalance = InnerYieldBalanceState.Data(
|
||||
integrationId = null,
|
||||
reward = YieldReward(
|
||||
rewardsFiat = "100 $",
|
||||
rewardsCrypto = "100 SOL",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
# https://github.com/tangem/tangem-sdk-android/
|
||||
# https://github.com/tangem/vico
|
||||
|
||||
tangemBlockchainSdk = "releases-5.26.0-1105"
|
||||
tangemBlockchainSdk = "releases-5.26.0-1107"
|
||||
#tangemBlockchainSdk = "0.0.1" # Keep it! - used for local builds
|
||||
tangemCardSdk = "releases-5.26.0-488"
|
||||
#tangemCardSdk = "0.0.1" # Keep it! - used for local builds ^
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue