From 042e8a0a168579a86bdb8ce7b1632a97aeeff9cf Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 20 Mar 2020 08:09:17 +0100 Subject: [PATCH] Majority propose shortcut (council) (#2423) --- .../src/Motions/ProposeExternal.tsx | 90 +++++++++++++++++++ .../{Propose.tsx => ProposeMotion.tsx} | 0 .../page-council/src/Motions/Slashing.tsx | 6 +- packages/page-council/src/Motions/index.tsx | 10 ++- .../src/Actions/Account/SetSessionKey.tsx | 1 + 5 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 packages/page-council/src/Motions/ProposeExternal.tsx rename packages/page-council/src/Motions/{Propose.tsx => ProposeMotion.tsx} (100%) diff --git a/packages/page-council/src/Motions/ProposeExternal.tsx b/packages/page-council/src/Motions/ProposeExternal.tsx new file mode 100644 index 0000000000..e328321530 --- /dev/null +++ b/packages/page-council/src/Motions/ProposeExternal.tsx @@ -0,0 +1,90 @@ +// Copyright 2017-2020 @polkadot/ui-staking 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 { SubmittableExtrinsic } from '@polkadot/api/types'; + +import React, { useCallback, useEffect, useState } from 'react'; +import { Button, Input, InputAddress, Modal, TxButton } from '@polkadot/react-components'; +import { useApi, useToggle } from '@polkadot/react-hooks'; +import { isHex } from '@polkadot/util'; + +import { useTranslation } from '../translate'; + +interface Props { + className?: string; + isMember: boolean; + members: string[]; +} + +function ProposeExternal ({ className, isMember, members }: Props): React.ReactElement { + const { t } = useTranslation(); + const { api } = useApi(); + const [isVisible, toggleVisible] = useToggle(); + const [accountId, setAcountId] = useState(null); + const [proposal, setProposal] = useState | null>(null); + const [{ isHashValid, hash }, setHash] = useState<{ isHashValid: boolean; hash?: string }>({ isHashValid: false, hash: '' }); + const threshold = Math.ceil((members.length || 0) * 0.5); + + const _onChangeHash = useCallback( + (hash?: string): void => setHash({ isHashValid: isHex(hash, 256), hash }), + [] + ); + + useEffect((): void => { + if (isHashValid && hash) { + setProposal(() => api.tx.democracy.externalProposeMajority(hash)); + } else { + setProposal(null); + } + }, [hash, isHashValid]); + + return ( + <> +