-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation to pool search (#1110)
- Loading branch information
1 parent
5e46ef0
commit 01afd37
Showing
11 changed files
with
125 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...feature_staking_impl/domain/nominationPools/selecting/PoolAvailabilityValidationSystem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.novafoundation.nova.feature_staking_impl.domain.nominationPools.selecting | ||
|
||
import io.novafoundation.nova.common.validation.ValidationSystem | ||
import io.novafoundation.nova.feature_staking_impl.domain.nominationPools.model.NominationPool | ||
import io.novafoundation.nova.runtime.multiNetwork.chain.model.Chain | ||
|
||
typealias PoolAvailabilityValidationSystem = ValidationSystem<PoolAvailabilityPayload, PoolAvailabilityFailure> | ||
|
||
class PoolAvailabilityPayload(val nominationPool: NominationPool, val chain: Chain) | ||
|
||
sealed interface PoolAvailabilityFailure { | ||
|
||
object PoolIsFull : PoolAvailabilityFailure | ||
|
||
object PoolIsClosed : PoolAvailabilityFailure | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
39 changes: 39 additions & 0 deletions
39
...undation/nova/feature_staking_impl/domain/validations/setup/PoolAvailabilityValidation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.novafoundation.nova.feature_staking_impl.domain.validations.setup | ||
|
||
import io.novafoundation.nova.common.validation.Validation | ||
import io.novafoundation.nova.common.validation.ValidationStatus | ||
import io.novafoundation.nova.common.validation.ValidationSystemBuilder | ||
import io.novafoundation.nova.common.validation.valid | ||
import io.novafoundation.nova.common.validation.validationError | ||
import io.novafoundation.nova.feature_staking_impl.data.nominationPools.network.blockhain.models.isOpen | ||
import io.novafoundation.nova.feature_staking_impl.data.nominationPools.repository.NominationPoolGlobalsRepository | ||
import io.novafoundation.nova.feature_staking_impl.domain.nominationPools.model.isActive | ||
import io.novafoundation.nova.feature_staking_impl.domain.nominationPools.selecting.PoolAvailabilityFailure | ||
import io.novafoundation.nova.feature_staking_impl.domain.nominationPools.selecting.PoolAvailabilityPayload | ||
|
||
class PoolAvailabilityValidation( | ||
private val nominationPoolGlobalsRepository: NominationPoolGlobalsRepository | ||
) : Validation<PoolAvailabilityPayload, PoolAvailabilityFailure> { | ||
|
||
override suspend fun validate(value: PoolAvailabilityPayload): ValidationStatus<PoolAvailabilityFailure> { | ||
val pool = value.nominationPool | ||
return when { | ||
!pool.status.isActive || !pool.state.isOpen -> validationError(PoolAvailabilityFailure.PoolIsClosed) | ||
isPoolFull(value) -> validationError(PoolAvailabilityFailure.PoolIsFull) | ||
else -> valid() | ||
} | ||
} | ||
|
||
private suspend fun isPoolFull(value: PoolAvailabilityPayload): Boolean { | ||
val pool = value.nominationPool | ||
val maxPoolMembers = nominationPoolGlobalsRepository.maxPoolMembersPerPool(value.chain.id) | ||
return maxPoolMembers != null && maxPoolMembers <= pool.membersCount | ||
} | ||
} | ||
|
||
fun ValidationSystemBuilder<PoolAvailabilityPayload, PoolAvailabilityFailure>.poolAvailable( | ||
nominationPoolGlobalsRepository: NominationPoolGlobalsRepository | ||
) { | ||
val validation = PoolAvailabilityValidation(nominationPoolGlobalsRepository = nominationPoolGlobalsRepository) | ||
validate(validation) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../nova/feature_staking_impl/presentation/pools/searchPool/SelectPoolValidationFailureUI.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.novafoundation.nova.feature_staking_impl.presentation.pools.searchPool | ||
|
||
import io.novafoundation.nova.common.base.TitleAndMessage | ||
import io.novafoundation.nova.common.resources.ResourceManager | ||
import io.novafoundation.nova.feature_staking_impl.R | ||
import io.novafoundation.nova.feature_staking_impl.domain.nominationPools.selecting.PoolAvailabilityFailure | ||
|
||
fun handleSelectPoolValidationFailure(error: PoolAvailabilityFailure, resourceManager: ResourceManager): TitleAndMessage { | ||
return when (error) { | ||
PoolAvailabilityFailure.PoolIsFull -> TitleAndMessage( | ||
resourceManager.getString(R.string.pool_full_failure_title), | ||
resourceManager.getString(R.string.pool_full_failure_message) | ||
) | ||
|
||
PoolAvailabilityFailure.PoolIsClosed -> TitleAndMessage( | ||
resourceManager.getString(R.string.pool_inactive_failure_title), | ||
resourceManager.getString(R.string.pool_inactive_failure_message) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters