diff --git a/packages/app-council/src/Motions/Motion.tsx b/packages/app-council/src/Motions/Motion.tsx index 5a167c0e7c..9cf467e608 100644 --- a/packages/app-council/src/Motions/Motion.tsx +++ b/packages/app-council/src/Motions/Motion.tsx @@ -5,19 +5,21 @@ import { DerivedCollectiveProposal } from '@polkadot/api-derive/types'; import React from 'react'; -import { AddressMini, Voting } from '@polkadot/react-components'; +import { AddressMini } from '@polkadot/react-components'; import ProposalCell from '@polkadot/app-democracy/Overview/ProposalCell'; import { formatNumber } from '@polkadot/util'; import { useTranslation } from '../translate'; +import Voting from './Voting'; interface Props { className?: string; isMember: boolean; + members: string[]; motion: DerivedCollectiveProposal; } -export default function Motion ({ className, isMember, motion: { hash, proposal, votes } }: Props): React.ReactElement | null { +export default function Motion ({ className, isMember, members, motion: { hash, proposal, votes } }: Props): React.ReactElement | null { const { t } = useTranslation(); if (!votes) { @@ -61,9 +63,9 @@ export default function Motion ({ className, isMember, motion: { hash, proposal, diff --git a/packages/app-council/src/Motions/Propose.tsx b/packages/app-council/src/Motions/Propose.tsx index f29f30728b..7cbd382a53 100644 --- a/packages/app-council/src/Motions/Propose.tsx +++ b/packages/app-council/src/Motions/Propose.tsx @@ -7,8 +7,7 @@ import { Call, Proposal } from '@polkadot/types/interfaces'; import BN from 'bn.js'; import React from 'react'; -import { registry } from '@polkadot/react-api'; -import { withCalls, withMulti } from '@polkadot/react-api/hoc'; +import { registry, withApi, withMulti } from '@polkadot/react-api'; import { Button, Extrinsic, InputNumber } from '@polkadot/react-components'; import TxModal, { TxModalState, TxModalProps } from '@polkadot/react-components/TxModal'; import { createType } from '@polkadot/types'; @@ -17,7 +16,7 @@ import translate from '../translate'; interface Props extends TxModalProps, ApiProps { isMember: boolean; - memberCount: number; + members: string[]; } interface State extends TxModalState { @@ -32,16 +31,14 @@ class Propose extends TxModal { this.defaultState = { ...this.defaultState, method: null, - threshold: props.memberCount ? new BN((props.memberCount / 2) + 1) : null + threshold: props.members.length ? new BN(Math.ceil(props.members.length * 0.5)) : null }; this.state = this.defaultState; } - public static getDerivedStateFromProps ({ memberCount }: Props, { threshold }: State): Pick | null { - if (!threshold && memberCount > 0) { - const simpleMajority = new BN((memberCount / 2) + 1); - - return { threshold: simpleMajority }; + public static getDerivedStateFromProps ({ members }: Props, { threshold }: State): Pick | null { + if (!threshold && members.length) { + return { threshold: new BN(Math.ceil(members.length * 0.5)) }; } return null; @@ -61,10 +58,10 @@ class Propose extends TxModal { } protected isDisabled = (): boolean => { - const { memberCount = 0 } = this.props; + const { members } = this.props; const { accountId, method, threshold } = this.state; - const hasThreshold = !!threshold && threshold.gtn(0) && threshold.ltn(memberCount + 1); + const hasThreshold = !!threshold && threshold.gtn(0) && threshold.ltn(members.length + 1); const hasMethod = !!method; return !accountId || !hasMethod || !hasThreshold; @@ -85,7 +82,7 @@ class Propose extends TxModal { } protected renderContent = (): React.ReactNode => { - const { apiDefaultTxSudo, memberCount = 0, t } = this.props; + const { apiDefaultTxSudo, members, t } = this.props; const { threshold } = this.state; return ( @@ -94,13 +91,13 @@ class Propose extends TxModal { className='medium' label={t('threshold')} help={t('The minimum number of council votes required to approve this motion')} - isError={!threshold || threshold.eqn(0) || threshold.gtn(memberCount)} + isError={!threshold || threshold.eqn(0) || threshold.gtn(members.length)} onChange={this.onChangeThreshold} onEnter={this.sendTx} placeholder={ t( 'Positive number between 1 and {{memberCount}}', - { replace: { memberCount } } + { replace: { memberCount: members.length } } ) } value={threshold || new BN(0)} @@ -116,10 +113,10 @@ class Propose extends TxModal { } private onChangeThreshold = (threshold: BN | null = null): void => { - const { memberCount = 0 } = this.props; + const { members } = this.props; - if (memberCount > 0 && !this.defaultState.threshold) { - this.defaultState.threshold = new BN((memberCount / 2) + 1); + if (members.length && !this.defaultState.threshold) { + this.defaultState.threshold = new BN(Math.ceil(members.length * 0.5)); } this.setState({ threshold }); @@ -135,14 +132,6 @@ class Propose extends TxModal { } export default withMulti( - Propose, - translate, - withCalls( - ['query.electionsPhragmen.members', { - fallbacks: ['query.elections.members'], - propName: 'memberCount', - transform: (value: any[]): number => - value.length - }] - ) + translate(Propose), + withApi ); diff --git a/packages/app-council/src/Motions/Slashing.tsx b/packages/app-council/src/Motions/Slashing.tsx index d5d5091951..e097f26d4f 100644 --- a/packages/app-council/src/Motions/Slashing.tsx +++ b/packages/app-council/src/Motions/Slashing.tsx @@ -2,12 +2,11 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { AccountId } from '@polkadot/types/interfaces'; import { CallFunction } from '@polkadot/types/types'; import React, { useEffect, useState } from 'react'; import { Button, Dropdown, Input, InputAddress, Modal, TxButton } from '@polkadot/react-components'; -import { useApi, useCall, useToggle } from '@polkadot/react-hooks'; +import { useApi, useToggle } from '@polkadot/react-hooks'; import { useTranslation } from '../translate'; import useAvailableSlashes from './useAvailableSlashes'; @@ -15,6 +14,7 @@ import useAvailableSlashes from './useAvailableSlashes'; interface Props { className?: string; isMember: boolean; + members: string[]; } interface Option { @@ -22,28 +22,16 @@ interface Option { value: number; } -export default function Slashing ({ className, isMember }: Props): React.ReactElement { +export default function Slashing ({ className, isMember, members }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); - const members = useCall(api.query.electionsPhragmen?.members || api.query.elections.members, []); const slashes = useAvailableSlashes(); const [isVisible, toggleVisible] = useToggle(); - const [isSelectedMember, setIsMember] = useState(false); const [accountId, setAcountId] = useState(null); const [proposal, setProposal] = useState(null); const [eras, setEras] = useState([]); const [selectedEra, setSelectedEra] = useState(0); - const threshold = Math.ceil((members?.length || 0) * 0.5); - - useEffect((): void => { - if (accountId && members) { - setIsMember( - members - .map(([accountId]): string => accountId.toString()) - .includes(accountId) - ); - } - }, [accountId, members]); + const threshold = Math.ceil((members.length || 0) * 0.5); useEffect((): void => { if (slashes?.length) { @@ -77,7 +65,7 @@ export default function Slashing ({ className, isMember }: Props): React.ReactEl <>