Update council params (genesisHash) (#3239)

This commit is contained in:
Jaco Greeff 2020-07-20 19:53:34 +02:00 committed by GitHub
parent ebdc380f22
commit f0ed07dc8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 6 deletions

View File

@ -10,6 +10,7 @@ import { useApi, useToggle } from '@polkadot/react-hooks';
import { isHex } from '@polkadot/util';
import { useTranslation } from '../translate';
import { getThreshold } from './thresholds';
interface Props {
className?: string;
@ -33,7 +34,7 @@ function ProposeExternal ({ className = '', isMember, members }: Props): React.R
const [accountId, setAcountId] = useState<string | null>(null);
const [{ proposal, proposalLength }, setProposal] = useState<ProposalState>({ proposalLength: 0 });
const [{ hash, isHashValid }, setHash] = useState<HashState>({ hash: '', isHashValid: false });
const threshold = Math.ceil((members.length || 0) * 0.6); // 60 for Polkadot
const threshold = Math.ceil((members.length || 0) * getThreshold(api));
const _onChangeHash = useCallback(
(hash?: string): void => setHash({ hash, isHashValid: isHex(hash, 256) }),

View File

@ -11,6 +11,7 @@ import { useApi, useToggle } from '@polkadot/react-hooks';
import { BN_ZERO } from '@polkadot/util';
import { useTranslation } from '../translate';
import { getThreshold } from './thresholds';
interface Props {
isMember: boolean;
@ -38,9 +39,9 @@ function Propose ({ isMember, members }: Props): React.ReactElement<Props> {
useEffect((): void => {
members && setThreshold({
isThresholdValid: members.length !== 0,
threshold: new BN(Math.ceil(members.length * 0.5))
threshold: new BN(Math.ceil(members.length * getThreshold(api)))
});
}, [members]);
}, [api, members]);
const _setMethod = useCallback(
(proposal?: SubmittableExtrinsic<'promise'> | null) => setProposal({

View File

@ -9,6 +9,7 @@ import { Button, Dropdown, Input, InputAddress, Modal, TxButton } from '@polkado
import { useApi, useToggle } from '@polkadot/react-hooks';
import { useTranslation } from '../translate';
import { getThreshold } from './thresholds';
import useAvailableSlashes from './useAvailableSlashes';
interface Props {
@ -31,7 +32,7 @@ function Slashing ({ className = '', isMember, members }: Props): React.ReactEle
const [proposal, setProposal] = useState<CallFunction | null>(null);
const [eras, setEras] = useState<Option[]>([]);
const [selectedEra, setSelectedEra] = useState(0);
const threshold = Math.ceil((members.length || 0) * 0.5);
const threshold = Math.ceil((members.length || 0) * getThreshold(api));
useEffect((): void => {
setEras(

View File

@ -0,0 +1,18 @@
// Copyright 2017-2020 @polkadot/app-council 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 { ApiPromise } from '@polkadot/api';
const THRESHOLDS: Record<string, number> = {
// Polkadot
'0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3': 0.6,
// Kusama
'0xb0a8d493285c2df73290dfb7e61f870f17b41801197a149ca93654499ea3dafe': 0.5
};
export function getThreshold (api: ApiPromise): number {
return THRESHOLDS[api.genesisHash.toHex()] || 0.5;
}
export { THRESHOLDS };

View File

@ -37,7 +37,7 @@ function Fasttrack ({ imageHash, threshold }: Props): React.ReactElement<Props>
const [votingBlocks, setVotingBlocks] = useState<BN | undefined>(DEF_VOTING);
const [{ proposal, proposalLength }, setProposal] = useState<ProposalState>({ proposalLength: 0 });
const memberThreshold = useMemo(
() => Math.ceil(members.length * 0.5),
() => Math.ceil(members.length * 0.66),
[members]
);

View File

@ -44,7 +44,7 @@ function Submission ({ councilProposals, id, isDisabled, members }: Props): Reac
useEffect((): void => {
setHasProposals(
!!councilProposals
.map(({ votes }): number => votes ? votes.index.toNumber() : -1)
.map(({ votes }) => votes ? votes.index.toNumber() : -1)
.filter((index) => index !== -1)
.length
);