Skip to content

Commit a20a28d

Browse files
authored
Merge pull request #647 from soramitsu/staging
fix moonriver
2 parents a0af83c + 7c0bf4e commit a20a28d

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

feature-staking-impl/src/main/java/jp/co/soramitsu/feature_staking_impl/presentation/confirm/ConfirmStakingViewModel.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,12 @@ class ConfirmStakingViewModel(
227227
is SetupStakingProcess.ReadyToSubmit.Parachain -> {
228228
val collator = currentProcessState.payload.blockProducers.first()
229229
val amount = bondPayload?.amount ?: error("Amount cant be null")
230-
val delegationCount = (scenarioInteractor.stakingStateFlow.first() as StakingState.Parachain.Delegator).delegations.size
230+
val delegationCount = when (val state = scenarioInteractor.stakingStateFlow.first()) {
231+
is StakingState.Parachain.Delegator -> state.delegations.size
232+
is StakingState.Parachain.Collator -> 0 // todo add collators support
233+
is StakingState.Parachain.None -> 0
234+
else -> 0
235+
}
231236
setupStakingInteractor.estimateFinalParachainFee(collator, it.planksFromAmount(amount), delegationCount)
232237
}
233238
}
@@ -287,7 +292,12 @@ class ConfirmStakingViewModel(
287292
val token = controllerAssetFlow.first().token
288293
val collator = currentProcessState.payload.blockProducers.first()
289294
val amount = bondPayload?.amount ?: error("Amount cant be null")
290-
val delegationCount = (scenarioInteractor.stakingStateFlow.first() as StakingState.Parachain.Delegator).delegations.size
295+
val delegationCount = when (val state = scenarioInteractor.stakingStateFlow.first()) {
296+
is StakingState.Parachain.Delegator -> state.delegations.size
297+
is StakingState.Parachain.Collator -> 0 // todo add collators support
298+
is StakingState.Parachain.None -> 0
299+
else -> 0
300+
}
291301
val accountAddress = (scenarioInteractor.stakingStateFlow.first() as StakingState.Parachain).accountAddress
292302
setupStakingInteractor.setupStaking(collator, token.planksFromAmount(amount), delegationCount, accountAddress)
293303
}

feature-staking-impl/src/main/java/jp/co/soramitsu/feature_staking_impl/presentation/staking/balance/StakingBalanceFragment.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ class StakingBalanceFragment : BaseFragment<StakingBalanceViewModel>(R.layout.fr
9494
binding.stakingBalanceUnbondings.unbondingsMoreAction.isEnabled = it
9595
}
9696

97+
viewModel.pendingAction.observe {
98+
binding.stakingBalanceActions.bondMore.isEnabled = it.not()
99+
binding.stakingBalanceActions.unbond.isEnabled = it.not()
100+
binding.stakingBalanceActions.redeem.isEnabled = it.not()
101+
}
102+
97103
viewModel.redeemEnabledLiveData.observe {
98104
binding.stakingBalanceActions.redeem.isEnabled = it
99105
}

feature-staking-impl/src/main/java/jp/co/soramitsu/feature_staking_impl/presentation/staking/balance/StakingBalanceViewModel.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class StakingBalanceViewModel(
6868
it.redeemable.amount > BigDecimal.ZERO
6969
}.asLiveData()
7070

71+
val pendingAction = MutableLiveData(false)
72+
7173
val shouldBlockActionButtons = stakingBalanceModelLiveData.map {
7274
val isParachain = assetFlow.first().token.configuration.staking == Chain.Asset.StakingType.PARACHAIN
7375
(it.redeemable.amount + it.unstaking.amount > BigDecimal.ZERO).and(isParachain)
@@ -167,10 +169,16 @@ class StakingBalanceViewModel(
167169
block: (ManageStakingValidationPayload) -> Unit,
168170
) {
169171
launch {
172+
pendingAction.value = true
170173
val stakingState = stakingScenarioInteractor.getSelectedAccountStakingState()
171174
validationExecutor.requireValid(
172175
validationSystem,
173176
ManageStakingValidationPayload(stakingState as? StakingState.Stash),
177+
progressConsumer = {
178+
if (it.not()) {
179+
pendingAction.value = false
180+
}
181+
},
174182
validationFailureTransformer = { manageStakingActionValidationFailure(it, resourceManager) },
175183
block = block
176184
)

feature-staking-impl/src/main/java/jp/co/soramitsu/feature_staking_impl/presentation/staking/bond/select/SelectBondMoreFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class SelectBondMoreFragment : BaseFragment<SelectBondMoreViewModel>(R.layout.fr
6767
observeValidations(viewModel)
6868

6969
viewModel.showNextProgress.observe(binding.bondMoreContinue::setProgress)
70+
viewModel.showNextProgress.observe(binding.bondMoreConfirm::setProgress)
7071

7172
viewModel.assetModelFlow.observe {
7273
binding.bondMoreAmount.setAssetBalance(it.assetBalance)

feature-staking-impl/src/main/java/jp/co/soramitsu/feature_staking_impl/presentation/staking/main/StakingViewState.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ sealed class StakeViewState<S>(
115115
private val availableManageActions: Set<ManageStakeAction>
116116
) : StakingViewState() {
117117

118-
init {
119-
syncStakingRewards()
120-
}
121-
122118
val manageStakingActionsButtonVisible = availableManageActions.isNotEmpty()
123119

124120
private val _showManageActionsEvent = MutableLiveData<Event<ManageStakingBottomSheet.Payload>>()
@@ -156,7 +152,7 @@ sealed class StakeViewState<S>(
156152
_showStatusAlertEvent.value = Event(titleAndMessage)
157153
}
158154

159-
private fun syncStakingRewards() {
155+
protected fun syncStakingRewards() {
160156
scope.launch {
161157
val syncResult = stakingInteractor.syncStakingRewards(stakeState.chain.id, stakeState.rewardsAddress)
162158

@@ -207,7 +203,11 @@ class ValidatorViewState(
207203
summaryFlowProvider = { relayChainScenarioInteractor.observeValidatorSummary(validatorState).shareIn(scope, SharingStarted.Eagerly, replay = 1) },
208204
statusMessageProvider = { getValidatorStatusTitleAndMessage(resourceManager, it) },
209205
availableManageActions = ManageStakeAction.values().toSet() - ManageStakeAction.VALIDATORS
210-
)
206+
) {
207+
init {
208+
syncStakingRewards()
209+
}
210+
}
211211

212212
private fun getValidatorStatusTitleAndMessage(
213213
resourceManager: ResourceManager,
@@ -237,7 +237,11 @@ class StashNoneViewState(
237237
summaryFlowProvider = { relayChainScenarioInteractor.observeStashSummary(stashState).shareIn(scope, SharingStarted.Eagerly, replay = 1) },
238238
statusMessageProvider = { getStashStatusTitleAndMessage(resourceManager, it) },
239239
availableManageActions = ManageStakeAction.values().toSet() - ManageStakeAction.PAYOUTS
240-
)
240+
) {
241+
init {
242+
syncStakingRewards()
243+
}
244+
}
241245

242246
private fun getStashStatusTitleAndMessage(
243247
resourceManager: ResourceManager,
@@ -265,7 +269,11 @@ class NominatorViewState(
265269
summaryFlowProvider = { relayChainScenarioInteractor.observeNominatorSummary(nominatorState).shareIn(scope, SharingStarted.Eagerly, replay = 1) },
266270
statusMessageProvider = { getNominatorStatusTitleAndMessage(resourceManager, it) },
267271
availableManageActions = ManageStakeAction.values().toSet()
268-
)
272+
) {
273+
init {
274+
syncStakingRewards()
275+
}
276+
}
269277

270278
private fun getNominatorStatusTitleAndMessage(
271279
resourceManager: ResourceManager,

feature-staking-impl/src/main/java/jp/co/soramitsu/feature_staking_impl/presentation/staking/unbond/select/SelectUnbondFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class SelectUnbondFragment : BaseFragment<SelectUnbondViewModel>(R.layout.fragme
6666
observeValidations(viewModel)
6767

6868
viewModel.showNextProgress.observe(binding.unbondContinue::setProgress)
69+
viewModel.showNextProgress.observe(binding.unbondConfirm::setProgress)
6970

7071
viewModel.assetModelFlow.observe {
7172
binding.unbondAmount.setAssetBalance(it.assetBalance)

0 commit comments

Comments
 (0)