-
Notifications
You must be signed in to change notification settings - Fork 295
/
WalletTypeDialog.tsx
332 lines (323 loc) · 12.5 KB
/
WalletTypeDialog.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// @flow
import React, { Component, Fragment } from 'react';
import { defineMessages, intlShape, FormattedHTMLMessage } from 'react-intl';
import { set } from 'lodash';
import { Checkbox } from 'react-polymorph/lib/components/Checkbox';
import { CheckboxSkin } from 'react-polymorph/lib/skins/simple/CheckboxSkin';
import RadioSet from '../../widgets/RadioSet';
import WalletRestoreDialog from './widgets/WalletRestoreDialog';
import globalMessages from '../../../i18n/global-messages';
import styles from './WalletTypeDialog.scss';
import {
WALLET_KINDS,
WALLET_DAEDALUS_KINDS,
WALLET_YOROI_KINDS,
WALLET_HARDWARE_KINDS,
} from '../../../config/walletRestoreConfig';
import type {
WalletKinds,
WalletKind,
WalletDaedalusKind,
WalletYoroiKind,
WalletHardwareKind,
HardwareWalletAcceptance,
} from '../../../types/walletRestoreTypes';
const messages = defineMessages({
labelWalletKind: {
id: 'wallet.restore.dialog.step.walletKind.label.walletKind',
defaultMessage: '!!!What kind of wallet would you like to restore?',
description: 'Label for the "labelwalletKind" checkbox.',
},
labelWalletKindDaedalus: {
id: 'wallet.restore.dialog.step.walletKind.label.walletKindDaedalus',
defaultMessage: '!!!Daedalus wallet',
description: 'Label for the "labelWalletKindDaedalus" checkbox.',
},
labelWalletKindYoroi: {
id: 'wallet.restore.dialog.step.walletKind.label.walletKindYoroi',
defaultMessage: '!!!Yoroi wallet',
description: 'Label for the "labelWalletKindYoroi" checkbox.',
},
labelWalletKindHardware: {
id: 'wallet.restore.dialog.step.walletKind.label.walletKindHardware',
defaultMessage: '!!!Hardware wallet',
description: 'Label for the "labelWalletKindHardware" checkbox.',
},
labelDaedalusWalletKind: {
id: 'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind',
defaultMessage:
'!!!What kind of Daedalus wallet would you like to restore?',
description: 'Label for the "labelDaedalusWalletKind" checkbox.',
},
labelDaedalusWalletKind12WordByron: {
id:
'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind12WordByron',
defaultMessage: '!!!12 words <em>(Byron legacy wallet)</em>',
description: 'Label for the "labelDaedalusWalletKind12WordByron" checkbox.',
},
labelDaedalusWalletKind15WordShelley: {
id:
'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind15WordShelley',
defaultMessage:
'!!!15 words <em>(Incentivized Testnet Rewards wallet)</em>',
description:
'Label for the "labelDaedalusWalletKind15WordShelley" checkbox.',
},
labelDaedalusWalletKind24WordShelley: {
id:
'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind24WordShelley',
defaultMessage: '!!!24 words <em>(Shelley wallet)</em>',
description:
'Label for the "labelDaedalusWalletKind24WordShelley" checkbox.',
},
labelDaedalusWalletKind27WordPaper: {
id:
'wallet.restore.dialog.step.walletKind.label.daedalusWalletKind27WordPaper',
defaultMessage: '!!!27 words - paper wallet (Byron legacy wallet)</em>',
description: 'Label for the "labelDaedalusWalletKind27WordPaper" checkbox.',
},
labelYoroiWalletKind: {
id: 'wallet.restore.dialog.step.walletKind.label.yoroiWalletKind',
defaultMessage: '!!!What kind of Yoroi wallet would you like to restore?',
description: 'Label for the "labelYoroiWalletKind" checkbox.',
},
labelYoroiWalletKind15WordByron: {
id:
'wallet.restore.dialog.step.walletKind.label.yoroiWalletKindByronLegacy15Word',
defaultMessage: '!!!15 words <em>(Byron legacy wallet)</em>',
description: 'Label for the "labelDaedalusWalletKind15WordByron" checkbox.',
},
labelYoroiWalletKind15WordShelley: {
id:
'wallet.restore.dialog.step.walletKind.label.yoroiWalletKindShelley15Word',
defaultMessage: '!!!15 words <em>(Shelley wallet)</em>',
description:
'Label for the "labelDaedalusWalletKind15WordShelley" checkbox.',
},
labelHardwareWalletKind: {
id: 'wallet.restore.dialog.step.walletKind.label.hardwareWalletKind',
defaultMessage:
'!!!What kind of hardware wallet would you like to restore?',
description: 'Label for the "labelHardwareWalletKind" checkbox.',
},
labelHardwareWalletKindLedger: {
id: 'wallet.restore.dialog.step.walletKind.label.hardwareWalletKindLedger',
defaultMessage: '!!!24 words - Ledger (Byron legacy wallet)',
description: 'Label for the "labelHardwareWalletKindLedger" checkbox.',
},
labelHardwareWalletKindTrezor: {
id: 'wallet.restore.dialog.step.walletKind.label.hardwareWalletKindTrezor',
defaultMessage: '!!!24 words - Trezor (Byron legacy wallet)',
description: 'Label for the "labelHardwareWalletKindTrezor" checkbox.',
},
hardwareWalletDisclaimer1: {
id: 'wallet.restore.dialog.step.walletKind.hardwareWalletDisclaimer1',
defaultMessage:
'!!!Hardware wallets store your private keys securely on a physical device so they are immune to common computer threats such as viruses and software bugs. Recovery phrases for hardware wallets should always be kept offline. By entering your hardware wallet recovery phrase in Daedalus, you expose your hardware wallet private keys to the security risks associated with computers and software.',
description: 'Label for the "hardwareWalletDisclaimer1" disclaimer.',
},
hardwareWalletDisclaimer2: {
id: 'wallet.restore.dialog.step.walletKind.hardwareWalletDisclaimer2',
defaultMessage:
'!!!All of your assets held on your hardware wallet device are associated with the same wallet recovery phrase and its corresponding private key. If you hold assets other than ada on your hardware wallet device, you expose all of those assets to security risks.',
description: 'Label for the "hardwareWalletDisclaimer2" disclaimer.',
},
hardwareWalletDisclaimer3: {
id: 'wallet.restore.dialog.step.walletKind.hardwareWalletDisclaimer3',
defaultMessage:
'!!!We strongly recommend that you delete the Byron legacy wallet that was restored from your hardware wallet once you have moved funds into a Shelley wallet.',
description: 'Label for the "hardwareWalletDisclaimer3" disclaimer.',
},
hardwareWalletCheckbox1: {
id: 'wallet.restore.dialog.step.walletKind.hardwareWalletCheckbox1',
defaultMessage:
'!!!I understand and accept responsibility for the security concerns of restoring a hardware wallet on a computer.',
description: 'Label for the "hardwareWalletCheckbox1" disclaimer.',
},
hardwareWalletCheckbox2: {
id: 'wallet.restore.dialog.step.walletKind.hardwareWalletCheckbox2',
defaultMessage:
'!!!I understand that I should delete the Byron legacy wallet I am restoring from a hardware wallet after moving funds to a Shelley wallet.',
description: 'Label for the "hardwareWalletCheckbox2" disclaimer.',
},
hardwareWalletCheckbox3: {
id: 'wallet.restore.dialog.step.walletKind.hardwareWalletCheckbox3',
defaultMessage:
'!!!I understand that I am exposing all of the assets that are stored on my hardware wallet device, and not just ada, to security risks.',
description: 'Label for the "hardwareWalletCheckbox2" disclaimer.',
},
});
type Props = {
onContinue: Function,
onClose: Function,
onSetWalletKind: Function,
walletKind: ?WalletKind,
walletKindDaedalus: ?WalletDaedalusKind,
walletKindYoroi: ?WalletYoroiKind,
walletKindHardware: ?WalletHardwareKind,
};
type State = {
[key: HardwareWalletAcceptance]: boolean,
};
export default class WalletTypeDialog extends Component<Props, State> {
static contextTypes = {
intl: intlShape.isRequired,
};
state = {
hardwareWalletAcceptance1: false,
hardwareWalletAcceptance2: false,
hardwareWalletAcceptance3: false,
};
toggleAcceptance = (param: HardwareWalletAcceptance) =>
this.setState((currentState) => set({}, param, !currentState[param]));
getWalletKind = (
kinds: Object,
message: string,
value: ?string,
kindParam?: string
) => (
<RadioSet
label={this.context.intl.formatMessage(message)}
items={Object.keys(kinds).map((key: string) => {
const kind: WalletKinds = kinds[key];
const messageParam = `label${kindParam || ''}WalletKind${kind}`;
const msg = messages[messageParam];
if (!msg) {
throw new Error(`Missing ${messageParam} message`);
}
return {
key: kind,
disabled: false,
label: <FormattedHTMLMessage {...msg} />,
selected: value === kind,
onChange: () => this.props.onSetWalletKind(kind, kindParam),
};
})}
verticallyAligned
/>
);
get isDisabled() {
const {
walletKind,
walletKindDaedalus,
walletKindYoroi,
walletKindHardware,
} = this.props;
const {
hardwareWalletAcceptance1,
hardwareWalletAcceptance2,
hardwareWalletAcceptance3,
} = this.state;
if (!walletKind) return true;
if (walletKind === WALLET_KINDS.DAEDALUS && !walletKindDaedalus)
return true;
if (walletKind === WALLET_KINDS.YOROI && !walletKindYoroi) return true;
return (
walletKind === WALLET_KINDS.HARDWARE &&
(!walletKindHardware ||
!hardwareWalletAcceptance1 ||
!hardwareWalletAcceptance2 ||
!hardwareWalletAcceptance3)
);
}
render() {
const { intl } = this.context;
const {
onClose,
onContinue,
walletKind,
walletKindDaedalus,
walletKindYoroi,
walletKindHardware,
} = this.props;
const {
hardwareWalletAcceptance1,
hardwareWalletAcceptance2,
hardwareWalletAcceptance3,
} = this.state;
return (
<WalletRestoreDialog
stepNumber={0}
actions={[
{
primary: true,
label: intl.formatMessage(globalMessages.dialogButtonContinueLabel),
onClick: onContinue,
disabled: this.isDisabled,
},
]}
onClose={onClose}
>
<div className={styles.component}>
{this.getWalletKind(
WALLET_KINDS,
messages.labelWalletKind,
walletKind
)}
</div>
<div>
{walletKind === WALLET_KINDS.DAEDALUS &&
this.getWalletKind(
WALLET_DAEDALUS_KINDS,
messages.labelDaedalusWalletKind,
walletKindDaedalus,
WALLET_KINDS.DAEDALUS
)}
{walletKind === WALLET_KINDS.YOROI &&
this.getWalletKind(
WALLET_YOROI_KINDS,
messages.labelYoroiWalletKind,
walletKindYoroi,
WALLET_KINDS.YOROI
)}
{walletKind === WALLET_KINDS.HARDWARE && (
<Fragment>
{this.getWalletKind(
WALLET_HARDWARE_KINDS,
messages.labelHardwareWalletKind,
walletKindHardware,
WALLET_KINDS.HARDWARE
)}
<p className={styles.hardwareWalletAcceptance}>
{intl.formatMessage(messages.hardwareWalletDisclaimer1)}
</p>
<p className={styles.hardwareWalletAcceptance}>
{intl.formatMessage(messages.hardwareWalletDisclaimer2)}
</p>
<p className={styles.hardwareWalletAcceptance}>
<b>{intl.formatMessage(messages.hardwareWalletDisclaimer3)}</b>
</p>
<Checkbox
className="walletSecurityRisk"
label={intl.formatMessage(messages.hardwareWalletCheckbox3)}
onChange={() =>
this.toggleAcceptance('hardwareWalletAcceptance3')
}
checked={hardwareWalletAcceptance3}
skin={CheckboxSkin}
/>
<Checkbox
className="restoreSecurityNote"
label={intl.formatMessage(messages.hardwareWalletCheckbox1)}
onChange={() =>
this.toggleAcceptance('hardwareWalletAcceptance1')
}
checked={hardwareWalletAcceptance1}
skin={CheckboxSkin}
/>
<Checkbox
className="walletDeleteNote"
label={intl.formatMessage(messages.hardwareWalletCheckbox2)}
onChange={() =>
this.toggleAcceptance('hardwareWalletAcceptance2')
}
checked={hardwareWalletAcceptance2}
skin={CheckboxSkin}
/>
</Fragment>
)}
</div>
</WalletRestoreDialog>
);
}
}