-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Propose tech committee motions #1996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d702a3a
Propose tech committe motions
kwingram25 aab698d
Merge branch 'master' into ki-tech-committee
kwingram25 109c286
bug, ignore .vscode
kwingram25 0d7a2e1
linting
kwingram25 0cd3e78
Some cleanups
jacogr 76ce790
Move Propose back
jacogr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,4 @@ npm-debug.log* | |
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .idea/ | ||
| .vscode/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<Props> { | ||
| const _hasThreshold = (threshold?: BN | null): boolean => | ||
| !!threshold && !threshold.isZero() && threshold.lten(memberCount); | ||
|
|
||
| const { apiDefaultTxSudo } = useApi(); | ||
| const [proposal, setProposal] = useState<Proposal | null>(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<TxDef> => [ | ||
| [ | ||
| '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 ( | ||
| <TxModal | ||
| isOpen | ||
| onClose={onClose} | ||
| {...txState} | ||
| header={t('Propose a committee motion')} | ||
| > | ||
| <InputNumber | ||
| className='medium' | ||
| label={t('threshold')} | ||
| help={t('The minimum number of committee votes required to approve this motion')} | ||
| isError={!hasThreshold} | ||
| onChange={_onChangeThreshold} | ||
| onEnter={txState.sendTx} | ||
| placeholder={t('Positive number between 1 and {{memberCount}}', { replace: { memberCount } })} | ||
| value={threshold || undefined} | ||
| /> | ||
| <Extrinsic | ||
| defaultValue={apiDefaultTxSudo} | ||
| label={t('proposal')} | ||
| onChange={_onChangeExtrinsic} | ||
| onEnter={txState.sendTx} | ||
| /> | ||
| </TxModal> | ||
| ); | ||
| } | ||
|
|
||
| export default translate(Propose); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // 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 { AccountId, Hash } from '@polkadot/types/interfaces'; | ||
|
|
||
| export interface ComponentProps { | ||
| className?: string; | ||
| proposals?: Hash[]; | ||
| members?: AccountId[]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole thing is just magic, no description of what is what. We will need to update this to be either an object of not having to pass
{...txState}(more magic) to the Modal. Contrast this to TxButton (old), where it is obvious what you are passing.(Not changing it as part of this PR as it works, but it needs a re-look)