-
Notifications
You must be signed in to change notification settings - Fork 70
/
useProposalConstants.ts
65 lines (55 loc) · 3.2 KB
/
useProposalConstants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { u128, u32 } from '@polkadot/types'
import { PalletProposalsEngineProposalParameters } from '@polkadot/types/lookup'
import { useMemo } from 'react'
import { Api } from '@/api'
import { useApi } from '@/api/hooks/useApi'
import { asProposalConstants, ProposalConstants } from '@/proposals/types/constants'
import { ProposalType } from '../types'
export const useProposalConstants = (proposalType?: ProposalType): ProposalConstants | null => {
const { api, isConnected } = useApi()
return useMemo(() => proposalConstants(api, proposalType), [proposalType, isConnected])
}
export const proposalConstants = (api?: Pick<Api, 'consts'>, proposalType?: ProposalType) => {
if (!proposalType) {
return null
}
const constantKey = proposalTypeToConstantKey.get(proposalType)
if (!constantKey) {
return null
}
const constants = api?.consts.proposalsCodex[constantKey]
return constants && extendsProposalPallet(constants) ? asProposalConstants(constants) : null
}
const extendsProposalPallet = (
proposalType: PalletProposalsEngineProposalParameters | u32 | u128
): proposalType is PalletProposalsEngineProposalParameters =>
!(proposalType instanceof u128 || proposalType instanceof u32)
const proposalTypeToConstantKey = new Map<ProposalType, keyof Api['consts']['proposalsCodex']>([
['updateChannelPayouts', 'updateChannelPayoutsProposalParameters'],
['updatePalletFrozenStatus', 'setPalletFozenStatusProposalParameters'],
['amendConstitution', 'amendConstitutionProposalParameters'],
['cancelWorkingGroupLeadOpening', 'cancelWorkingGroupLeadOpeningProposalParameters'],
['createWorkingGroupLeadOpening', 'createWorkingGroupLeadOpeningProposalParameters'],
['decreaseWorkingGroupLeadStake', 'decreaseWorkingGroupLeadStakeProposalParameters'],
['fillWorkingGroupLeadOpening', 'fillWorkingGroupOpeningProposalParameters'],
['fundingRequest', 'fundingRequestProposalParameters'],
['runtimeUpgrade', 'runtimeUpgradeProposalParameters'],
['setCouncilBudgetIncrement', 'setCouncilBudgetIncrementProposalParameters'],
['setCouncilorReward', 'setCouncilorRewardProposalParameters'],
['setInitialInvitationBalance', 'setInitialInvitationBalanceProposalParameters'],
['setInitialInvitationCount', 'setInvitationCountProposalParameters'],
['setMaxValidatorCount', 'setMaxValidatorCountProposalParameters'],
['setMembershipLeadInvitationQuota', 'setMembershipLeadInvitationQuotaProposalParameters'],
['setMembershipPrice', 'setMembershipPriceProposalParameters'],
['setReferralCut', 'setReferralCutProposalParameters'],
['setWorkingGroupLeadReward', 'setWorkingGroupLeadRewardProposalParameters'],
['signal', 'signalProposalParameters'],
['slashWorkingGroupLead', 'slashWorkingGroupLeadProposalParameters'],
['terminateWorkingGroupLead', 'terminateWorkingGroupLeadProposalParameters'],
['updateWorkingGroupBudget', 'updateWorkingGroupBudgetProposalParameters'],
['veto', 'vetoProposalProposalParameters'],
['setEraPayoutDampingFactor', 'setEraPayoutDampingFactorProposalParameters'],
['decreaseCouncilBudget', 'decreaseCouncilBudgetProposalParameters'],
['updateTokenPalletTokenConstraints', 'updateTokenPalletTokenConstraints'],
['updateArgoBridgeConstraints', 'updateArgoBridgeConstraints'],
])