Failed council close with 0 length/weight (#2839)

* Failed council close with 0 length/weight

* 0/0 close for tc
This commit is contained in:
Jaco Greeff 2020-05-28 20:22:14 +02:00 committed by GitHub
parent 74f4956a5d
commit b2c3eb8fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import { useAccounts, useApi, useToggle } from '@polkadot/react-hooks';
import { useTranslation } from '../translate';
interface Props {
hasFailed: boolean;
hash: Hash;
idNumber: ProposalIndex;
isDisabled: boolean;
@ -18,7 +19,7 @@ interface Props {
proposal: Proposal;
}
function Close ({ hash, idNumber, isDisabled, members, proposal }: Props): React.ReactElement<Props> | null {
function Close ({ hasFailed, hash, idNumber, isDisabled, members, proposal }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const { allAccounts } = useAccounts();
@ -74,7 +75,9 @@ function Close ({ hash, idNumber, isDisabled, members, proposal }: Props): React
onStart={toggleOpen}
params={
api.tx.council.close.meta.args.length === 4
? [hash, idNumber, proposalWeight, proposalLength]
? hasFailed
? [hash, idNumber, 0, 0]
: [hash, idNumber, proposalWeight, proposalLength]
: [hash, idNumber]
}
tx='council.close'

View File

@ -25,7 +25,7 @@ interface Props {
}
function Motion ({ className = '', isMember, members, motion: { hash, proposal, votes }, prime }: Props): React.ReactElement<Props> | null {
const { isCloseable, isVoteable, remainingBlocks } = useVotingStatus(votes, members.length, 'council');
const { hasFailed, isCloseable, isVoteable, remainingBlocks } = useVotingStatus(votes, members.length, 'council');
if (!votes) {
return null;
@ -66,6 +66,7 @@ function Motion ({ className = '', isMember, members, motion: { hash, proposal,
)}
{isCloseable && (
<Close
hasFailed={hasFailed}
hash={hash}
idNumber={index}
isDisabled={!isMember}

View File

@ -11,6 +11,7 @@ import { useAccounts, useApi, useToggle } from '@polkadot/react-hooks';
import { useTranslation } from '../translate';
interface Props {
hasFailed: boolean;
hash: Hash;
idNumber: ProposalIndex;
isDisabled: boolean;
@ -18,7 +19,7 @@ interface Props {
proposal: Proposal;
}
function Close ({ hash, idNumber, isDisabled, members, proposal }: Props): React.ReactElement<Props> | null {
function Close ({ hasFailed, hash, idNumber, isDisabled, members, proposal }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { api } = useApi();
const { allAccounts } = useAccounts();
@ -74,7 +75,9 @@ function Close ({ hash, idNumber, isDisabled, members, proposal }: Props): React
onStart={toggleOpen}
params={
api.tx.technicalCommittee.close.meta.args.length === 4
? [hash, idNumber, proposalWeight, proposalLength]
? hasFailed
? [hash, idNumber, 0, 0]
: [hash, idNumber, proposalWeight, proposalLength]
: [hash, idNumber]
}
tx='technicalCommittee.close'

View File

@ -31,7 +31,7 @@ function Proposal ({ className = '', imageHash, isMember, members, prime }: Prop
const votes = useCall<Votes | null>(api.query.technicalCommittee.voting, [imageHash], {
transform: (optVotes: Option<Votes>) => optVotes.unwrapOr(null)
});
const { isCloseable, isVoteable, remainingBlocks } = useVotingStatus(votes, members.length, 'technicalCommittee');
const { hasFailed, isCloseable, isVoteable, remainingBlocks } = useVotingStatus(votes, members.length, 'technicalCommittee');
if (!proposal || !votes) {
return null;
@ -85,6 +85,7 @@ function Proposal ({ className = '', imageHash, isMember, members, prime }: Prop
)}
{isCloseable && (
<Close
hasFailed={hasFailed}
hash={imageHash}
idNumber={index}
isDisabled={!isMember}

View File

@ -12,6 +12,8 @@ import useApi from './useApi';
import useCall from './useCall';
interface State {
hasFailed: boolean;
hasPassed: boolean;
isCloseable: boolean;
isVoteable: boolean;
remainingBlocks: BN | null;
@ -20,6 +22,8 @@ interface State {
function getStatus (api: ApiPromise, bestNumber: BlockNumber, votes: Votes, numMembers: number, section: 'council' | 'technicalCommittee'): State {
if (!votes.end) {
return {
hasFailed: false,
hasPassed: false,
isCloseable: false,
isVoteable: true,
remainingBlocks: null
@ -27,13 +31,15 @@ function getStatus (api: ApiPromise, bestNumber: BlockNumber, votes: Votes, numM
}
const isEnd = bestNumber.gte(votes.end);
const isPassing = votes.threshold.lten(votes.ayes.length);
const isFailing = votes.threshold.gtn(Math.abs(numMembers - votes.nays.length));
const hasPassed = votes.threshold.lten(votes.ayes.length);
const hasFailed = votes.threshold.gtn(Math.abs(numMembers - votes.nays.length));
return {
hasFailed,
hasPassed,
isCloseable: api.tx[section].close.meta.args.length === 2
? isEnd
: isEnd || isPassing || isFailing,
: isEnd || hasPassed || hasFailed,
isVoteable: !isEnd,
remainingBlocks: isEnd
? null
@ -44,7 +50,7 @@ function getStatus (api: ApiPromise, bestNumber: BlockNumber, votes: Votes, numM
export default function useVotingStatus (votes: Votes | null | undefined, numMembers: number, section: 'council' | 'technicalCommittee'): State {
const { api } = useApi();
const bestNumber = useCall<BlockNumber>(api.derive.chain.bestNumber, []);
const [state, setState] = useState<State>({ isCloseable: false, isVoteable: false, remainingBlocks: null });
const [state, setState] = useState<State>({ hasFailed: false, hasPassed: false, isCloseable: false, isVoteable: false, remainingBlocks: null });
useEffect((): void => {
bestNumber && votes && setState(