diff --git a/.gitignore b/.gitignore index 2ac9c3d1be63..151e2d373e54 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ npm-debug.log* yarn-debug.log* yarn-error.log* .idea/ +.vscode/ diff --git a/packages/app-tech-comm/src/Overview/Summary.tsx b/packages/app-tech-comm/src/Overview/Summary.tsx index c75ed3f5726a..0653a24de329 100644 --- a/packages/app-tech-comm/src/Overview/Summary.tsx +++ b/packages/app-tech-comm/src/Overview/Summary.tsx @@ -4,7 +4,7 @@ // 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 } from '../types'; import React from 'react'; import { SummaryBox, CardSummary } from '@polkadot/react-components'; @@ -14,10 +14,7 @@ import { formatNumber } from '@polkadot/util'; import translate from '../translate'; -interface Props extends I18nProps { - members?: AccountId[]; - proposals?: Hash[]; -} +interface Props extends ComponentProps, I18nProps {} function Summary ({ className, members, proposals, t }: Props): React.ReactElement { const { api } = useApi(); diff --git a/packages/app-tech-comm/src/Overview/index.tsx b/packages/app-tech-comm/src/Overview/index.tsx index aa97c3a027b5..99a3b2a0ba00 100644 --- a/packages/app-tech-comm/src/Overview/index.tsx +++ b/packages/app-tech-comm/src/Overview/index.tsx @@ -2,32 +2,27 @@ // 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 { I18nProps } from '@polkadot/react-components/types'; +import { ComponentProps } from '../types'; import React from 'react'; +import translate from '../translate'; import Members from './Members'; import Summary from './Summary'; -interface Props { - className?: string; - members?: AccountId[]; - proposals?: Hash[]; -} +interface Props extends I18nProps, ComponentProps {} -export default function Overview ({ className, members, proposals }: Props): React.ReactElement { +function Overview ({ className, members, proposals }: Props): React.ReactElement { return (
- {/* - - - - */}
); } + +export default translate(Overview); 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 9bedb0c7b0fe..dd5e96f1b8b5 100644 --- a/packages/app-tech-comm/src/Proposals/Proposal.tsx +++ b/packages/app-tech-comm/src/Proposals/Proposal.tsx @@ -21,14 +21,14 @@ 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 optProposal = trackStream>(api.query.technicalCommittee.proposalOf, [hash]); const votes = trackStream>(api.query.technicalCommittee.voting, [hash]); - if (!votes?.isSome) { + if (!optProposal?.isSome || !votes?.isSome) { return null; } - const proposal = _proposal?.unwrapOr(null); + const proposal = optProposal.unwrap(); const { ayes, index, nays, threshold } = votes.unwrap(); return ( 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..16707786333c --- /dev/null +++ b/packages/app-tech-comm/src/Proposals/Propose.tsx @@ -0,0 +1,83 @@ +// 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, Proposal } 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 { + memberCount?: number; + onClose: () => void; +} + +function Propose ({ t, onClose, memberCount = 0 }: Props): React.ReactElement { + const _hasThreshold = (threshold?: BN | null): boolean => + !!threshold && !threshold.isZero() && threshold.lten(memberCount); + + const { apiDefaultTxSudo } = useApi(); + const [proposal, setProposal] = useState(null); + const [[threshold, hasThreshold], setThreshold] = useState<[BN | null, boolean]>([ + new BN(memberCount / 2 + 1), + true + ]); + + // FIXME Rework this, unless you know, you can never figure out what all these options mean here + const txState = useTx( + (): TxSource => [ + [ + 'technicalCommittee.propose', + [threshold, proposal] + ], + !!proposal && hasThreshold + ], + [memberCount, proposal, threshold, hasThreshold], + {} + ); + + useEffect((): void => { + setThreshold([threshold, _hasThreshold(threshold)]); + }, [memberCount]); + + const _onChangeExtrinsic = (method?: Call): void => + setProposal(method ? createType(registry, 'Proposal', method) : null); + const _onChangeThreshold = (threshold?: BN): void => + setThreshold([threshold || null, _hasThreshold(threshold)]); + + 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..febac97a8940 100644 --- a/packages/app-tech-comm/src/Proposals/index.tsx +++ b/packages/app-tech-comm/src/Proposals/index.tsx @@ -2,23 +2,39 @@ // This software may be modified and distributed under the terms // 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 { Hash } from '@polkadot/types/interfaces'; +import { ComponentProps } 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 translate from '../translate'; +import Proposal from './Proposal'; +import Propose from './Propose'; -interface Props extends I18nProps { - proposals?: Hash[]; -} +interface Props extends ComponentProps, I18nProps {} + +function Proposals ({ className, members, proposals, t }: Props): React.ReactElement { + const [isProposeOpen, setIsProposeOpen] = useState(false); + const _toggleProposal = (): void => setIsProposeOpen(!isProposeOpen); -function Proposals ({ className, proposals, t }: Props): React.ReactElement { return (
- {/* */} + {isProposeOpen && ( + + )} + +