Treasury app (#1324)
* treasury app * fixes * more fixes * treasury app * fixes * more fixes * fixes + collections * force travis
This commit is contained in:
parent
a33292803a
commit
b74755bbaa
@ -24,34 +24,32 @@ class Members extends React.PureComponent<Props> {
|
||||
|
||||
return (
|
||||
<Columar>
|
||||
<Column header={t('members')}>
|
||||
{this.renderNone(council_activeCouncil.map(([address, block]) => (
|
||||
<Column
|
||||
emptyText={t('No members found')}
|
||||
headerText={t('members')}
|
||||
>
|
||||
{council_activeCouncil.map(([address, block]) => (
|
||||
<Member
|
||||
address={address}
|
||||
block={block}
|
||||
key={address}
|
||||
/>
|
||||
)))}
|
||||
))}
|
||||
</Column>
|
||||
<Column header={t('candidates')}>
|
||||
{this.renderNone(council_candidates.map((address) => (
|
||||
<Column
|
||||
emptyText={t('No members found')}
|
||||
headerText={t('candidates')}
|
||||
>
|
||||
{council_candidates.map((address) => (
|
||||
<Candidate
|
||||
address={address}
|
||||
key={address}
|
||||
/>
|
||||
)))}
|
||||
))}
|
||||
</Column>
|
||||
</Columar>
|
||||
);
|
||||
}
|
||||
|
||||
private renderNone (items: Array<React.ReactNode>) {
|
||||
const { t } = this.props;
|
||||
|
||||
return items.length
|
||||
? items
|
||||
: <article>{t('No addresses found')}</article>;
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(
|
||||
|
||||
@ -30,20 +30,17 @@ class Proposals extends React.PureComponent<Props> {
|
||||
const { t } = this.props;
|
||||
|
||||
return (
|
||||
<Column header={t('proposals')}>
|
||||
<Column
|
||||
emptyText={t('No available proposals')}
|
||||
headerText={t('proposals')}
|
||||
>
|
||||
{this.renderProposals()}
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
|
||||
private renderProposals () {
|
||||
const { democracy_publicProps, t } = this.props;
|
||||
|
||||
if (!democracy_publicProps || !democracy_publicProps.length) {
|
||||
return (
|
||||
<article>{t('no available proposals')}</article>
|
||||
);
|
||||
}
|
||||
const { democracy_publicProps = [] } = this.props;
|
||||
|
||||
return democracy_publicProps.map(([idNumber, proposal]) => (
|
||||
<ProposalDisplay
|
||||
|
||||
@ -22,24 +22,21 @@ class Referendums extends React.PureComponent<Props> {
|
||||
const { t } = this.props;
|
||||
|
||||
return (
|
||||
<Column header={t('referendum')}>
|
||||
<Column
|
||||
emptyText={t('No available referendums')}
|
||||
headerText={t('referendum')}
|
||||
>
|
||||
{this.renderReferendums()}
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
|
||||
private renderReferendums () {
|
||||
const { democracy_referendums = [], t } = this.props;
|
||||
const { democracy_referendums = [] } = this.props;
|
||||
const referendums = democracy_referendums
|
||||
.filter((opt) => opt.isSome)
|
||||
.map((opt) => opt.unwrap());
|
||||
|
||||
if (!referendums.length) {
|
||||
return (
|
||||
<article>{t('no available referendums')}</article>
|
||||
);
|
||||
}
|
||||
|
||||
return referendums.map((referendum) => (
|
||||
<Referendum
|
||||
idNumber={referendum.index}
|
||||
|
||||
@ -28,7 +28,7 @@ class Events extends React.PureComponent<Props> {
|
||||
}));
|
||||
|
||||
return (
|
||||
<Column header={t('events')}>
|
||||
<Column headerText={t('events')}>
|
||||
<EventsDisplay
|
||||
eventClassName='explorer--BlockByHash-block'
|
||||
events={events}
|
||||
|
||||
@ -24,7 +24,8 @@ class Extrinsics extends React.PureComponent<Props> {
|
||||
return (
|
||||
<Column
|
||||
className={className}
|
||||
header={label || t('extrinsics')}
|
||||
emptyText={t('No pending extrinsics are in the queue')}
|
||||
headerText={label || t('extrinsics')}
|
||||
>
|
||||
{this.renderContent()}
|
||||
</Column>
|
||||
@ -32,17 +33,9 @@ class Extrinsics extends React.PureComponent<Props> {
|
||||
}
|
||||
|
||||
private renderContent () {
|
||||
const { t, value } = this.props;
|
||||
const { value = [] } = this.props;
|
||||
|
||||
if (!value || !value.length) {
|
||||
return (
|
||||
<article>
|
||||
{t('no pending extrinsics are in the queue')}
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
return value.map(this.renderExtrinsic);
|
||||
return (value || []).map(this.renderExtrinsic);
|
||||
}
|
||||
|
||||
// FIXME This is _very_ similar to what we have in democracy/Item
|
||||
|
||||
@ -24,7 +24,7 @@ class Logs extends React.PureComponent<Props> {
|
||||
}
|
||||
|
||||
return (
|
||||
<Column header={t('logs')}>
|
||||
<Column headerText={t('logs')}>
|
||||
{value.map(this.renderItem)}
|
||||
</Column>
|
||||
);
|
||||
|
||||
@ -27,10 +27,10 @@ class Main extends React.PureComponent<Props> {
|
||||
<Query />
|
||||
<Summary />
|
||||
<Columar>
|
||||
<Column header={t('recent blocks')}>
|
||||
<Column headerText={t('recent blocks')}>
|
||||
<BlockHeaders />
|
||||
</Column>
|
||||
<Column header={t('recent events')}>
|
||||
<Column headerText={t('recent events')}>
|
||||
<Events events={events} />
|
||||
</Column>
|
||||
</Columar>
|
||||
|
||||
@ -62,10 +62,16 @@ class CurrentList extends React.PureComponent<Props, State> {
|
||||
/>
|
||||
</FilterOverlay>
|
||||
<Columar className='validator--ValidatorsList'>
|
||||
<Column header={t('validators')}>
|
||||
<Column
|
||||
emptyText={t('No addresses found')}
|
||||
headerText={t('validators')}
|
||||
>
|
||||
{this.renderColumn(current, t('validator (stash)'))}
|
||||
</Column>
|
||||
<Column header={t('next up')}>
|
||||
<Column
|
||||
emptyText={t('No addresses found')}
|
||||
headerText={t('next up')}
|
||||
>
|
||||
{this.renderColumn(next, t('intention (stash)'))}
|
||||
</Column>
|
||||
</Columar>
|
||||
@ -74,15 +80,9 @@ class CurrentList extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private renderColumn (addresses: Array<string>, defaultName: string) {
|
||||
const { balances, lastAuthor, lastBlock, recentlyOffline, t } = this.props;
|
||||
const { balances, lastAuthor, lastBlock, recentlyOffline } = this.props;
|
||||
const { filter } = this.state;
|
||||
|
||||
if (addresses.length === 0) {
|
||||
return (
|
||||
<article>{t('no addresses found')}</article>
|
||||
);
|
||||
}
|
||||
|
||||
return addresses.map((address) => (
|
||||
<Address
|
||||
address={address}
|
||||
|
||||
201
packages/app-treasury/LICENSE
Normal file
201
packages/app-treasury/LICENSE
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
1
packages/app-treasury/README.md
Normal file
1
packages/app-treasury/README.md
Normal file
@ -0,0 +1 @@
|
||||
# @polkadot/app-treasury
|
||||
18
packages/app-treasury/package.json
Normal file
18
packages/app-treasury/package.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "@polkadot/app-treasury",
|
||||
"version": "0.34.0-beta.21",
|
||||
"description": "A referendum & proposal app",
|
||||
"main": "index.js",
|
||||
"scripts": {},
|
||||
"author": "Keith Ingram <keith@parity.io>",
|
||||
"maintainers": [
|
||||
"Keith Ingram <keith@parity.io>",
|
||||
"Jaco Greeff <jacogr@gmail.com>"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.4.5",
|
||||
"@polkadot/ui-app": "^0.34.0-beta.21",
|
||||
"@polkadot/ui-reactive": "^0.34.0-beta.21"
|
||||
}
|
||||
}
|
||||
71
packages/app-treasury/src/Overview/Approve.tsx
Normal file
71
packages/app-treasury/src/Overview/Approve.tsx
Normal file
@ -0,0 +1,71 @@
|
||||
// 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 { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Dropdown } from '@polkadot/ui-app';
|
||||
import TxModal, { TxModalProps, TxModalState } from '@polkadot/ui-app/TxModal';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
type Props = I18nProps & TxModalProps & {
|
||||
isApproved?: boolean,
|
||||
proposalInfo?: React.ReactNode,
|
||||
proposalId: string
|
||||
};
|
||||
|
||||
type State = TxModalState & {
|
||||
isApproving: boolean
|
||||
};
|
||||
|
||||
class Approve extends TxModal<Props, State> {
|
||||
state: State = {
|
||||
...this.defaultState,
|
||||
isApproving: false
|
||||
};
|
||||
|
||||
private approveOptions = () => [
|
||||
{ text: this.props.t('Yay, I approve'), value: true },
|
||||
{ text: this.props.t('Nay, I do not approve'), value: false }
|
||||
]
|
||||
|
||||
headerText = () => this.props.t('Approve or reject proposal');
|
||||
|
||||
txMethod = () => this.state.isApproving ? 'treasury.approveProposal' : 'treasury.rejectProposal';
|
||||
txParams = () => [this.props.proposalId];
|
||||
|
||||
renderPreContent = () => {
|
||||
const { proposalInfo = null } = this.props;
|
||||
|
||||
return (
|
||||
<>
|
||||
{proposalInfo}
|
||||
<br />
|
||||
<br />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
renderContent = () => {
|
||||
const { t } = this.props;
|
||||
const { isApproving } = this.state;
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
help={t('Select your vote preference for this spend proposal, either to approve or disapprove')}
|
||||
label={t('action')}
|
||||
options={this.approveOptions()}
|
||||
onChange={this.onChangeApproving}
|
||||
value={isApproving}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
private onChangeApproving = (isApproving: boolean) => {
|
||||
this.setState({ isApproving });
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(Approve);
|
||||
61
packages/app-treasury/src/Overview/Item.tsx
Normal file
61
packages/app-treasury/src/Overview/Item.tsx
Normal file
@ -0,0 +1,61 @@
|
||||
// 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 { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { TreasuryProposal } from '@polkadot/types';
|
||||
import { Card } from '@polkadot/ui-app';
|
||||
import { styles as rowStyles } from '@polkadot/ui-app/Row';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
type Props = I18nProps & {
|
||||
children?: React.ReactNode,
|
||||
isApproved?: boolean,
|
||||
proposal: TreasuryProposal,
|
||||
proposalExtra?: React.ReactNode,
|
||||
proposalId: string
|
||||
};
|
||||
|
||||
class Item extends React.PureComponent<Props> {
|
||||
render () {
|
||||
const { children, className, proposalExtra, proposalId } = this.props;
|
||||
|
||||
return (
|
||||
<Card className={className}>
|
||||
<div className='ui--Row'>
|
||||
<div className='ui--Row-base'>
|
||||
<div className='ui--Row-details treasury--Item-header'>
|
||||
<h3 className='treasury--Item-header-id'>
|
||||
#{proposalId}
|
||||
</h3>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
{proposalExtra}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(styled(Item as React.ComponentClass<Props>)`
|
||||
${rowStyles}
|
||||
|
||||
.treasury--Item-header {
|
||||
margin: -0.5rem -0.5rem 0 0;
|
||||
}
|
||||
|
||||
.treasury--Approve-approved {
|
||||
color: green;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.treasury--Item-header-id {
|
||||
font-size: 2rem;
|
||||
line-height: 2rem;
|
||||
}
|
||||
`);
|
||||
155
packages/app-treasury/src/Overview/Proposal.tsx
Normal file
155
packages/app-treasury/src/Overview/Proposal.tsx
Normal file
@ -0,0 +1,155 @@
|
||||
// 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 { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Option, TreasuryProposal } from '@polkadot/types';
|
||||
import { Button, Icon, InputAddress, Labelled, Static } from '@polkadot/ui-app';
|
||||
import { withCalls, withMulti, withObservable } from '@polkadot/ui-api';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import { formatBalance } from '@polkadot/util';
|
||||
|
||||
import translate from '../translate';
|
||||
import Item from './Item';
|
||||
import Approve from './Approve';
|
||||
|
||||
type Props = I18nProps & {
|
||||
allAccounts?: SubjectInfo,
|
||||
isApproved: boolean,
|
||||
proposal?: TreasuryProposal | null,
|
||||
proposalId: string
|
||||
};
|
||||
|
||||
type State = {
|
||||
isApproveOpen: boolean
|
||||
};
|
||||
|
||||
class ProposalDisplay extends React.PureComponent<Props, State> {
|
||||
state: State = {
|
||||
isApproveOpen: false
|
||||
};
|
||||
|
||||
render () {
|
||||
const { isApproved, proposal, proposalId } = this.props;
|
||||
|
||||
if (!proposal) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Item
|
||||
isApproved={isApproved}
|
||||
proposal={proposal}
|
||||
proposalExtra={this.renderExtra()}
|
||||
proposalId={proposalId}
|
||||
>
|
||||
{this.renderAccessory()}
|
||||
</Item>
|
||||
);
|
||||
}
|
||||
|
||||
private renderAccessory () {
|
||||
const { allAccounts, isApproved, proposalId, t } = this.props;
|
||||
const { isApproveOpen } = this.state;
|
||||
|
||||
if (isApproved) {
|
||||
return (
|
||||
<h3 className='treasury--Approve-approved'>
|
||||
<Icon name='check' />
|
||||
{' '}
|
||||
{t('Approved')}
|
||||
</h3>
|
||||
);
|
||||
}
|
||||
|
||||
const hasAccounts = allAccounts && Object.keys(allAccounts).length !== 0;
|
||||
if (!hasAccounts) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className='ui--Row-buttons'>
|
||||
<Button.Group>
|
||||
<Button
|
||||
isPrimary
|
||||
label={t('Respond')}
|
||||
labelIcon='reply'
|
||||
onClick={this.showApprove}
|
||||
/>
|
||||
</Button.Group>
|
||||
</div>
|
||||
<Approve
|
||||
isOpen={isApproveOpen}
|
||||
onClose={this.hideApprove}
|
||||
proposalInfo={this.renderExtra()}
|
||||
proposalId={proposalId}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
private renderExtra () {
|
||||
const { isApproved, proposal, t } = this.props;
|
||||
|
||||
if (!proposal) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { bond, beneficiary, proposer, value } = proposal;
|
||||
|
||||
return (
|
||||
<div className={['treasury--Proposal-info', !isApproved && 'with-children'].join(' ')}>
|
||||
<Labelled label={t('proposed by')}>
|
||||
<InputAddress
|
||||
isDisabled
|
||||
value={proposer}
|
||||
withLabel={false}
|
||||
/>
|
||||
</Labelled>
|
||||
<Labelled label={t('beneficiary')}>
|
||||
<InputAddress
|
||||
isDisabled
|
||||
value={beneficiary}
|
||||
withLabel={false}
|
||||
/>
|
||||
</Labelled>
|
||||
<Static label={t('value')}>
|
||||
{formatBalance(value)}
|
||||
</Static>
|
||||
<Static label={t('bond')}>
|
||||
{formatBalance(bond)}
|
||||
</Static>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
private showApprove = (): void => {
|
||||
this.setState({
|
||||
isApproveOpen: true
|
||||
});
|
||||
}
|
||||
|
||||
private hideApprove = (): void => {
|
||||
this.setState({
|
||||
isApproveOpen: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default withMulti(
|
||||
ProposalDisplay,
|
||||
translate,
|
||||
withCalls<Props>(
|
||||
['query.treasury.proposals', {
|
||||
paramName: 'proposalId',
|
||||
propName: 'proposal',
|
||||
transform: (value: Option<TreasuryProposal>) =>
|
||||
value.unwrapOr(null)
|
||||
}]
|
||||
),
|
||||
withObservable(keyring.accounts.subject, { propName: 'allAccounts' })
|
||||
);
|
||||
120
packages/app-treasury/src/Overview/Proposals.tsx
Normal file
120
packages/app-treasury/src/Overview/Proposals.tsx
Normal file
@ -0,0 +1,120 @@
|
||||
// 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 { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { ProposalIndex } from '@polkadot/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { withCalls, withMulti } from '@polkadot/ui-api';
|
||||
import { Button, Column } from '@polkadot/ui-app';
|
||||
|
||||
import Proposal from './Proposal';
|
||||
import Propose from './Propose';
|
||||
import translate from '../translate';
|
||||
|
||||
type Props = I18nProps & {
|
||||
isApprovals?: boolean,
|
||||
treasury_approvals?: Array<BN>,
|
||||
treasury_proposalCount?: BN
|
||||
};
|
||||
|
||||
type State = {
|
||||
isProposeOpen: boolean,
|
||||
proposalIndices: Array<BN>
|
||||
};
|
||||
|
||||
class ProposalsBase extends React.PureComponent<Props> {
|
||||
state: State = {
|
||||
isProposeOpen: false,
|
||||
proposalIndices: [] as Array<BN>
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps ({ isApprovals = false, treasury_approvals = [] as Array<BN>, treasury_proposalCount = new BN(0) }: Props) {
|
||||
let proposalIndices: Array<BN> = [];
|
||||
|
||||
if (isApprovals) {
|
||||
proposalIndices = treasury_approvals;
|
||||
} else {
|
||||
for (let i = 0; i < treasury_proposalCount.toNumber(); i++) {
|
||||
proposalIndices.push(new BN(i));
|
||||
}
|
||||
}
|
||||
return { proposalIndices };
|
||||
}
|
||||
|
||||
render () {
|
||||
const { isApprovals, t } = this.props;
|
||||
const { isProposeOpen } = this.state;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Column
|
||||
emptyText={t(isApprovals ? 'No approved proposals' : 'No pending proposals')}
|
||||
headerText={t(isApprovals ? 'Approved' : 'Proposals')}
|
||||
buttons={!isApprovals && (
|
||||
<Button.Group>
|
||||
<Button
|
||||
isPrimary
|
||||
label={t('Submit a spend proposal')}
|
||||
labelIcon='add'
|
||||
onClick={this.togglePropose(true)}
|
||||
/>
|
||||
</Button.Group>
|
||||
)}
|
||||
>
|
||||
{this.renderProposals()}
|
||||
</Column>
|
||||
{!isApprovals && (
|
||||
<Propose
|
||||
isOpen={isProposeOpen}
|
||||
onClose={this.togglePropose(false)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
private renderProposals () {
|
||||
const { isApprovals } = this.props;
|
||||
const { proposalIndices } = this.state;
|
||||
|
||||
return proposalIndices.map((proposalId) => (
|
||||
<Proposal
|
||||
isApproved={isApprovals}
|
||||
proposalId={proposalId.toString()}
|
||||
key={proposalId.toString()}
|
||||
/>
|
||||
));
|
||||
}
|
||||
|
||||
private togglePropose = (isProposeOpen: boolean) => () => {
|
||||
this.setState({
|
||||
isProposeOpen
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const Proposals = withMulti(
|
||||
styled(ProposalsBase as React.ComponentClass<Props, State>)`
|
||||
.treasury--Proposals-inner {
|
||||
display: flex;
|
||||
flex-wrap: column;
|
||||
}
|
||||
`,
|
||||
translate,
|
||||
withCalls<Props>(
|
||||
[
|
||||
'query.treasury.approvals',
|
||||
{
|
||||
transform: (value: Array<ProposalIndex>) => value.map((proposalId) => new BN(proposalId))
|
||||
}
|
||||
],
|
||||
'query.treasury.proposalCount'
|
||||
)
|
||||
);
|
||||
|
||||
export default Proposals;
|
||||
export const Approvals = () => <Proposals isApprovals />;
|
||||
94
packages/app-treasury/src/Overview/Propose.tsx
Normal file
94
packages/app-treasury/src/Overview/Propose.tsx
Normal file
@ -0,0 +1,94 @@
|
||||
// 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 BN from 'bn.js';
|
||||
import React from 'react';
|
||||
|
||||
import { InputAddress, InputBalance } from '@polkadot/ui-app';
|
||||
import TxModal, { TxModalState, TxModalProps } from '@polkadot/ui-app/TxModal';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
type Props = TxModalProps;
|
||||
|
||||
type State = TxModalState & {
|
||||
beneficiary?: string,
|
||||
value: BN
|
||||
};
|
||||
|
||||
class Propose extends TxModal<Props, State> {
|
||||
state: State = {
|
||||
...this.defaultState,
|
||||
value: new BN(0)
|
||||
};
|
||||
|
||||
headerText = () => this.props.t('Submit a spend proposal');
|
||||
|
||||
txMethod = () => 'treasury.proposeSpend';
|
||||
txParams = () => {
|
||||
const { beneficiary, value } = this.state;
|
||||
|
||||
return [
|
||||
value, beneficiary
|
||||
];
|
||||
}
|
||||
|
||||
isDisabled = () => {
|
||||
const { accountId, beneficiary, value } = this.state;
|
||||
const hasValue = !!value && value.gtn(0);
|
||||
const hasBeneficiary = !!beneficiary;
|
||||
|
||||
return !accountId || !hasValue || !hasBeneficiary;
|
||||
}
|
||||
|
||||
renderContent = () => {
|
||||
const { t } = this.props;
|
||||
const { value } = this.state;
|
||||
const hasValue = !!value && value.gtn(0);
|
||||
|
||||
return (
|
||||
<>
|
||||
<InputAddress
|
||||
className='medium'
|
||||
label={t('beneficiary')}
|
||||
help={t('The account to which the proposed balance will be transferred if approved')}
|
||||
type='allPlus'
|
||||
onChange={this.onChangeBeneficiary}
|
||||
/>
|
||||
<InputBalance
|
||||
className='medium'
|
||||
isError={!hasValue}
|
||||
help={t('The amount that will be allocated from the treasury pot')}
|
||||
label={t('value')}
|
||||
onChange={this.onChangeValue}
|
||||
onEnter={this.sendTx}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
private nextState (newState: State): void {
|
||||
this.setState(
|
||||
(prevState: State): State => {
|
||||
const { accountId = prevState.accountId, beneficiary = prevState.beneficiary, value = prevState.value } = newState;
|
||||
|
||||
return {
|
||||
accountId,
|
||||
beneficiary,
|
||||
value
|
||||
} as State;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private onChangeBeneficiary = (beneficiary: string): void => {
|
||||
this.nextState({ beneficiary } as State);
|
||||
}
|
||||
|
||||
private onChangeValue = (value?: BN): void => {
|
||||
this.nextState({ value } as State);
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(Propose);
|
||||
59
packages/app-treasury/src/Overview/Summary.tsx
Normal file
59
packages/app-treasury/src/Overview/Summary.tsx
Normal file
@ -0,0 +1,59 @@
|
||||
// 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 { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { SummaryBox, CardSummary } from '@polkadot/ui-app';
|
||||
import { withCalls } from '@polkadot/ui-api';
|
||||
import { formatBalance, formatNumber } from '@polkadot/util';
|
||||
|
||||
import translate from '../translate';
|
||||
|
||||
type Props = I18nProps & {
|
||||
treasury_proposalCount?: BN,
|
||||
treasury_approvals?: Array<BN>,
|
||||
treasury_pot?: BN
|
||||
};
|
||||
|
||||
class Summary extends React.PureComponent<Props> {
|
||||
render () {
|
||||
const { treasury_proposalCount = new BN(0), treasury_approvals = [] as Array<BN>, treasury_pot = new BN(0), t } = this.props;
|
||||
const value = treasury_pot
|
||||
? treasury_pot.toString()
|
||||
: null;
|
||||
|
||||
return (
|
||||
<SummaryBox>
|
||||
<section>
|
||||
<CardSummary label={t('proposals')}>
|
||||
{formatNumber(treasury_proposalCount)}
|
||||
</CardSummary>
|
||||
<CardSummary label={t('approved')}>
|
||||
{treasury_approvals ? treasury_approvals.length : '0'}
|
||||
</CardSummary>
|
||||
</section>
|
||||
<section>
|
||||
<CardSummary label={t('pot')}>
|
||||
{
|
||||
value
|
||||
? `${formatBalance(value, false)}${treasury_pot.gtn(0) ? formatBalance.calcSi(value).value : ''}`
|
||||
: '-'
|
||||
}
|
||||
|
||||
</CardSummary>
|
||||
</section>
|
||||
</SummaryBox>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(
|
||||
withCalls<Props>(
|
||||
'query.treasury.proposalCount',
|
||||
'query.treasury.approvals',
|
||||
'query.treasury.pot'
|
||||
)(Summary)
|
||||
);
|
||||
35
packages/app-treasury/src/Overview/index.tsx
Normal file
35
packages/app-treasury/src/Overview/index.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
// 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 { AppProps, BareProps, I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Columar } from '@polkadot/ui-app';
|
||||
|
||||
import Summary from './Summary';
|
||||
import Proposals, { Approvals } from './Proposals';
|
||||
|
||||
type Props = AppProps & BareProps & I18nProps;
|
||||
|
||||
type State = {
|
||||
isProposeOpen: boolean
|
||||
};
|
||||
|
||||
export default class Overview extends React.PureComponent<Props, State> {
|
||||
state: State = {
|
||||
isProposeOpen: false
|
||||
};
|
||||
|
||||
render () {
|
||||
return (
|
||||
<>
|
||||
<Summary />
|
||||
<Columar>
|
||||
<Proposals />
|
||||
<Approvals />
|
||||
</Columar>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
210
packages/app-treasury/src/Settings.tsx
Normal file
210
packages/app-treasury/src/Settings.tsx
Normal file
@ -0,0 +1,210 @@
|
||||
// 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/ui-app/types';
|
||||
import { ApiProps } from '@polkadot/ui-api/types';
|
||||
import { BlockNumber, BalanceOf, Permill } from '@polkadot/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React from 'react';
|
||||
import { RouteComponentProps } from 'react-router';
|
||||
|
||||
import { Button, InputAddress, InputBalance, InputNumber, TxButton, TxComponent } from '@polkadot/ui-app';
|
||||
import { withCalls, withMulti } from '@polkadot/ui-api';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
type Props = I18nProps & ApiProps & RouteComponentProps & {
|
||||
basePath: string,
|
||||
proposalBond: Permill,
|
||||
proposalBondMinimum: BalanceOf,
|
||||
spendPeriod: BlockNumber,
|
||||
burn: Permill,
|
||||
pot: BalanceOf
|
||||
};
|
||||
|
||||
type State = {
|
||||
accountId?: string,
|
||||
proposalBond?: BN,
|
||||
proposalBondMinimum?: BN,
|
||||
spendPeriod?: BN,
|
||||
burn?: BN,
|
||||
pot?: BN
|
||||
};
|
||||
|
||||
class Settings extends TxComponent<Props, State> {
|
||||
state: State = {};
|
||||
|
||||
static getDerivedStateFromProps ({ proposalBond, proposalBondMinimum, spendPeriod, burn, pot }: Props, state: State) {
|
||||
const newState: State = {};
|
||||
|
||||
if (proposalBond && !state.proposalBond) {
|
||||
newState.proposalBond = new BN(proposalBond);
|
||||
}
|
||||
|
||||
if (proposalBondMinimum && !state.proposalBondMinimum) {
|
||||
newState.proposalBondMinimum = new BN(proposalBondMinimum);
|
||||
}
|
||||
|
||||
if (spendPeriod && !state.spendPeriod) {
|
||||
newState.spendPeriod = new BN(spendPeriod);
|
||||
}
|
||||
|
||||
if (burn && !state.burn) {
|
||||
newState.burn = new BN(burn);
|
||||
}
|
||||
|
||||
if (pot && !state.pot) {
|
||||
newState.pot = new BN(pot);
|
||||
}
|
||||
|
||||
return newState;
|
||||
}
|
||||
|
||||
render () {
|
||||
const { t } = this.props;
|
||||
const { accountId, proposalBond, proposalBondMinimum, spendPeriod, burn, pot } = this.state;
|
||||
|
||||
const hasConfig = !!proposalBond && !!proposalBondMinimum && !!spendPeriod && !!burn;
|
||||
const hasPot = !!pot;
|
||||
|
||||
return (
|
||||
<>
|
||||
<section>
|
||||
<InputAddress
|
||||
className='medium'
|
||||
label={t('using my account')}
|
||||
help={t('The account used to change your settings')}
|
||||
type='account'
|
||||
onChange={this.onChangeAccount}
|
||||
/>
|
||||
</section>
|
||||
{hasConfig && proposalBond && proposalBondMinimum && (
|
||||
<section>
|
||||
<h1>
|
||||
{t('configuration')}
|
||||
</h1>
|
||||
<InputBalance
|
||||
className='medium'
|
||||
value={proposalBond}
|
||||
help={t('Proposal bond')}
|
||||
label={t('proposal bond')}
|
||||
onChange={this.onChangeProposalBond}
|
||||
/>
|
||||
<InputBalance
|
||||
className='medium'
|
||||
value={proposalBondMinimum}
|
||||
help={t('Proposal bond minimum')}
|
||||
label={t('proposal bond minimum')}
|
||||
onChange={this.onChangeProposalBondMinimum}
|
||||
/>
|
||||
<InputNumber
|
||||
className='medium'
|
||||
help={t('Spend period')}
|
||||
label={t('spend period')}
|
||||
onChange={this.onChangeSpendPeriod}
|
||||
value={spendPeriod}
|
||||
/>
|
||||
<InputNumber
|
||||
className='medium'
|
||||
help={t('Burn percentage')}
|
||||
label={t('burn percentage')}
|
||||
onChange={this.onChangeBurn}
|
||||
value={burn}
|
||||
/>
|
||||
<Button.Group>
|
||||
<TxButton
|
||||
accountId={accountId}
|
||||
label={t('Submit')}
|
||||
tx='treasury.configure'
|
||||
params={[
|
||||
proposalBond.toString(),
|
||||
proposalBondMinimum.toString(),
|
||||
spendPeriod,
|
||||
burn
|
||||
]}
|
||||
/>
|
||||
</Button.Group>
|
||||
</section>
|
||||
)}
|
||||
{hasPot && (
|
||||
<section>
|
||||
<h1>
|
||||
{t('pot')}
|
||||
</h1>
|
||||
<InputBalance
|
||||
className='medium'
|
||||
defaultValue={pot}
|
||||
help={t('Pot')}
|
||||
label={t('pot size')}
|
||||
onChange={this.onChangePot}
|
||||
/>
|
||||
<Button.Group>
|
||||
<TxButton
|
||||
accountId={accountId}
|
||||
label={t('Submit')}
|
||||
tx='treasury.setPot'
|
||||
params={[pot]}
|
||||
/>
|
||||
</Button.Group>
|
||||
</section>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
private nextState (newState: State): void {
|
||||
this.setState(
|
||||
(prevState: State): State => {
|
||||
const { accountId = prevState.accountId, proposalBond = prevState.proposalBond, proposalBondMinimum = prevState.proposalBondMinimum, spendPeriod = prevState.spendPeriod, burn = prevState.burn, pot = prevState.pot } = newState;
|
||||
// const isValid = !!beneficiary && !!value && value.gt(new BN(0)) && !!accountId && accountId.length > 0;
|
||||
|
||||
return {
|
||||
accountId,
|
||||
proposalBond,
|
||||
proposalBondMinimum,
|
||||
spendPeriod,
|
||||
burn,
|
||||
pot
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private onChangeAccount = (accountId: string): void => {
|
||||
this.nextState({ accountId } as State);
|
||||
}
|
||||
|
||||
private onChangeProposalBond = (proposalBond?: BN): void => {
|
||||
this.nextState({ proposalBond } as State);
|
||||
}
|
||||
|
||||
private onChangeProposalBondMinimum = (proposalBondMinimum?: BN): void => {
|
||||
this.nextState({ proposalBondMinimum } as State);
|
||||
}
|
||||
|
||||
private onChangeSpendPeriod = (spendPeriod?: BN): void => {
|
||||
this.nextState({ spendPeriod } as State);
|
||||
}
|
||||
|
||||
private onChangeBurn = (burn?: BN): void => {
|
||||
this.nextState({ burn } as State);
|
||||
}
|
||||
|
||||
private onChangePot = (pot?: BN): void => {
|
||||
this.nextState({ pot } as State);
|
||||
}
|
||||
}
|
||||
|
||||
export default withMulti(
|
||||
Settings,
|
||||
translate,
|
||||
withCalls<Props>(
|
||||
['query.treasury.proposalBond', { propName: 'proposalBond' }],
|
||||
['query.treasury.proposalBondMinimum', { propName: 'proposalBondMinimum' }],
|
||||
['query.treasury.spendPeriod', { propName: 'spendPeriod' }],
|
||||
['query.treasury.burn', { propName: 'burn' }],
|
||||
['query.treasury.pot', { propName: 'pot' }]
|
||||
)
|
||||
);
|
||||
67
packages/app-treasury/src/index.tsx
Normal file
67
packages/app-treasury/src/index.tsx
Normal file
@ -0,0 +1,67 @@
|
||||
// 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 { AppProps, BareProps, I18nProps } from '@polkadot/ui-app/types';
|
||||
import { TabItem } from '@polkadot/ui-app/Tabs';
|
||||
|
||||
import React from 'react';
|
||||
import { Route, Switch } from 'react-router';
|
||||
import { HelpOverlay, Tabs } from '@polkadot/ui-app';
|
||||
|
||||
import basicMd from './md/basic.md';
|
||||
import Overview from './Overview';
|
||||
import Settings from './Settings';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
type Props = AppProps & BareProps & I18nProps;
|
||||
|
||||
type State = {
|
||||
tabs: Array<TabItem>
|
||||
};
|
||||
|
||||
class App extends React.PureComponent<Props, State> {
|
||||
constructor (props: Props) {
|
||||
super(props);
|
||||
|
||||
const { t } = props;
|
||||
|
||||
this.state = {
|
||||
tabs: [
|
||||
{
|
||||
isRoot: true,
|
||||
name: 'overview',
|
||||
text: t('Treasury overview')
|
||||
},
|
||||
{
|
||||
name: 'settings',
|
||||
text: t('Edit settings')
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
render () {
|
||||
const { basePath } = this.props;
|
||||
const { tabs } = this.state;
|
||||
|
||||
return (
|
||||
<main className='treasury--App'>
|
||||
<HelpOverlay md={basicMd} />
|
||||
<header>
|
||||
<Tabs
|
||||
basePath={basePath}
|
||||
items={tabs}
|
||||
/>
|
||||
</header>
|
||||
<Switch>
|
||||
<Route path={`${basePath}/settings`} component={Settings} />
|
||||
<Route component={Overview} />
|
||||
</Switch>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(App);
|
||||
3
packages/app-treasury/src/md/basic.md
Normal file
3
packages/app-treasury/src/md/basic.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Treasury
|
||||
|
||||
This application lets you view and vote to approve or deny treasury spend proposals.
|
||||
7
packages/app-treasury/src/translate.ts
Normal file
7
packages/app-treasury/src/translate.ts
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2019 @polkadot/app-explorer 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 { withTranslation } from 'react-i18next';
|
||||
|
||||
export default withTranslation(['democracy', 'ui']);
|
||||
@ -22,6 +22,7 @@ import storage from './storage';
|
||||
import sudo from './sudo';
|
||||
import toolbox from './toolbox';
|
||||
import transfer from './transfer';
|
||||
import treasury from './treasury';
|
||||
|
||||
const routes: Routes = appSettings.uiMode === 'light'
|
||||
? ([] as Routes).concat(
|
||||
@ -48,6 +49,7 @@ const routes: Routes = appSettings.uiMode === 'light'
|
||||
staking,
|
||||
democracy,
|
||||
council,
|
||||
treasury,
|
||||
null,
|
||||
contracts,
|
||||
storage,
|
||||
|
||||
24
packages/apps-routing/src/treasury.ts
Normal file
24
packages/apps-routing/src/treasury.ts
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2017-2019 @polkadot/apps-routing 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 { Routes } from './types';
|
||||
|
||||
import Treasury from '@polkadot/app-treasury';
|
||||
|
||||
export default ([
|
||||
{
|
||||
Component: Treasury,
|
||||
display: {
|
||||
needsAccounts: true,
|
||||
needsApi: [
|
||||
'tx.treasury.proposeSpend'
|
||||
]
|
||||
},
|
||||
i18n: {
|
||||
defaultValue: 'Treasury'
|
||||
},
|
||||
icon: 'gem',
|
||||
name: 'treasury'
|
||||
}
|
||||
] as Routes);
|
||||
@ -2,68 +2,67 @@
|
||||
// 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/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import Collection, { CollectionProps, CollectionState, collectionStyles } from './Collection';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
type Props = I18nProps & {
|
||||
buttons?: React.ReactNode,
|
||||
children: React.ReactNode,
|
||||
className?: string,
|
||||
emptyText?: string
|
||||
};
|
||||
type Props = CollectionProps;
|
||||
|
||||
class CardGrid extends React.PureComponent<Props> {
|
||||
render () {
|
||||
const { buttons, children, className } = this.props;
|
||||
type State = CollectionState;
|
||||
|
||||
class CardGrid extends Collection<Props, State> {
|
||||
static getDerivedStateFromProps ({ children }: Props) {
|
||||
if (!children || (children as Array<any>).length <= 0) {
|
||||
return this.empty();
|
||||
return { isEmpty: true, showHeader: false };
|
||||
}
|
||||
return { isEmpty: false, showHeader: true };
|
||||
}
|
||||
|
||||
renderEmpty () {
|
||||
const { buttons, headerText, t } = this.props;
|
||||
|
||||
if (headerText) {
|
||||
return super.renderEmpty();
|
||||
}
|
||||
|
||||
const emptyText = this.props.emptyText || t('No items');
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<div className='ui--CardGrid-empty'>
|
||||
<h2>
|
||||
{emptyText}
|
||||
</h2>
|
||||
{buttons && (
|
||||
<div className='ui--CardGrid-buttons'>
|
||||
{buttons}
|
||||
</div>
|
||||
)}
|
||||
<div className='ui--CardGrid-grid'>
|
||||
{children}
|
||||
<div className='ui--CardGrid-spacer' />
|
||||
<div className='ui--CardGrid-spacer' />
|
||||
<div className='ui--CardGrid-spacer' />
|
||||
</div>
|
||||
<div className='ui--CardGrid-spacer' />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
empty () {
|
||||
const { buttons, className, emptyText, t } = this.props;
|
||||
renderCollection () {
|
||||
const { children } = this.props;
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<div className='ui--CardGrid-empty'>
|
||||
<h2>
|
||||
{emptyText || t('No items')}
|
||||
</h2>
|
||||
{buttons && (
|
||||
<div className='ui--CardGrid-buttons'>
|
||||
{buttons}
|
||||
</div>
|
||||
)}
|
||||
<div className='ui--CardGrid-spacer' />
|
||||
</div>
|
||||
<div className='ui--CardGrid-grid'>
|
||||
{children}
|
||||
<div className='ui--CardGrid-spacer' />
|
||||
<div className='ui--CardGrid-spacer' />
|
||||
<div className='ui--CardGrid-spacer' />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default translate(
|
||||
styled(CardGrid)`
|
||||
styled(CardGrid as React.ComponentClass<Props, State>)`
|
||||
${collectionStyles}
|
||||
|
||||
.ui--CardGrid-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
@ -75,6 +74,10 @@ export default translate(
|
||||
}
|
||||
}
|
||||
|
||||
.ui--CardGrid-lowercase {
|
||||
text-transform: lowercase;
|
||||
}
|
||||
|
||||
.ui--Card,
|
||||
.ui--CardGrid-spacer {
|
||||
flex: 1 1;
|
||||
|
||||
135
packages/ui-app/src/Collection.tsx
Normal file
135
packages/ui-app/src/Collection.tsx
Normal file
@ -0,0 +1,135 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-app 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/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
export type CollectionProps = I18nProps & {
|
||||
buttons?: React.ReactNode,
|
||||
children: React.ReactNode,
|
||||
className?: string,
|
||||
headerText?: React.ReactNode,
|
||||
emptyText?: React.ReactNode
|
||||
};
|
||||
|
||||
export type CollectionState = {
|
||||
isEmpty: boolean,
|
||||
showHeader?: boolean
|
||||
};
|
||||
|
||||
export const collectionStyles = `
|
||||
.ui--Collection-header {
|
||||
display: flex;
|
||||
margin-bottom: 0.5rem;
|
||||
min-height: 2.75rem;
|
||||
|
||||
h1 {
|
||||
flex: 1 1;
|
||||
margin: 0;
|
||||
text-transform: lowercase;
|
||||
}
|
||||
}
|
||||
|
||||
.ui--Collection-lowercase {
|
||||
text-transform: lowercase;
|
||||
}
|
||||
`;
|
||||
|
||||
export default class Collection<P extends CollectionProps, S extends CollectionState> extends React.PureComponent<P, S> {
|
||||
constructor (props: P) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
isEmpty: props.children && (props.children as Array<any>).length > 0
|
||||
} as S;
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps ({ children }: CollectionProps) {
|
||||
if (!children || (children as Array<any>).length <= 0) {
|
||||
return { isEmpty: true };
|
||||
}
|
||||
return { isEmpty: false };
|
||||
}
|
||||
|
||||
render () {
|
||||
const { className } = this.props;
|
||||
const { isEmpty, showHeader = true } = this.state;
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
{showHeader && this.renderHeader()}
|
||||
{isEmpty ?
|
||||
this.renderEmpty() :
|
||||
this.renderCollection()
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
protected renderHeader () {
|
||||
const { buttons, headerText } = this.props;
|
||||
|
||||
return (
|
||||
<div className='ui--Collection-header'>
|
||||
<h1>
|
||||
{headerText && headerText}
|
||||
</h1>
|
||||
{buttons && (
|
||||
<div className='ui--Collection-buttons'>
|
||||
{buttons}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
protected renderEmpty () {
|
||||
const { t } = this.props;
|
||||
|
||||
const emptyText = this.props.emptyText || t('No items');
|
||||
|
||||
// if (headerText) {
|
||||
return (
|
||||
<article>
|
||||
<div className='ui--Collection-lowercase'>
|
||||
{emptyText}
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
// }
|
||||
|
||||
// return (
|
||||
// <div className='ui--CardGrid-empty'>
|
||||
// <h2>
|
||||
// {emptyText}
|
||||
// </h2>
|
||||
// {buttons && (
|
||||
// <div className='ui--CardGrid-buttons'>
|
||||
// {buttons}
|
||||
// </div>
|
||||
// )}
|
||||
// <div className='ui--CardGrid-spacer' />
|
||||
// </div>
|
||||
// );
|
||||
}
|
||||
|
||||
protected renderCollection (): React.ReactNode {
|
||||
const { children } = this.props;
|
||||
return children;
|
||||
}
|
||||
|
||||
// renderGrid () {
|
||||
// const { children } = this.props;
|
||||
//
|
||||
// return (
|
||||
// <div className='ui--CardGrid-grid'>
|
||||
// {children}
|
||||
// <div className='ui--CardGrid-spacer' />
|
||||
// <div className='ui--CardGrid-spacer' />
|
||||
// <div className='ui--CardGrid-spacer' />
|
||||
// </div>
|
||||
// );
|
||||
// }
|
||||
}
|
||||
@ -5,49 +5,75 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode,
|
||||
className?: string,
|
||||
header: React.ReactNode
|
||||
};
|
||||
import Collection, { CollectionProps, CollectionState, collectionStyles } from './Collection';
|
||||
|
||||
class Column extends React.PureComponent<Props> {
|
||||
import translate from './translate';
|
||||
|
||||
type Props = CollectionProps;
|
||||
|
||||
type State = CollectionState;
|
||||
|
||||
class Column extends Collection<Props, State> {
|
||||
render () {
|
||||
const { children, className, header } = this.props;
|
||||
const { className } = this.props;
|
||||
const { isEmpty } = this.state;
|
||||
|
||||
return (
|
||||
<div className={`ui--Column ${className}`}>
|
||||
<h1>{header}</h1>
|
||||
<article className='container'>
|
||||
{children}
|
||||
</article>
|
||||
{this.renderHeader()}
|
||||
{isEmpty ?
|
||||
this.renderEmpty() :
|
||||
this.renderCollection()
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
renderCollection () {
|
||||
const { children } = this.props;
|
||||
return (
|
||||
<article className='container'>
|
||||
{children}
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
// renderEmpty () {
|
||||
// const { emptyText } = this.props;
|
||||
// return (
|
||||
// <article className='container'>
|
||||
// {emptyText}
|
||||
// </article>
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
export default styled(Column)`
|
||||
box-sizing: border-box;
|
||||
flex: 1 1;
|
||||
margin: 0;
|
||||
padding: 0.5rem;
|
||||
export default translate(
|
||||
styled(Column as React.ComponentClass<Props, State>)`
|
||||
${collectionStyles}
|
||||
|
||||
.container {
|
||||
box-sizing: border-box;
|
||||
flex: 1 1;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
padding: 0.5rem;
|
||||
|
||||
article {
|
||||
border: none;
|
||||
.container {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
article {
|
||||
border: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
article+article {
|
||||
border-top: 1px solid #f2f2f2;
|
||||
}
|
||||
}
|
||||
|
||||
article+article {
|
||||
border-top: 1px solid #f2f2f2;
|
||||
@media (min-width: 1025px) {
|
||||
max-width: 50%;
|
||||
min-width: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 1025px) {
|
||||
max-width: 50%;
|
||||
min-width: 50%;
|
||||
}
|
||||
`;
|
||||
`
|
||||
);
|
||||
|
||||
@ -296,7 +296,7 @@ export default withMulti(
|
||||
padding-left: 4rem;
|
||||
}
|
||||
|
||||
&.hideAddress .ui--KeyPair .ui--KeyPair-address {
|
||||
&.hideAddress .ui--KeyPair .address {
|
||||
flex: 0;
|
||||
max-width: 0;
|
||||
}
|
||||
|
||||
184
packages/ui-app/src/TxModal.tsx
Normal file
184
packages/ui-app/src/TxModal.tsx
Normal file
@ -0,0 +1,184 @@
|
||||
// Copyright 2017-2019 @polkadot/app-contracts 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/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Button, InputAddress, Modal, TxButton, TxComponent } from '@polkadot/ui-app';
|
||||
|
||||
export type TxModalProps = I18nProps & {
|
||||
isOpen: boolean,
|
||||
onSubmit?: () => void,
|
||||
onClose?: () => void
|
||||
onSuccess?: () => void,
|
||||
onFailed?: () => void
|
||||
};
|
||||
|
||||
export type TxModalState = {
|
||||
accountId?: string | null,
|
||||
isBusy: boolean
|
||||
};
|
||||
|
||||
class TxModal<P extends TxModalProps, S extends TxModalState> extends TxComponent<P, S> {
|
||||
protected defaultState: S = {
|
||||
accountId: null
|
||||
} as S;
|
||||
|
||||
state: S = this.defaultState;
|
||||
|
||||
componentWillReceiveProps ({ isOpen }: P, _: S) {
|
||||
if (isOpen && !this.props.isOpen && !this.state.isBusy) {
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const { isOpen } = this.props;
|
||||
|
||||
return (
|
||||
<Modal
|
||||
className='ui--Modal'
|
||||
dimmer='inverted'
|
||||
onClose={this.onClose}
|
||||
open={isOpen}
|
||||
>
|
||||
<Modal.Header>
|
||||
{this.headerText()}
|
||||
</Modal.Header>
|
||||
<Modal.Content>
|
||||
{this.renderPreContent()}
|
||||
{this.renderInputAccount()}
|
||||
{this.renderContent()}
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
{this.renderButtons()}
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
protected headerText = (): React.ReactNode => '';
|
||||
protected accountHelp = (): React.ReactNode => this.props.t('Select the account to use for this action.');
|
||||
protected accountLabel = (): React.ReactNode => this.props.t('using my account');
|
||||
protected submitLabel = (): React.ReactNode => this.props.t('Submit');
|
||||
protected cancelLabel = (): React.ReactNode => this.props.t('Cancel');
|
||||
|
||||
protected onClose = () => {
|
||||
const { onClose } = this.props;
|
||||
|
||||
onClose && onClose();
|
||||
}
|
||||
|
||||
protected onChangeAccount = (accountId: string | null): void => {
|
||||
this.setState({ accountId });
|
||||
}
|
||||
|
||||
protected onSubmit = (): void => {
|
||||
const { onSubmit } = this.props;
|
||||
|
||||
this.toggleBusy(true);
|
||||
onSubmit && onSubmit();
|
||||
}
|
||||
|
||||
protected onSuccess = (): void => {
|
||||
const { onClose, onSuccess } = this.props;
|
||||
|
||||
this.toggleBusy(false);
|
||||
onSuccess && onSuccess();
|
||||
onClose && onClose();
|
||||
}
|
||||
|
||||
protected onFailed = (): void => {
|
||||
const { onFailed } = this.props;
|
||||
|
||||
this.toggleBusy(false);
|
||||
onFailed && onFailed();
|
||||
}
|
||||
|
||||
isDisabled = (): boolean => {
|
||||
const { accountId } = this.state;
|
||||
|
||||
return !accountId;
|
||||
}
|
||||
|
||||
protected toggleBusy = (isBusy: boolean) => () => {
|
||||
this.setState({
|
||||
isBusy
|
||||
});
|
||||
}
|
||||
|
||||
protected txMethod: () => string = () => '';
|
||||
protected txParams: () => Array<any> = () => [];
|
||||
|
||||
protected renderContent: () => React.ReactNode | null = () => null;
|
||||
protected renderPreContent: () => React.ReactNode | null = () => null;
|
||||
|
||||
protected renderButtons: () => React.ReactNode | null = () => {
|
||||
return (
|
||||
<Button.Group>
|
||||
{this.renderCancelButton()}
|
||||
{this.renderTxButton()}
|
||||
</Button.Group>
|
||||
);
|
||||
}
|
||||
|
||||
protected renderInputAccount () {
|
||||
const { accountId, isBusy } = this.state;
|
||||
|
||||
return (
|
||||
<InputAddress
|
||||
defaultValue={accountId}
|
||||
help={this.accountHelp()}
|
||||
isDisabled={isBusy}
|
||||
isInput={false}
|
||||
label={this.accountLabel()}
|
||||
onChange={this.onChangeAccount}
|
||||
type='account'
|
||||
value={accountId}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
protected renderTxButton () {
|
||||
const { accountId } = this.state;
|
||||
|
||||
return (
|
||||
<TxButton
|
||||
accountId={accountId}
|
||||
isDisabled={this.isDisabled()}
|
||||
isPrimary
|
||||
label={this.submitLabel()}
|
||||
onClick={this.onSubmit}
|
||||
onFailed={this.onFailed}
|
||||
onSuccess={this.onSuccess}
|
||||
params={this.txParams()}
|
||||
ref={this.button}
|
||||
tx={this.txMethod()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
protected renderCancelButton () {
|
||||
const { t } = this.props;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
isNegative
|
||||
onClick={this.onClose}
|
||||
label={t('Cancel')}
|
||||
/>
|
||||
<Button.Or />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
protected reset = () => {
|
||||
this.setState(
|
||||
this.defaultState
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default TxModal;
|
||||
@ -63,5 +63,6 @@ export { default as Toggle } from './Toggle';
|
||||
export { default as Tooltip } from './Tooltip';
|
||||
export { default as TxButton } from './TxButton';
|
||||
export { default as TxComponent } from './TxComponent';
|
||||
export { default as TxModal } from './TxModal';
|
||||
|
||||
export { default as media } from './media';
|
||||
|
||||
@ -35,6 +35,8 @@
|
||||
"@polkadot/app-toolbox/*": [ "packages/app-toolbox/src/*" ],
|
||||
"@polkadot/app-transfer": [ "packages/app-transfer/src" ],
|
||||
"@polkadot/app-transfer/*": [ "packages/app-transfer/src/*" ],
|
||||
"@polkadot/app-treasury": [ "packages/app-treasury/src" ],
|
||||
"@polkadot/app-treasury/*": [ "packages/app-treasury/src/*" ],
|
||||
"@polkadot/apps-routing": [ "packages/apps-routing/src" ],
|
||||
"@polkadot/apps-routing/*": [ "packages/apps-routing/src/*" ],
|
||||
"@polkadot/ui-api": [ "packages/ui-api/src" ],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user