From 2be66d6a81822596562952dcc77bbce4cde21587 Mon Sep 17 00:00:00 2001 From: Jaco Date: Tue, 14 Sep 2021 12:50:33 +0300 Subject: [PATCH] Allow collective close from any account (#6120) --- packages/page-council/src/Motions/Close.tsx | 6 +-- packages/page-council/src/Motions/Motion.tsx | 48 +++-------------- .../page-tech-comm/src/Proposals/Close.tsx | 6 +-- .../page-tech-comm/src/Proposals/Proposal.tsx | 52 ++++--------------- 4 files changed, 22 insertions(+), 90 deletions(-) diff --git a/packages/page-council/src/Motions/Close.tsx b/packages/page-council/src/Motions/Close.tsx index e7751e597c..6374be577a 100644 --- a/packages/page-council/src/Motions/Close.tsx +++ b/packages/page-council/src/Motions/Close.tsx @@ -14,11 +14,10 @@ interface Props { hasFailed: boolean; hash: Hash; idNumber: ProposalIndex; - members: string[]; proposal: Proposal; } -function Close ({ hasFailed, hash, idNumber, members, proposal }: Props): React.ReactElement | null { +function Close ({ hasFailed, hash, idNumber, proposal }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); const [isOpen, toggleOpen] = useToggle(); @@ -48,9 +47,8 @@ function Close ({ hasFailed, hash, idNumber, members, proposal }: Props): React. ('The council account that will apply the close for the current round.')}> ('Select the account you wish close the proposal with.')} - label={t('sending account')} + label={t('close from account')} onChange={setAccountId} type='account' /> diff --git a/packages/page-council/src/Motions/Motion.tsx b/packages/page-council/src/Motions/Motion.tsx index dbe21d6ebf..43b03f6fd5 100644 --- a/packages/page-council/src/Motions/Motion.tsx +++ b/packages/page-council/src/Motions/Motion.tsx @@ -7,12 +7,11 @@ import type { AccountId } from '@polkadot/types/interfaces'; import React, { useMemo } from 'react'; import ProposalCell from '@polkadot/app-democracy/Overview/ProposalCell'; -import { Icon, LinkExternal, TxButton } from '@polkadot/react-components'; -import { useAccounts, useApi, useCollectiveInstance, useVotingStatus, useWeight } from '@polkadot/react-hooks'; +import { Icon, LinkExternal } from '@polkadot/react-components'; +import { useAccounts, useCollectiveInstance, useVotingStatus } from '@polkadot/react-hooks'; import { BlockToTime } from '@polkadot/react-query'; import { formatNumber } from '@polkadot/util'; -import { useTranslation } from '../translate'; import Close from './Close'; import Voters from './Voters'; import Voting from './Voting'; @@ -31,22 +30,10 @@ interface VoterState { } function Motion ({ className = '', isMember, members, motion: { hash, proposal, votes }, prime }: Props): React.ReactElement | null { - const { t } = useTranslation(); - const { api } = useApi(); const { allAccounts } = useAccounts(); const { hasFailed, isCloseable, isVoteable, remainingBlocks } = useVotingStatus(votes, members.length, 'council'); - const [proposalWeight, proposalLength] = useWeight(proposal); const modLocation = useCollectiveInstance('council'); - const [councilId, isMultiMembers] = useMemo( - (): [string | null, boolean] => { - const councilIds = allAccounts.filter((accountId) => members.includes(accountId)); - - return [councilIds[0] || null, councilIds.length > 1]; - }, - [allAccounts, members] - ); - const { hasVoted, hasVotedAye } = useMemo( (): VoterState => { if (votes) { @@ -112,31 +99,12 @@ function Motion ({ className = '', isMember, members, motion: { hash, proposal, /> )} {isCloseable && ( - isMultiMembers - ? ( - - ) - : ( - ('Close')} - params={ - api.tx[modLocation].close?.meta.args.length === 4 - ? hasFailed - ? [hash, index, 0, 0] - : [hash, index, proposalWeight, proposalLength] - : [hash, index] - } - tx={api.tx[modLocation].closeOperational || api.tx[modLocation].close} - /> - ) + )} diff --git a/packages/page-tech-comm/src/Proposals/Close.tsx b/packages/page-tech-comm/src/Proposals/Close.tsx index 023c8ffc09..819662bd63 100644 --- a/packages/page-tech-comm/src/Proposals/Close.tsx +++ b/packages/page-tech-comm/src/Proposals/Close.tsx @@ -14,12 +14,11 @@ interface Props { hasFailed: boolean; hash: Hash; idNumber: ProposalIndex; - members: string[]; proposal: Proposal; type: 'membership' | 'technicalCommittee'; } -function Close ({ hasFailed, hash, idNumber, members, proposal, type }: Props): React.ReactElement | null { +function Close ({ hasFailed, hash, idNumber, proposal, type }: Props): React.ReactElement | null { const { t } = useTranslation(); const { api } = useApi(); const [isOpen, toggleOpen] = useToggle(); @@ -48,9 +47,8 @@ function Close ({ hasFailed, hash, idNumber, members, proposal, type }: Props): ('The committee account that will apply the close for the current round.')}> ('Select the account you wish close the proposal with.')} - label={t('sending account')} + label={t('close from account')} onChange={setAccountId} type='account' /> diff --git a/packages/page-tech-comm/src/Proposals/Proposal.tsx b/packages/page-tech-comm/src/Proposals/Proposal.tsx index fb64632500..82e974650b 100644 --- a/packages/page-tech-comm/src/Proposals/Proposal.tsx +++ b/packages/page-tech-comm/src/Proposals/Proposal.tsx @@ -4,15 +4,14 @@ import type { DeriveCollectiveProposal } from '@polkadot/api-derive/types'; import type { AccountId, Hash } from '@polkadot/types/interfaces'; -import React, { useMemo } from 'react'; +import React from 'react'; import ProposalCell from '@polkadot/app-democracy/Overview/ProposalCell'; -import { AddressMini, TxButton } from '@polkadot/react-components'; -import { useAccounts, useApi, useCall, useCollectiveInstance, useVotingStatus, useWeight } from '@polkadot/react-hooks'; +import { AddressMini } from '@polkadot/react-components'; +import { useApi, useCall, useCollectiveInstance, useVotingStatus } from '@polkadot/react-hooks'; import { BlockToTime } from '@polkadot/react-query'; import { formatNumber } from '@polkadot/util'; -import { useTranslation } from '../translate'; import Close from './Close'; import Voting from './Voting'; @@ -26,23 +25,11 @@ interface Props { } function Proposal ({ className = '', imageHash, members, prime, type }: Props): React.ReactElement | null { - const { t } = useTranslation(); const { api } = useApi(); - const { allAccounts } = useAccounts(); const derive = useCall(api.derive[type].proposal, [imageHash]); const { hasFailed, isCloseable, isVoteable, remainingBlocks } = useVotingStatus(derive?.votes, members.length, type); - const [proposalWeight, proposalLength] = useWeight(derive?.proposal); const modLocation = useCollectiveInstance(type); - const [councilId, isMultiMembers] = useMemo( - (): [string | null, boolean] => { - const councilIds = allAccounts.filter((accountId) => members.includes(accountId)); - - return [councilIds[0] || null, councilIds.length > 1]; - }, - [allAccounts, members] - ); - if (!modLocation || !derive || !derive.votes) { return null; } @@ -96,32 +83,13 @@ function Proposal ({ className = '', imageHash, members, prime, type }: Props): /> )} {isCloseable && ( - isMultiMembers - ? ( - - ) - : ( - ('Close')} - params={ - api.tx[modLocation].close?.meta.args.length === 4 - ? hasFailed - ? [imageHash, index, 0, 0] - : [imageHash, index, proposalWeight, proposalLength] - : [imageHash, index] - } - tx={api.tx[modLocation].closeOperational || api.tx[modLocation].close} - /> - ) + )}