Allow specification of tc fasttrack threshold (#5370)
* Allow specification of members threshold * Adjust * Auto-calc threshold
This commit is contained in:
parent
89fbcabba5
commit
28e8474013
@ -11,7 +11,8 @@ export default function create (t: TFunction): Route {
|
||||
Component,
|
||||
display: {
|
||||
needsApi: [
|
||||
'tx.assets.setMetadata'
|
||||
'tx.assets.setMetadata',
|
||||
'tx.assets.transferKeepAlive'
|
||||
]
|
||||
},
|
||||
group: 'network',
|
||||
|
||||
@ -6,6 +6,7 @@ import type { DeriveProposalExternal } from '@polkadot/api-derive/types';
|
||||
import React from 'react';
|
||||
|
||||
import { AddressMini, Button } from '@polkadot/react-components';
|
||||
import { useMembers } from '@polkadot/react-hooks';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
|
||||
import Fasttrack from './Fasttrack';
|
||||
@ -18,6 +19,8 @@ interface Props {
|
||||
}
|
||||
|
||||
function External ({ className = '', value: { image, imageHash, threshold } }: Props): React.ReactElement<Props> | null {
|
||||
const { isMember, members } = useMembers('technicalCommittee');
|
||||
|
||||
return (
|
||||
<tr className={className}>
|
||||
<ProposalCell
|
||||
@ -37,9 +40,10 @@ function External ({ className = '', value: { image, imageHash, threshold } }: P
|
||||
{!image?.proposal && (
|
||||
<PreImageButton imageHash={imageHash} />
|
||||
)}
|
||||
{threshold && (
|
||||
{threshold && isMember && (
|
||||
<Fasttrack
|
||||
imageHash={imageHash}
|
||||
members={members}
|
||||
threshold={threshold}
|
||||
/>
|
||||
)}
|
||||
|
||||
@ -8,12 +8,13 @@ import BN from 'bn.js';
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { Button, Input, InputAddress, InputNumber, Modal, TxButton } from '@polkadot/react-components';
|
||||
import { useApi, useMembers, useToggle } from '@polkadot/react-hooks';
|
||||
import { useApi, useToggle } from '@polkadot/react-hooks';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
|
||||
interface Props {
|
||||
imageHash: Hash;
|
||||
members: string[];
|
||||
threshold: VoteThreshold;
|
||||
}
|
||||
|
||||
@ -26,32 +27,34 @@ const ONE_MIN = (1 * 60) / 6;
|
||||
const DEF_DELAY = new BN(ONE_MIN);
|
||||
const DEF_VOTING = new BN(ONE_MIN * 60 * 3);
|
||||
|
||||
function Fasttrack ({ imageHash, threshold }: Props): React.ReactElement<Props> | null {
|
||||
function Fasttrack ({ imageHash, members, threshold }: Props): React.ReactElement<Props> | null {
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const { isMember, members } = useMembers('technicalCommittee');
|
||||
const [isFasttrackOpen, toggleFasttrack] = useToggle();
|
||||
const [allowFast, setAllowFast] = useState(false);
|
||||
const [accountId, setAcountId] = useState<string | null>(null);
|
||||
const [delayBlocks, setDelayBlocks] = useState<BN | undefined>(DEF_DELAY);
|
||||
const [votingBlocks, setVotingBlocks] = useState<BN | undefined>(DEF_VOTING);
|
||||
const [{ proposal, proposalLength }, setProposal] = useState<ProposalState>({ proposalLength: 0 });
|
||||
const [votingBlocks, setVotingBlocks] = useState<BN | undefined>(api.consts.democracy.fastTrackVotingPeriod || DEF_VOTING);
|
||||
const [{ proposal, proposalLength }, setProposal] = useState<ProposalState>(() => ({ proposalLength: 0 }));
|
||||
|
||||
const memberThreshold = useMemo(
|
||||
() => Math.ceil(members.length * 0.66),
|
||||
[members]
|
||||
() => new BN(
|
||||
!votingBlocks || api.consts.democracy.fastTrackVotingPeriod.lte(votingBlocks)
|
||||
? Math.ceil(members.length * 0.66)
|
||||
: members.length
|
||||
),
|
||||
[api, members, votingBlocks]
|
||||
);
|
||||
|
||||
useEffect((): void => {
|
||||
setAllowFast(isMember && threshold.isSimplemajority);
|
||||
}, [isMember, threshold]);
|
||||
|
||||
useEffect((): void => {
|
||||
const proposal = delayBlocks && delayBlocks.gtn(0) && votingBlocks && votingBlocks.gtn(0)
|
||||
const proposal = delayBlocks && !delayBlocks.isZero() && votingBlocks && !votingBlocks.isZero()
|
||||
? api.tx.democracy.fastTrack(imageHash, votingBlocks, delayBlocks)
|
||||
: null;
|
||||
|
||||
setProposal({ proposal, proposalLength: proposal?.length || 0 });
|
||||
}, [api, delayBlocks, imageHash, votingBlocks]);
|
||||
setProposal({
|
||||
proposal,
|
||||
proposalLength: proposal?.length || 0
|
||||
});
|
||||
}, [api, delayBlocks, imageHash, members, votingBlocks]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -78,22 +81,29 @@ function Fasttrack ({ imageHash, threshold }: Props): React.ReactElement<Props>
|
||||
<InputNumber
|
||||
autoFocus
|
||||
help={t<string>('The voting period to apply in blocks')}
|
||||
isZeroable={false}
|
||||
label={t<string>('voting period')}
|
||||
onChange={setVotingBlocks}
|
||||
value={votingBlocks}
|
||||
/>
|
||||
<InputNumber
|
||||
help={t<string>('The delay period to apply in blocks')}
|
||||
isZeroable={false}
|
||||
label={t<string>('delay')}
|
||||
onChange={setDelayBlocks}
|
||||
value={delayBlocks}
|
||||
/>
|
||||
<InputNumber
|
||||
defaultValue={memberThreshold}
|
||||
isDisabled
|
||||
label={t<string>('threshold')}
|
||||
/>
|
||||
</Modal.Content>
|
||||
<Modal.Actions onCancel={toggleFasttrack}>
|
||||
<TxButton
|
||||
accountId={accountId}
|
||||
icon='fast-forward'
|
||||
isDisabled={!accountId || !proposal || !memberThreshold}
|
||||
isDisabled={!accountId || !proposal}
|
||||
label={t<string>('Fast track')}
|
||||
onStart={toggleFasttrack}
|
||||
params={
|
||||
@ -108,7 +118,7 @@ function Fasttrack ({ imageHash, threshold }: Props): React.ReactElement<Props>
|
||||
)}
|
||||
<Button
|
||||
icon='fast-forward'
|
||||
isDisabled={!allowFast}
|
||||
isDisabled={!threshold.isSimplemajority}
|
||||
label={t<string>('Fast track')}
|
||||
onClick={toggleFasttrack}
|
||||
/>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user