diff --git a/packages/page-democracy/src/Overview/Fasttrack.tsx b/packages/page-democracy/src/Overview/Fasttrack.tsx index 5261faf4b4..158221c153 100644 --- a/packages/page-democracy/src/Overview/Fasttrack.tsx +++ b/packages/page-democracy/src/Overview/Fasttrack.tsx @@ -8,8 +8,8 @@ import BN from 'bn.js'; import React, { useEffect, useMemo, useState } from 'react'; import { getFastTrackThreshold } from '@polkadot/apps-config'; -import { Button, Input, InputAddress, InputNumber, Modal, TxButton } from '@polkadot/react-components'; -import { useApi, useCollectiveInstance, useToggle } from '@polkadot/react-hooks'; +import { Button, Input, InputAddress, InputNumber, Modal, Toggle, TxButton } from '@polkadot/react-components'; +import { useApi, useCall, useCollectiveInstance, useToggle } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; @@ -37,7 +37,9 @@ function Fasttrack ({ imageHash, members, threshold }: Props): React.ReactElemen const [delayBlocks, setDelayBlocks] = useState(DEF_DELAY); const [votingBlocks, setVotingBlocks] = useState(api.consts.democracy.fastTrackVotingPeriod || DEF_VOTING); const [{ proposal, proposalLength }, setProposal] = useState(() => ({ proposalLength: 0 })); + const [withVote, toggleVote] = useToggle(true); const modLocation = useCollectiveInstance('technicalCommittee'); + const proposalCount = useCall(modLocation && api.query[modLocation].proposalCount); const memberThreshold = useMemo( () => new BN( @@ -48,6 +50,27 @@ function Fasttrack ({ imageHash, members, threshold }: Props): React.ReactElemen [api, members, votingBlocks] ); + const extrinsic = useMemo( + (): SubmittableExtrinsic<'promise'> | null => { + if (!modLocation || !proposal || !proposalCount) { + return null; + } + + const proposeTx = api.tx[modLocation].propose.meta.args.length === 3 + ? api.tx[modLocation].propose(memberThreshold, proposal, proposalLength) + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore Old-type + : api.tx[modLocation].propose(memberThreshold, proposal); + + return withVote + ? api.tx.utility.batch([ + proposeTx, + api.tx[modLocation].vote(proposal.method.hash, proposalCount, true) + ]) + : proposeTx; + }, [api, memberThreshold, modLocation, proposal, proposalCount, proposalLength, withVote] + ); + useEffect((): void => { const proposal = delayBlocks && !delayBlocks.isZero() && votingBlocks && !votingBlocks.isZero() ? api.tx.democracy.fastTrack(imageHash, votingBlocks, delayBlocks) @@ -69,57 +92,63 @@ function Fasttrack ({ imageHash, members, threshold }: Props): React.ReactElemen ('Fast track proposal')} onClose={toggleFasttrack} - size='small' + size='large' > - ('Select the account you wish to make the proposal with.')} - label={t('propose from account')} - onChange={setAcountId} - type='account' - withLabel - /> - ('The external proposal to send to the technical committee')} - isDisabled - label={t('preimage hash')} - value={imageHash.toHex()} - /> - ('The voting period to apply in blocks')} - isZeroable={false} - label={t('voting period')} - onChange={setVotingBlocks} - value={votingBlocks} - /> - ('The delay period to apply in blocks')} - isZeroable={false} - label={t('delay')} - onChange={setDelayBlocks} - value={delayBlocks} - /> - ('threshold')} - /> + ('Select the committee account you wish to make the proposal with.')}> + ('propose from account')} + onChange={setAcountId} + type='account' + withLabel + /> + + ('The external proposal to send to the technical committee')}> + ('preimage hash')} + value={imageHash.toHex()} + /> + + ('The voting period and delay to apply to this proposal. The threshold is calculated from these values.')}> + ('The voting period to apply in blocks')} + isZeroable={false} + label={t('voting period')} + onChange={setVotingBlocks} + value={votingBlocks} + /> + ('The delay period to apply in blocks')} + isZeroable={false} + label={t('delay')} + onChange={setDelayBlocks} + value={delayBlocks} + /> + ('threshold')} + /> + + ('Submit an Aye vote alongside the proposal as part of a batch')}> + ('Submit Aye vote with proposal')} + onChange={toggleVote} + value={withVote} + /> + ('Fast track')} onStart={toggleFasttrack} - params={ - api.tx[modLocation].propose.meta.args.length === 3 - ? [memberThreshold, proposal, proposalLength] - : [memberThreshold, proposal] - } - tx={api.tx[modLocation].propose} />