mirror of
https://github.com/pezkuwichain/pezkuwi-wallet-android.git
synced 2026-04-21 22:38:01 +00:00
fix: governance voting and default chain selection for Pezkuwi
Add pezpallet_* type paths to SiVoteTypeMapping so ConvictionVoting vote encoding works on Pezkuwi chains. Set Pezkuwi relay as preferred default chain for governance and crowdloan screens.
This commit is contained in:
+3
-1
@@ -8,6 +8,7 @@ import io.novafoundation.nova.runtime.state.NothingAdditional
|
||||
import io.novafoundation.nova.runtime.state.uniqueOption
|
||||
|
||||
private const val CROWDLOAN_SHARED_STATE = "CROWDLOAN_SHARED_STATE"
|
||||
private const val PEZKUWI_RELAY_CHAIN_ID = "1aa94987791a5544e9667ec249d2cef1b8fdd6083c85b93fc37892d54a1156ca"
|
||||
|
||||
class CrowdloanSharedState(
|
||||
chainRegistry: ChainRegistry,
|
||||
@@ -16,5 +17,6 @@ class CrowdloanSharedState(
|
||||
preferences = preferences,
|
||||
chainRegistry = chainRegistry,
|
||||
supportedOptions = uniqueOption { chain, chainAsset -> chain.hasCrowdloans and chainAsset.isUtilityAsset },
|
||||
preferencesKey = CROWDLOAN_SHARED_STATE
|
||||
preferencesKey = CROWDLOAN_SHARED_STATE,
|
||||
preferredChainId = PEZKUWI_RELAY_CHAIN_ID
|
||||
)
|
||||
|
||||
+3
-1
@@ -12,6 +12,7 @@ import io.novafoundation.nova.runtime.multiNetwork.chain.model.ChainId
|
||||
import io.novafoundation.nova.runtime.state.SelectableSingleAssetSharedState
|
||||
|
||||
private const val GOVERNANCE_SHARED_STATE = "GOVERNANCE_SHARED_STATE"
|
||||
private const val PEZKUWI_RELAY_CHAIN_ID = "1aa94987791a5544e9667ec249d2cef1b8fdd6083c85b93fc37892d54a1156ca"
|
||||
|
||||
class GovernanceSharedState(
|
||||
chainRegistry: ChainRegistry,
|
||||
@@ -27,7 +28,8 @@ class GovernanceSharedState(
|
||||
emptyList()
|
||||
}
|
||||
},
|
||||
preferencesKey = GOVERNANCE_SHARED_STATE
|
||||
preferencesKey = GOVERNANCE_SHARED_STATE,
|
||||
preferredChainId = PEZKUWI_RELAY_CHAIN_ID
|
||||
),
|
||||
MutableGovernanceState {
|
||||
|
||||
|
||||
+3
-1
@@ -7,6 +7,8 @@ fun SiVoteTypeMapping(): ReplaceTypesSiTypeMapping {
|
||||
|
||||
return ReplaceTypesSiTypeMapping(
|
||||
"pallet_democracy.vote.Vote" to voteType,
|
||||
"pallet_conviction_voting.vote.Vote" to voteType
|
||||
"pallet_conviction_voting.vote.Vote" to voteType,
|
||||
"pezpallet_democracy.vote.Vote" to voteType,
|
||||
"pezpallet_conviction_voting.vote.Vote" to voteType
|
||||
)
|
||||
}
|
||||
|
||||
+14
-4
@@ -32,13 +32,17 @@ abstract class SelectableSingleAssetSharedState<A : SelectableAssetAdditionalDat
|
||||
private val preferencesKey: String,
|
||||
private val chainRegistry: ChainRegistry,
|
||||
private val supportedOptions: SupportedOptionsResolver<A>,
|
||||
private val preferences: Preferences
|
||||
private val preferences: Preferences,
|
||||
private val preferredChainId: ChainId? = null
|
||||
) : SelectedAssetOptionSharedState<A> {
|
||||
|
||||
override val selectedOption: Flow<SupportedAssetOption<A>> = preferences.stringFlow(
|
||||
field = preferencesKey,
|
||||
initialValueProducer = {
|
||||
val option = availableToSelect().first()
|
||||
val options = availableToSelect()
|
||||
val option = preferredChainId?.let { preferred ->
|
||||
options.firstOrNull { it.assetWithChain.chain.id == preferred }
|
||||
} ?: options.first()
|
||||
val chainAsset = option.assetWithChain.asset
|
||||
val additional = option.additional
|
||||
|
||||
@@ -74,6 +78,12 @@ abstract class SelectableSingleAssetSharedState<A : SelectableAssetAdditionalDat
|
||||
preferences.putString(preferencesKey, encode(chainId, chainAssetId, optionIdentifier))
|
||||
}
|
||||
|
||||
private suspend fun preferredOrFirst(options: List<SupportedAssetOption<A>>): SupportedAssetOption<A> {
|
||||
return preferredChainId?.let { preferred ->
|
||||
options.firstOrNull { it.assetWithChain.chain.id == preferred }
|
||||
} ?: options.first()
|
||||
}
|
||||
|
||||
private suspend fun getChainWithAssetOrFallback(chainId: ChainId, chainAssetId: Int, additionalIdentifier: String?): SupportedAssetOption<A> {
|
||||
val optionalChainAndAsset = chainRegistry.enabledChainWithAssetOrNull(chainId, chainAssetId)
|
||||
val supportedOptions = optionalChainAndAsset?.let {
|
||||
@@ -82,10 +92,10 @@ abstract class SelectableSingleAssetSharedState<A : SelectableAssetAdditionalDat
|
||||
|
||||
return when {
|
||||
// previously used chain asset was removed -> fallback to default
|
||||
optionalChainAndAsset == null -> availableToSelect().first()
|
||||
optionalChainAndAsset == null -> preferredOrFirst(availableToSelect())
|
||||
|
||||
// previously supported option is no longer supported -> fallback to default
|
||||
supportedOptions.isEmpty() -> availableToSelect().first()
|
||||
supportedOptions.isEmpty() -> preferredOrFirst(availableToSelect())
|
||||
|
||||
// there is no particular additional option specified -> select first one
|
||||
additionalIdentifier == null -> SupportedAssetOption(optionalChainAndAsset, additional = supportedOptions.first())
|
||||
|
||||
Reference in New Issue
Block a user