diff --git a/packages/page-democracy/src/Overview/DispatchEntry.tsx b/packages/page-democracy/src/Overview/DispatchEntry.tsx index 2ebf256acf..611cade2f4 100644 --- a/packages/page-democracy/src/Overview/DispatchEntry.tsx +++ b/packages/page-democracy/src/Overview/DispatchEntry.tsx @@ -52,11 +52,12 @@ function DispatchEntry ({ blockNumber, hash, referendumIndex }: Props): React.Re proposal={proposal} /> - + {!proposal && ( + + )} | null { const { t } = useTranslation(); const { api } = useApi(); const external = useCall>>(api.query.democracy.nextExternal, []); - const [hash, setHash] = useState(null); + const [[hash, threshold], setInfo] = useState<[Hash | null, VoteThreshold | null]>([null, null]); const [expanded, setExpanded] = useState<{ at: BlockNumber; balance: Balance; proposer: AccountId; proposal: Proposal } | null>(null); const preimage = useCall>>(api.query.democracy.preimages, [hash]); useEffect((): void => { - setHash( - external?.isSome - ? external.unwrap()[0] - : null + setInfo( + external + ? external.unwrapOr([null, null]) + : [null, null] ); }, [external]); @@ -72,11 +73,21 @@ function Externals ({ className }: Props): React.ReactElement | null { proposal={expanded?.proposal} /> - + {!expanded?.proposal && ( + <> + + + + )} + {hash && threshold && ( + + )} diff --git a/packages/page-democracy/src/Overview/Fasttrack.tsx b/packages/page-democracy/src/Overview/Fasttrack.tsx new file mode 100644 index 0000000000..2b64c1c20d --- /dev/null +++ b/packages/page-democracy/src/Overview/Fasttrack.tsx @@ -0,0 +1,111 @@ +// Copyright 2017-2020 @polkadot/app-democracy authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { SubmittableExtrinsic } from '@polkadot/api/types'; +import { Hash, VoteThreshold } from '@polkadot/types/interfaces'; + +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 { useTranslation } from '../translate'; + +interface Props { + hash: Hash; + threshold: VoteThreshold; +} + +const ONE_MIN = (1 * 60) / 6; +const DEF_DELAY = new BN(ONE_MIN); +const DEF_VOTING = new BN(ONE_MIN * 60 * 3); + +function Fasttrack ({ hash, threshold }: Props): React.ReactElement | 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(null); + const [delayBlocks, setDelayBlocks] = useState(DEF_DELAY); + const [votingBlocks, setVotingBlocks] = useState(DEF_VOTING); + const [proposal, setProposal] = useState | null>(null); + const memberThreshold = useMemo( + () => Math.ceil(members.length * 0.5), + [members] + ); + + useEffect((): void => { + setAllowFast(isMember && threshold.isSimplemajority); + }, [isMember, threshold]); + + useEffect((): void => { + setProposal( + () => delayBlocks?.gtn(0) && votingBlocks?.gtn(0) + ? api.tx.democracy.fastTrack(hash, votingBlocks, delayBlocks) + : null + ); + }, [delayBlocks, hash, votingBlocks]); + + return ( + <> + {isFasttrackOpen && ( + + + + + + + + + + + + )} +