From d702a3ab05ceef2a10b86edd18adae289210152a Mon Sep 17 00:00:00 2001 From: Keith Ingram Date: Tue, 3 Dec 2019 18:07:04 -0500 Subject: [PATCH 1/5] Propose tech committe motions --- .../app-tech-comm/src/Overview/Summary.tsx | 8 +- packages/app-tech-comm/src/Overview/index.tsx | 17 +--- packages/app-tech-comm/src/Overview/types.ts | 17 ---- .../app-tech-comm/src/Proposals/Proposal.tsx | 3 +- .../app-tech-comm/src/Proposals/Propose.tsx | 98 +++++++++++++++++++ .../app-tech-comm/src/Proposals/index.tsx | 27 +++-- packages/app-tech-comm/src/index.tsx | 5 +- packages/app-tech-comm/src/types.ts | 12 +++ packages/react-components/src/InputNumber.tsx | 4 +- packages/react-hooks/src/types.ts | 7 +- packages/react-hooks/src/useTx.ts | 40 ++++---- 11 files changed, 170 insertions(+), 68 deletions(-) delete mode 100644 packages/app-tech-comm/src/Overview/types.ts create mode 100644 packages/app-tech-comm/src/Proposals/Propose.tsx create mode 100644 packages/app-tech-comm/src/types.ts diff --git a/packages/app-tech-comm/src/Overview/Summary.tsx b/packages/app-tech-comm/src/Overview/Summary.tsx index c75ed3f5726a..8a6674f21f47 100644 --- a/packages/app-tech-comm/src/Overview/Summary.tsx +++ b/packages/app-tech-comm/src/Overview/Summary.tsx @@ -3,8 +3,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { I18nProps } from '@polkadot/react-components/types'; -import { AccountId, Hash } from '@polkadot/types/interfaces'; +import { ComponentProps as Props } from '../types'; import React from 'react'; import { SummaryBox, CardSummary } from '@polkadot/react-components'; @@ -14,11 +13,6 @@ import { formatNumber } from '@polkadot/util'; import translate from '../translate'; -interface Props extends I18nProps { - members?: AccountId[]; - proposals?: Hash[]; -} - function Summary ({ className, members, proposals, t }: Props): React.ReactElement { const { api } = useApi(); const proposalCount = trackStream(api.query.technicalCommittee.proposalCount, []); diff --git a/packages/app-tech-comm/src/Overview/index.tsx b/packages/app-tech-comm/src/Overview/index.tsx index aa97c3a027b5..76144c0d554a 100644 --- a/packages/app-tech-comm/src/Overview/index.tsx +++ b/packages/app-tech-comm/src/Overview/index.tsx @@ -2,19 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { AccountId, Hash } from '@polkadot/types/interfaces'; +import { ComponentProps as Props } from '../types'; import React from 'react'; import Members from './Members'; import Summary from './Summary'; -interface Props { - className?: string; - members?: AccountId[]; - proposals?: Hash[]; -} - export default function Overview ({ className, members, proposals }: Props): React.ReactElement { return (
@@ -22,12 +16,9 @@ export default function Overview ({ className, members, proposals }: Props): Rea members={members} proposals={proposals} /> - {/* - - - - */} - +
); } diff --git a/packages/app-tech-comm/src/Overview/types.ts b/packages/app-tech-comm/src/Overview/types.ts deleted file mode 100644 index 8e1d3534df36..000000000000 --- a/packages/app-tech-comm/src/Overview/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2017-2019 @polkadot/app-democracy 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 { SetIndex } from '@polkadot/types/interfaces'; -import { DerivedElectionsInfo } from '@polkadot/api-derive/types'; - -import BN from 'bn.js'; - -export interface ComponentProps { - electionsInfo: DerivedElectionsInfo; -} - -export interface VoterPosition { - setIndex: SetIndex; - globalIndex: BN; -} diff --git a/packages/app-tech-comm/src/Proposals/Proposal.tsx b/packages/app-tech-comm/src/Proposals/Proposal.tsx index 8c3dd977dc12..8b2f6102f5c1 100644 --- a/packages/app-tech-comm/src/Proposals/Proposal.tsx +++ b/packages/app-tech-comm/src/Proposals/Proposal.tsx @@ -21,9 +21,10 @@ interface Props extends I18nProps { function Proposal ({ className, hash, t }: Props): React.ReactElement | null { const { api } = useApi(); - const proposal = trackStream(api.query.technicalCommittee.proposalOf, [hash]); + const option = trackStream>(api.query.technicalCommittee.proposalOf, [hash]); const votes = trackStream>(api.query.technicalCommittee.voting, [hash]); + const proposal = option?.unwrapOr(null) || null; if (!proposal || !votes?.isSome) { return null; } diff --git a/packages/app-tech-comm/src/Proposals/Propose.tsx b/packages/app-tech-comm/src/Proposals/Propose.tsx new file mode 100644 index 000000000000..868347f4eb17 --- /dev/null +++ b/packages/app-tech-comm/src/Proposals/Propose.tsx @@ -0,0 +1,98 @@ +// Copyright 2017-2019 @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 { I18nProps } from '@polkadot/react-components/types'; +import { TxSource, TxDef } from '@polkadot/react-hooks/types'; +import { Call } from '@polkadot/types/interfaces'; + +import BN from 'bn.js'; +import React, { useEffect, useState } from 'react'; +import { registry } from '@polkadot/react-api'; +import { Extrinsic, InputNumber, TxModalNew as TxModal } from '@polkadot/react-components'; +import { useApi, useTx } from '@polkadot/react-hooks'; +import { createType } from '@polkadot/types'; + +import translate from '../translate'; + +interface Props extends I18nProps { + isOpen: boolean; + memberCount: number; + onClose: () => void; +} + +function Propose ({ t, isOpen, onClose, memberCount = 0 }: Props): React.ReactElement { + const _hasThreshold = (threshold?: BN | null): boolean => { + return !!threshold &&; !threshold.isZero() && threshold.lten(memberCount); + } + + const [method, setMethod] = useState(null); + const [[threshold, hasThreshold], setThreshold] = useState<[BN | null, boolean]>([ + new BN(memberCount / 2 + 1), + true + ]); + + const _onChangeThreshold = (threshold?: BN): void => { + setThreshold([threshold || null, _hasThreshold(threshold)]); + }; + + const _onChangeExtrinsic = (method?: Call): void => { + !!method && setMethod(method); + }; + + useEffect( + (): void => setThreshold([threshold, _hasThreshold(threshold)]), + [memberCount] + ); + + const { apiDefaultTxSudo } = useApi(); + const txState = useTx( + (): TxSource => [ + [ + 'technicalCommittee.propose', + [threshold, method ? createType(registry, 'Proposal', method) : null] + ], + !!method && hasThreshold + ], + [memberCount, method, threshold, hasThreshold], + { + onSuccess: onClose + } + ); + + return ( + + + + + } + /> + ); +} + +export default translate(Propose); diff --git a/packages/app-tech-comm/src/Proposals/index.tsx b/packages/app-tech-comm/src/Proposals/index.tsx index 96b3707651c7..f342999743f4 100644 --- a/packages/app-tech-comm/src/Proposals/index.tsx +++ b/packages/app-tech-comm/src/Proposals/index.tsx @@ -3,22 +3,33 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Hash } from '@polkadot/types/interfaces'; -import { I18nProps } from '@polkadot/react-components/types'; +import { ComponentProps as Props } from '../types'; -import React from 'react'; -import { Table } from '@polkadot/react-components'; +import React, { useState } from 'react'; +import { Button, Table } from '@polkadot/react-components'; import Proposal from './Proposal'; +import Propose from './Propose'; import translate from '../translate'; -interface Props extends I18nProps { - proposals?: Hash[]; -} +function Proposals ({ className, members, proposals, t }: Props): React.ReactElement { + const [isProposeOpen, setIsProposeOpen] = useState(false); -function Proposals ({ className, proposals, t }: Props): React.ReactElement { return (
- {/* */} + +