From 0745b02b83576a77595d24aabf75a9e4f06bd715 Mon Sep 17 00:00:00 2001 From: antonijzelinskij <107959809+antonijzelinskij@users.noreply.github.com> Date: Wed, 13 Sep 2023 09:23:07 +0200 Subject: [PATCH] Fix/min stake relaychain logic (#1115) * Fixed minStake calculation logic for relaychains * Update StartStakingLandingViewModel.kt --- common/src/main/res/values/strings.xml | 3 +++ .../domain/StakingInteractorExt.kt | 2 +- .../landing/StartStakingLandingViewModel.kt | 25 ++++++++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml index caab2747d2..d2ce8f3575 100644 --- a/common/src/main/res/values/strings.xml +++ b/common/src/main/res/values/strings.xml @@ -1,5 +1,8 @@ + + Stake anytime. Your stake will actively earn rewards %s + Pool is full You cannot join pool since it reached maximum number of members diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/StakingInteractorExt.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/StakingInteractorExt.kt index 56fe63f422..f75bccecb3 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/StakingInteractorExt.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/domain/StakingInteractorExt.kt @@ -67,7 +67,7 @@ fun minimumStake( bagListSize: BigInteger?, maxElectingVoters: BigInteger? ): BigInteger { - if (bagListSize != null && maxElectingVoters != null && bagListSize < maxElectingVoters) return minimumNominatorBond + if (bagListSize == null || maxElectingVoters == null || bagListSize < maxElectingVoters) return minimumNominatorBond val stakeByNominator = exposures .fold(mutableMapOf()) { acc, exposure -> diff --git a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/staking/start/landing/StartStakingLandingViewModel.kt b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/staking/start/landing/StartStakingLandingViewModel.kt index ee2feca9d8..e75cb8ca6c 100644 --- a/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/staking/start/landing/StartStakingLandingViewModel.kt +++ b/feature-staking-impl/src/main/java/io/novafoundation/nova/feature_staking_impl/presentation/staking/start/landing/StartStakingLandingViewModel.kt @@ -58,6 +58,7 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map import kotlinx.coroutines.launch import java.math.BigInteger +import jp.co.soramitsu.fearless_utils.hash.isPositive import kotlin.time.Duration class StartStakingInfoModel( @@ -261,17 +262,25 @@ class StartStakingLandingViewModel( eraDuration: Duration, themeColor: Int ): StakingConditionRVItem { - val minStake = minStakeAmount.formatPlanks(asset.token.configuration) - .toSpannable(colorSpan(themeColor)) val time = resourceManager.getString( R.string.start_staking_fragment_min_stake_condition_duration, resourceManager.formatDuration(eraDuration, false) ).toSpannable(colorSpan(themeColor)) - return StakingConditionRVItem( - iconId = R.drawable.ic_stake_anytime, - text = resourceManager.getString(R.string.start_staking_fragment_min_stake_condition).formatAsSpannable(minStake, time), - ) + return if (minStakeAmount.isPositive()) { + val minStake = minStakeAmount.formatPlanks(asset.token.configuration) + .toSpannable(colorSpan(themeColor)) + + StakingConditionRVItem( + iconId = R.drawable.ic_stake_anytime, + text = resourceManager.getString(R.string.start_staking_fragment_min_stake_condition).formatAsSpannable(minStake, time), + ) + } else { + StakingConditionRVItem( + iconId = R.drawable.ic_stake_anytime, + text = resourceManager.getString(R.string.start_staking_fragment_min_stake_condition_no_min_stake).formatAsSpannable(time), + ) + } } private fun createUnstakeCondition( @@ -304,17 +313,21 @@ class StartStakingLandingViewModel( isRestakeOnlyCase(payouts) -> { resourceManager.getString(R.string.start_staking_fragment_reward_frequency_condition_restake_only).formatAsSpannable(time) } + isPayoutsOnlyCase(payouts) -> { resourceManager.getString(R.string.start_staking_fragment_reward_frequency_condition_payout_only).formatAsSpannable(time) } + payoutTypes.containsOnly(PayoutType.Manual) -> { resourceManager.getString(R.string.start_staking_fragment_reward_frequency_condition_manual).formatAsSpannable(time) } + payoutTypes.containsManualAndAutomatic() -> { val automaticPayoutFormattedAmount = payouts.automaticPayoutMinAmount?.formatPlanks(asset.token.configuration).orEmpty() resourceManager.getString(R.string.start_staking_fragment_reward_frequency_condition_automatic_and_manual) .formatAsSpannable(time, automaticPayoutFormattedAmount) } + else -> { resourceManager.getString(R.string.start_staking_fragment_reward_frequency_condition_fallback) .formatAsSpannable(time)