-
Notifications
You must be signed in to change notification settings - Fork 295
/
WalletPublicKeyDialog.tsx
143 lines (135 loc) · 4.25 KB
/
WalletPublicKeyDialog.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import { defineMessages, intlShape } from 'react-intl';
import { Input } from 'react-polymorph/lib/components/Input';
import vjf from 'mobx-react-form/lib/validators/VJF';
import styles from './PublicKeyDialog.scss';
import ReactToolboxMobxForm from '../../../utils/ReactToolboxMobxForm';
import { submitOnEnter } from '../../../utils/form';
import globalMessages from '../../../i18n/global-messages';
import { FORM_VALIDATION_DEBOUNCE_WAIT } from '../../../config/timingConfig';
import Dialog from '../../widgets/Dialog';
import DialogCloseButton from '../../widgets/DialogCloseButton';
import LocalizableError from '../../../i18n/LocalizableError';
import type { ReactIntlMessage } from '../../../types/i18nTypes';
const messages: { [string]: ReactIntlMessage } = defineMessages({
title: {
id: 'wallet.settings.walletPublicKeyDialog.title',
defaultMessage: '!!!Reveal wallet public key',
description: 'Title "Choose a stake pool" on the reveal Wallet Id dialog.',
},
description: {
id: 'wallet.settings.walletPublicKeyDialog.description',
defaultMessage:
'!!!Please enter your spending password to reveal your wallet’s public key.',
description: 'Description on the reveal Wallet Id dialog.',
},
buttonLabel: {
id: 'wallet.settings.walletPublicKeyDialog.button',
defaultMessage: '!!!Reveal wallet public key',
description: 'Description on the reveal Wallet Id dialog.',
},
});
type Props = {
onRevealPublicKey: Function,
onClose: Function,
error: ?LocalizableError,
hasReceivedWalletPublicKey: boolean,
walletName: string,
};
@observer
export default class WalletPublicKeyDialog extends Component<Props> {
static contextTypes = {
intl: intlShape.isRequired,
};
componentDidUpdate() {
const { hasReceivedWalletPublicKey, onClose } = this.props;
if (hasReceivedWalletPublicKey) {
onClose();
}
}
form = new ReactToolboxMobxForm(
{
fields: {
spendingPassword: {
type: 'password',
label: this.context.intl.formatMessage(
globalMessages.spendingPasswordLabel
),
placeholder: this.context.intl.formatMessage(
globalMessages.spendingPasswordPlaceholder
),
value: '',
validators: [
({ field }) => {
if (field.value === '') {
return [
false,
this.context.intl.formatMessage(
globalMessages.fieldIsRequired
),
];
}
return [true];
},
],
},
},
},
{
plugins: { vjf: vjf() },
options: {
validateOnChange: true,
validationDebounceWait: FORM_VALIDATION_DEBOUNCE_WAIT,
},
}
);
submit = () => {
this.form.submit({
onSuccess: (form) => {
const { spendingPassword } = form.values();
const { onRevealPublicKey } = this.props;
onRevealPublicKey({ spendingPassword });
},
});
};
handleSubmitOnEnter = submitOnEnter.bind(this, this.submit);
render() {
const { intl } = this.context;
const { onClose, error, walletName } = this.props;
const { form } = this;
const spendingPasswordField = form.$('spendingPassword');
const actions = [
{
label: intl.formatMessage(messages.buttonLabel),
onClick: this.submit,
primary: true,
disabled: !this.form.isValid,
},
];
return (
<Dialog
title={intl.formatMessage(messages.title)}
subtitle={walletName}
actions={actions}
closeOnOverlayClick
onClose={onClose}
className={styles.dialog}
closeButton={<DialogCloseButton onClose={onClose} />}
>
<div className={styles.description}>
{intl.formatMessage(messages.description)}
</div>
<Input
className={styles.spendingPassword}
{...spendingPasswordField.bind()}
error={spendingPasswordField.error}
onKeyPress={this.handleSubmitOnEnter}
autoFocus
/>
{error && <p className={styles.error}>{intl.formatMessage(error)}</p>}
</Dialog>
);
}
}