-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Approve.tsx
115 lines (93 loc) · 3.08 KB
/
Approve.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2017-2020 @polkadot/app-treasury 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, BlockNumber } from '@polkadot/types/interfaces';
import { ApiProps } from '@polkadot/react-api/types';
import { I18nProps } from '@polkadot/react-components/types';
import React from 'react';
import { Button, Dropdown } from '@polkadot/react-components';
import { withMulti, withApi, withCalls } from '@polkadot/react-api/hoc';
import TxModal, { TxModalProps, TxModalState } from '@polkadot/react-components/TxModal';
import translate from '../translate';
interface Props extends I18nProps, ApiProps, TxModalProps {
isApproved?: boolean;
proposalInfo?: React.ReactNode;
proposalId: string;
threshold: number;
}
interface State extends TxModalState {
isApproving: boolean;
}
class Approve extends TxModal<Props, State> {
public state: State = {
...this.defaultState,
isApproving: false
};
private approveOptions = (): { text: string; value: boolean }[] => [
{ text: this.props.t('Aye, I approve'), value: true },
{ text: this.props.t('Nay, I do not approve'), value: false }
]
protected headerText = (): string => this.props.t('Approve or reject proposal');
protected txMethod = (): string => 'council.propose';
protected txParams = (): [number, any] => {
const { api, proposalId, threshold } = this.props;
const { isApproving } = this.state;
const method = isApproving ? 'approveProposal' : 'rejectProposal';
const spendProposal = api.tx.treasury[method](proposalId);
return [threshold, spendProposal];
}
protected renderTrigger = (): React.ReactNode => {
const { api, t } = this.props;
// disable voting for 1.x (we only use elections here)
if (!api.query.elections) {
return null;
}
return (
<div className='ui--Row-buttons'>
<Button.Group>
<Button
icon='reply'
isPrimary
label={t('Respond')}
onClick={this.showModal}
/>
</Button.Group>
</div>
);
}
protected renderPreContent = (): React.ReactNode => {
const { proposalInfo = null } = this.props;
if (!proposalInfo) {
return null;
}
return proposalInfo;
}
protected renderContent = (): React.ReactNode => {
const { t } = this.props;
const { isApproving } = this.state;
return (
<Dropdown
help={t('Propose a majority council motion to either approve or reject this spend proposal')}
label={t('proposed council action')}
onChange={this.onChangeApproving}
options={this.approveOptions()}
value={isApproving}
/>
);
}
private onChangeApproving = (isApproving: boolean): void => {
this.setState({ isApproving });
}
}
export default withMulti(
Approve,
translate,
withApi,
withCalls(
['query.elections.members', {
propName: 'threshold',
transform: (value: [AccountId, BlockNumber][]): number =>
Math.ceil(value.length * 0.5)
}]
)
);