From 0789371b712b00321be0ea9765f79c6bf2164f28 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 28 May 2020 08:54:01 +0200 Subject: [PATCH] Re-add tc with length & weights (#2840) * Re-add tc with length & weights * Apply fixes * Move useVotingstatus --- packages/page-council/src/Motions/Motion.tsx | 4 +- .../page-democracy/src/Overview/Fasttrack.tsx | 23 +++-- .../page-tech-comm/src/Proposals/Close.tsx | 95 +++++++++++++++++++ .../page-tech-comm/src/Proposals/Proposal.tsx | 51 +++++++--- .../page-tech-comm/src/Proposals/Propose.tsx | 20 +++- .../page-tech-comm/src/Proposals/Voting.tsx | 4 +- .../page-tech-comm/src/Proposals/index.tsx | 4 +- packages/react-hooks/src/index.ts | 1 + .../src}/useVotingStatus.ts | 16 ++-- 9 files changed, 182 insertions(+), 36 deletions(-) create mode 100644 packages/page-tech-comm/src/Proposals/Close.tsx rename packages/{page-council/src/Motions => react-hooks/src}/useVotingStatus.ts (70%) diff --git a/packages/page-council/src/Motions/Motion.tsx b/packages/page-council/src/Motions/Motion.tsx index 92d40322d9..56e2ad78c1 100644 --- a/packages/page-council/src/Motions/Motion.tsx +++ b/packages/page-council/src/Motions/Motion.tsx @@ -8,13 +8,13 @@ import { DeriveCollectiveProposal } from '@polkadot/api-derive/types'; import React from 'react'; import ProposalCell from '@polkadot/app-democracy/Overview/ProposalCell'; import { LinkExternal } from '@polkadot/react-components'; +import { useVotingStatus } from '@polkadot/react-hooks'; import { BlockToTime } from '@polkadot/react-query'; import { formatNumber } from '@polkadot/util'; import Close from './Close'; import Voters from './Votes'; import Voting from './Voting'; -import useVotingStatus from './useVotingStatus'; interface Props { className?: string; @@ -25,7 +25,7 @@ interface Props { } function Motion ({ className = '', isMember, members, motion: { hash, proposal, votes }, prime }: Props): React.ReactElement | null { - const { isCloseable, isVoteable, remainingBlocks } = useVotingStatus(votes, members.length); + const { isCloseable, isVoteable, remainingBlocks } = useVotingStatus(votes, members.length, 'council'); if (!votes) { return null; diff --git a/packages/page-democracy/src/Overview/Fasttrack.tsx b/packages/page-democracy/src/Overview/Fasttrack.tsx index 59fb5b7566..5f13bfccbb 100644 --- a/packages/page-democracy/src/Overview/Fasttrack.tsx +++ b/packages/page-democracy/src/Overview/Fasttrack.tsx @@ -17,6 +17,11 @@ interface Props { threshold: VoteThreshold; } +interface ProposalState { + proposal?: SubmittableExtrinsic<'promise'> | null; + proposalLength: number; +} + const ONE_MIN = (1 * 60) / 6; const DEF_DELAY = new BN(ONE_MIN); const DEF_VOTING = new BN(ONE_MIN * 60 * 3); @@ -30,7 +35,7 @@ function Fasttrack ({ imageHash, threshold }: Props): React.ReactElement const [accountId, setAcountId] = useState(null); const [delayBlocks, setDelayBlocks] = useState(DEF_DELAY); const [votingBlocks, setVotingBlocks] = useState(DEF_VOTING); - const [proposal, setProposal] = useState | null>(null); + const [{ proposal, proposalLength }, setProposal] = useState({ proposalLength: 0 }); const memberThreshold = useMemo( () => Math.ceil(members.length * 0.5), [members] @@ -41,11 +46,11 @@ function Fasttrack ({ imageHash, threshold }: Props): React.ReactElement }, [isMember, threshold]); useEffect((): void => { - setProposal( - () => delayBlocks && delayBlocks.gtn(0) && votingBlocks && votingBlocks.gtn(0) - ? api.tx.democracy.fastTrack(imageHash, votingBlocks, delayBlocks) - : null - ); + const proposal = delayBlocks && delayBlocks.gtn(0) && votingBlocks && votingBlocks.gtn(0) + ? api.tx.democracy.fastTrack(imageHash, votingBlocks, delayBlocks) + : null; + + setProposal({ proposal, proposalLength: proposal?.length || 0 }); }, [api, delayBlocks, imageHash, votingBlocks]); return ( @@ -92,7 +97,11 @@ function Fasttrack ({ imageHash, threshold }: Props): React.ReactElement isPrimary label={t('Fast track')} onStart={toggleFasttrack} - params={[memberThreshold, proposal]} + params={ + api.tx.technicalCommittee.propose.meta.args.length === 3 + ? [threshold, proposal, proposalLength] + : [memberThreshold, proposal] + } tx='technicalCommittee.propose' /> diff --git a/packages/page-tech-comm/src/Proposals/Close.tsx b/packages/page-tech-comm/src/Proposals/Close.tsx new file mode 100644 index 0000000000..6d2f7a9fd5 --- /dev/null +++ b/packages/page-tech-comm/src/Proposals/Close.tsx @@ -0,0 +1,95 @@ +// Copyright 2017-2020 @polkadot/app-tech-comm 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 { Hash, Proposal, ProposalIndex, Weight } from '@polkadot/types/interfaces'; + +import React, { useEffect, useState } from 'react'; +import { Button, InputAddress, Modal, ProposedAction, TxButton } from '@polkadot/react-components'; +import { useAccounts, useApi, useToggle } from '@polkadot/react-hooks'; + +import { useTranslation } from '../translate'; + +interface Props { + hash: Hash; + idNumber: ProposalIndex; + isDisabled: boolean; + members: string[]; + proposal: Proposal; +} + +function Close ({ hash, idNumber, isDisabled, members, proposal }: Props): React.ReactElement | null { + const { t } = useTranslation(); + const { api } = useApi(); + const { allAccounts } = useAccounts(); + const [isOpen, toggleOpen] = useToggle(); + const [accountId, setAccountId] = useState(null); + const [proposalLength] = useState(proposal.encodedLength); + const [proposalWeight, setProposalWeight] = useState(null); + + useEffect((): void => { + allAccounts.length && (async () => setProposalWeight( + (await api.tx(proposal).paymentInfo(allAccounts[0])).weight + ))().catch(console.error); + }, [api, allAccounts, proposal]); + + return ( + <> + {isOpen && ( + ('Close proposal')} + size='large' + > + + + + + + +

{t('The proposal that will be affected. Once closed for the current voting round, it would need to be re-submitted for a subsequent voting round.')}

+
+
+ + + ('Select the account you wish close the proposal with.')} + label={t('sending account')} + onChange={setAccountId} + type='account' + /> + + +

{t('The committee account that will apply the close for the current round.')}

+
+
+
+ + + +
+ )} +