Allow collective close from any account (#6120)

This commit is contained in:
Jaco 2021-09-14 12:50:33 +03:00 committed by GitHub
parent d1bc9843db
commit 2be66d6a81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 90 deletions

View File

@ -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<Props> | null {
function Close ({ hasFailed, hash, idNumber, proposal }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const [isOpen, toggleOpen] = useToggle();
@ -48,9 +47,8 @@ function Close ({ hasFailed, hash, idNumber, members, proposal }: Props): React.
</Modal.Columns>
<Modal.Columns hint={t<string>('The council account that will apply the close for the current round.')}>
<InputAddress
filter={members}
help={t<string>('Select the account you wish close the proposal with.')}
label={t<string>('sending account')}
label={t<string>('close from account')}
onChange={setAccountId}
type='account'
/>

View File

@ -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<Props> | 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
hasFailed={hasFailed}
hash={hash}
idNumber={index}
members={members}
proposal={proposal}
/>
)
: (
<TxButton
accountId={councilId}
icon='times'
label={t<string>('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}
/>
)
<Close
hasFailed={hasFailed}
hash={hash}
idNumber={index}
proposal={proposal}
/>
)}
</td>
<td className='badge'>

View File

@ -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<Props> | null {
function Close ({ hasFailed, hash, idNumber, proposal, type }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const [isOpen, toggleOpen] = useToggle();
@ -48,9 +47,8 @@ function Close ({ hasFailed, hash, idNumber, members, proposal, type }: Props):
</Modal.Columns>
<Modal.Columns hint={t<string>('The committee account that will apply the close for the current round.')}>
<InputAddress
filter={members}
help={t<string>('Select the account you wish close the proposal with.')}
label={t<string>('sending account')}
label={t<string>('close from account')}
onChange={setAccountId}
type='account'
/>

View File

@ -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<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const { allAccounts } = useAccounts();
const derive = useCall<DeriveCollectiveProposal>(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
hasFailed={hasFailed}
hash={imageHash}
idNumber={index}
members={members}
proposal={derive.proposal}
type={type}
/>
)
: (
<TxButton
accountId={councilId}
icon='times'
label={t<string>('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}
/>
)
<Close
hasFailed={hasFailed}
hash={imageHash}
idNumber={index}
proposal={derive.proposal}
type={type}
/>
)}
</td>
</tr>