-
Notifications
You must be signed in to change notification settings - Fork 295
/
ExportWalletToFileDialog.tsx
210 lines (189 loc) · 6 KB
/
ExportWalletToFileDialog.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// @flow
import React, { Component } from 'react';
import type { Node } from 'react';
import { observer } from 'mobx-react';
import classnames from 'classnames';
import { defineMessages, intlShape, FormattedHTMLMessage } from 'react-intl';
import vjf from 'mobx-react-form/lib/validators/VJF';
// import { Input } from 'react-polymorph/lib/components/Input';
// import { InputSkin } from 'react-polymorph/lib/skins/simple/InputSkin';
import DialogCloseButton from '../../widgets/DialogCloseButton';
import ReactToolboxMobxForm from '../../../utils/ReactToolboxMobxForm';
import globalMessages from '../../../i18n/global-messages';
import Dialog from '../../widgets/Dialog';
import LocalizableError from '../../../i18n/LocalizableError';
import styles from './ExportWalletToFileDialog.scss';
import { FORM_VALIDATION_DEBOUNCE_WAIT } from '../../../config/timingConfig';
import { submitOnEnter } from '../../../utils/form';
const messages = defineMessages({
headline: {
id: 'wallet.settings.exportToFile.dialog.headline',
defaultMessage: '!!!Export Wallet',
description: 'headline for "export wallet to file" dialog.',
},
introduction: {
id: 'wallet.settings.exportToFile.dialog.introduction',
defaultMessage:
'!!!You are exporting <strong>{walletName}</strong> to a file.',
description: 'headline for "export wallet to file" dialog.',
},
exportButtonLabel: {
id: 'wallet.settings.exportToFile.dialog.submit.label',
defaultMessage: '!!!Export',
description: 'Label for export wallet to file submit button.',
},
// TODO: re-enable when we have full/readOnly exports
// fullTabTitle: {
// id: 'wallet.export.choices.tab.title.full',
// defaultMessage: '!!!Full',
// description: 'Tab title "Full" on wallet export dialog.'
// },
// readOnlyTabTitle: {
// id: 'wallet.export.choices.tab.title.readOnly',
// defaultMessage: '!!!Read-only',
// description: 'Tab title "Read-only" on wallet export dialog.'
// },
});
type ExportType = 'full' | 'readOnly';
const EXPORT_TYPE = {
FULL: 'full',
READ_ONLY: 'readOnly',
};
export type OnSubmitParams = $Exact<{
exportType: ExportType,
password: ?string,
}>;
type Props = {
walletName: string,
isSubmitting: boolean,
onSubmit: (OnSubmitParams) => Promise<void>,
onClose: () => void,
error?: ?LocalizableError,
};
type State = {
exportType: ExportType,
};
@observer
export default class ExportWalletToFileDialog extends Component<Props, State> {
static contextTypes = {
intl: intlShape.isRequired,
};
constructor(props: Props, children: Node) {
super(props, children);
this.state = {
exportType: EXPORT_TYPE.FULL,
};
}
// onChangeExportType(exportType: ExportType) {
// this.setState({ exportType });
// }
form = new ReactToolboxMobxForm(
{
fields: {
spendingPassword: {
type: 'password',
label: this.context.intl.formatMessage(
globalMessages.spendingPasswordLabel
),
placeholder: this.context.intl.formatMessage(
globalMessages.spendingPasswordPlaceholder
),
value: '',
validators: [
() => {
// 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: async (form) => {
const { spendingPassword } = form.values();
const formData = {
exportType: this.state.exportType,
password: spendingPassword || null,
};
await this.props.onSubmit(formData);
},
});
};
handleSubmitOnEnter = submitOnEnter.bind(this, this.submit);
render() {
// const { form } = this;
const { intl } = this.context;
const { onClose, walletName, isSubmitting, error } = this.props;
// const { exportType } = this.state;
const dialogClasses = classnames([styles.component, 'WalletExportDialog']);
const actions = [
{
className: isSubmitting ? styles.isSubmitting : null,
label: intl.formatMessage(messages.exportButtonLabel),
primary: true,
onClick: this.submit,
},
];
// const spendingPasswordField = form.$('spendingPassword');
return (
<Dialog
className={dialogClasses}
title={intl.formatMessage(messages.headline)}
actions={actions}
closeOnOverlayClick
onClose={onClose}
closeButton={<DialogCloseButton />}
>
{/* TODO: re-enable when we have full/readOnly exports
<div className={styles.choices}>
<button
className={exportType === 'full' ? styles.activeButton : ''}
onClick={() => this.onChangeExportType('full')}
>
{intl.formatMessage(messages.fullTabTitle)}
</button>
<button
disabled
className={exportType === 'readOnly' ? styles.activeButton : ''}
onClick={() => this.onChangeExportType('readOnly')}
>
{intl.formatMessage(messages.readOnlyTabTitle)}
</button>
</div>
*/}
<div className={styles.introduction}>
<FormattedHTMLMessage
{...messages.introduction}
values={{ walletName }}
/>
</div>
{/*
<Input
className={styles.spendingPassword}
{...spendingPasswordField.bind()}
error={spendingPasswordField.error}
skin={InputSkin}
onKeyPress={this.handleSubmitOnEnter}
/>
*/}
{error && <p className={styles.error}>{intl.formatMessage(error)}</p>}
</Dialog>
);
}
}