-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
TipEndorse.tsx
72 lines (66 loc) · 2.1 KB
/
TipEndorse.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
// 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 BN from 'bn.js';
import React, { useState } from 'react';
import { Button, InputAddress, InputBalance, Modal, TxButton } from '@polkadot/react-components';
import { useToggle } from '@polkadot/react-hooks';
import { useTranslation } from '../translate';
interface Props {
hash: string;
isMember: boolean;
members: string[];
}
function TipEndorse ({ hash, isMember, members }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const [isOpen, toggleOpen] = useToggle();
const [accountId, setAccountId] = useState<string | null>(null);
const [value, setValue] = useState<BN | undefined>();
const hasValue = value?.gtn(0);
return (
<>
<Button
icon='check'
isDisabled={!isMember}
label={t('Endorse')}
onClick={toggleOpen}
/>
{isOpen && (
<Modal
header={t('Submit tip endorsement')}
size='small'
>
<Modal.Content>
<InputAddress
filter={members}
help={t('Select the account you wish to submit the tip from.')}
label={t('submit with account')}
onChange={setAccountId}
type='account'
withLabel
/>
<InputBalance
help={t('The tip amount that should be allocated')}
isError={!hasValue}
label={t('value')}
onChange={setValue}
/>
</Modal.Content>
<Modal.Actions onCancel={toggleOpen}>
<TxButton
accountId={accountId}
icon='add'
isDisabled={!accountId || !hasValue }
isPrimary
label={t('Submit tip')}
onStart={toggleOpen}
params={[hash, value]}
tx='treasury.tip'
/>
</Modal.Actions>
</Modal>
)}
</>
);
}
export default React.memo(TipEndorse);