Skip to content

Commit

Permalink
Rebag validations (#1062)
Browse files Browse the repository at this point in the history
* Rebag validations

* Code style
  • Loading branch information
valentunn authored Aug 16, 2023
1 parent 511e63d commit 265fb09
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dagger.Provides
import dagger.multibindings.IntoMap
import io.novafoundation.nova.common.di.scope.FeatureScope
import io.novafoundation.nova.common.validation.CompositeValidation
import io.novafoundation.nova.common.validation.ValidationSystem
import io.novafoundation.nova.feature_account_api.domain.interfaces.AccountRepository
import io.novafoundation.nova.feature_staking_api.domain.api.StakingRepository
import io.novafoundation.nova.feature_staking_impl.data.StakingSharedState
Expand All @@ -16,6 +17,7 @@ import io.novafoundation.nova.feature_staking_impl.domain.validations.main.MainS
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.MainStakingUnlockingLimitValidation
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.SYSTEM_MANAGE_REWARD_DESTINATION
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.SYSTEM_MANAGE_STAKING_BOND_MORE
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.SYSTEM_MANAGE_STAKING_REBAG
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.SYSTEM_MANAGE_STAKING_REBOND
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.SYSTEM_MANAGE_STAKING_REDEEM
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.SYSTEM_MANAGE_STAKING_UNBOND
Expand Down Expand Up @@ -128,6 +130,16 @@ class StakeActionsValidationsModule {
)
)

@FeatureScope
@Named(SYSTEM_MANAGE_STAKING_REBAG)
@Provides
fun provideRebagValidationSystem(
@Named(BALANCE_REQUIRED_CONTROLLER)
controllerRequiredValidation: MainStakingAccountRequiredValidation
): StakeActionsValidationSystem = ValidationSystem {
validate(controllerRequiredValidation)
}

@FeatureScope
@Named(SYSTEM_MANAGE_REWARD_DESTINATION)
@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ const val SYSTEM_MANAGE_REWARD_DESTINATION = "ManageStakingRewardDestination"
const val SYSTEM_MANAGE_PAYOUTS = "ManageStakingPayouts"
const val SYSTEM_MANAGE_VALIDATORS = "ManageStakingValidators"
const val SYSTEM_MANAGE_CONTROLLER = "ManageStakingController"
const val SYSTEM_MANAGE_STAKING_REBAG = "ManageStakingRebag"

typealias StakeActionsValidationSystem = ValidationSystem<StakeActionsValidationPayload, StakeActionsValidationFailure>
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RelaychainAlertsComponentFactory(
private val resourceManager: ResourceManager,
private val redeemValidationSystem: StakeActionsValidationSystem,
private val bondMoreValidationSystem: StakeActionsValidationSystem,
private val rebagValidationSystem: StakeActionsValidationSystem,
private val router: StakingRouter,
private val stakingSharedComputation: StakingSharedComputation,
) {
Expand All @@ -53,6 +54,7 @@ class RelaychainAlertsComponentFactory(
alertsInteractor = alertsInteractor,
redeemValidationSystem = redeemValidationSystem,
bondMoreValidationSystem = bondMoreValidationSystem,
rebagValidationSystem = rebagValidationSystem,
router = router,

assetWithChain = assetWithChain,
Expand All @@ -70,6 +72,7 @@ private class RelaychainAlertsComponent(

private val redeemValidationSystem: StakeActionsValidationSystem,
private val bondMoreValidationSystem: StakeActionsValidationSystem,
private val rebagValidationSystem: StakeActionsValidationSystem,
private val router: StakingRouter,
) : AlertsComponent,
CoroutineScope by hostContext.scope,
Expand Down Expand Up @@ -138,7 +141,7 @@ private class RelaychainAlertsComponent(
Alert.Rebag -> AlertModel(
resourceManager.getString(R.string.staking_alert_rebag_title),
resourceManager.getString(R.string.staking_alert_rebag_message),
AlertModel.Type.CallToAction { router.openRebag() }
AlertModel.Type.CallToAction(::rebagClicked)
)
}
}
Expand All @@ -162,6 +165,10 @@ private class RelaychainAlertsComponent(
router.openRedeem()
}

private fun rebagClicked() = requireValidManageStakingAction(rebagValidationSystem) {
router.openRebag()
}

private fun requireValidManageStakingAction(
validationSystem: StakeActionsValidationSystem,
action: () -> Unit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.novafoundation.nova.feature_staking_impl.domain.common.StakingSharedCo
import io.novafoundation.nova.feature_staking_impl.domain.period.StakingRewardPeriodInteractor
import io.novafoundation.nova.feature_staking_impl.domain.staking.unbond.UnbondInteractor
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.SYSTEM_MANAGE_STAKING_BOND_MORE
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.SYSTEM_MANAGE_STAKING_REBAG
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.SYSTEM_MANAGE_STAKING_REBOND
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.SYSTEM_MANAGE_STAKING_REDEEM
import io.novafoundation.nova.feature_staking_impl.domain.validations.main.StakeActionsValidationSystem
Expand All @@ -37,13 +38,15 @@ class RelaychainModule {
resourceManager: ResourceManager,
@Named(SYSTEM_MANAGE_STAKING_REDEEM) redeemValidationSystem: StakeActionsValidationSystem,
@Named(SYSTEM_MANAGE_STAKING_BOND_MORE) bondMoreValidationSystem: StakeActionsValidationSystem,
@Named(SYSTEM_MANAGE_STAKING_REBAG) rebagValidationSystem: StakeActionsValidationSystem,
router: StakingRouter,
) = RelaychainAlertsComponentFactory(
stakingSharedComputation = stakingSharedComputation,
alertsInteractor = alertsInteractor,
resourceManager = resourceManager,
redeemValidationSystem = redeemValidationSystem,
bondMoreValidationSystem = bondMoreValidationSystem,
rebagValidationSystem = rebagValidationSystem,
router = router
)

Expand Down

0 comments on commit 265fb09

Please sign in to comment.