Skip to content

Commit

Permalink
Fix/min stake relaychain logic (#1115)
Browse files Browse the repository at this point in the history
* Fixed minStake calculation logic for relaychains

* Update StartStakingLandingViewModel.kt
  • Loading branch information
antonijzelinskij authored Sep 13, 2023
1 parent 5afe1b9 commit 0745b02
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
3 changes: 3 additions & 0 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="TypographyEllipsis">

<string name="start_staking_fragment_min_stake_condition_no_min_stake">Stake anytime. Your stake will actively earn rewards %s</string>

<string name="pool_full_failure_title">Pool is full</string>
<string name="pool_full_failure_message">You cannot join pool since it reached maximum number of members</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountIdKey, BigInteger>()) { acc, exposure ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0745b02

Please sign in to comment.