Newer
Older
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
// Copyright 2015-2018 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause
import React, { Component } from 'react';
import { AccountHeader, Card, Form as FetherForm } from 'fether-ui';
import { inject, observer } from 'mobx-react';
import { accountsInfo$ } from '@parity/light.js';
import light from '@parity/light.js-react';
import { Link, withRouter } from 'react-router-dom';
import withAccount from '../utils/withAccount';
@withRouter
@withAccount
@light({
accountsInfo: accountsInfo$
})
@inject('createAccountStore')
@observer
class BackupAccount extends Component {
state = {
confirm: '',
isLoading: false,
password: '',
message: ''
};
toggleMsg = msg => {
this.setState({
message: msg
});
};
handleConfirmChange = ({ target: { value } }) => {
this.setState({ confirm: value });
};
handlePasswordChange = ({ target: { value } }) => {
this.setState({ password: value });
};
handleSubmit = event => {
const { accountAddress, createAccountStore, history } = this.props;
const { password } = this.state;
event.preventDefault();
this.setState({ isLoading: true });
// Save to parity
createAccountStore
.backupAccount(accountAddress, password)
.then(res => {
if (res) {
createAccountStore.clear();
setTimeout(() => history.push(`/accounts`), 5000);
}
})
.catch(err => {
this.toggleMsg(err.text + ' Please check your password and try again.');
});
};
render () {
const {
accountsInfo,
history,
location: { pathname }
} = this.props;
const { confirm, isLoading, message, password } = this.state;
const accountAddress = pathname.slice(-42);
return (
<div>
<AccountHeader
address={accountAddress}
copyAddress
name={
accountsInfo &&
accountsInfo[accountAddress] &&
accountsInfo[accountAddress].name
}
left={
<Link to='/accounts' className='icon -back'>
Back
</Link>
}
/>
<br />
<Card className='-space-around'>
<form key='backupAccount' onSubmit={this.handleSubmit}>
<div className='text'>
<p>Encrypt your backup with your password:</p>
</div>
<FetherForm.Field
label='Password'
onChange={this.handlePasswordChange}
required
type='password'
value={password}
/>
<FetherForm.Field
label='Confirm'
onChange={this.handleConfirmChange}
required
type='password'
value={confirm}
/>
<p className='error'> {message} </p>
<nav className='form-nav -space-around'>
<button className='button -cancel' onClick={history.goBack}>
Back
</button>
<button
className='button'
disabled={!password || confirm !== password || isLoading}
>
Confirm backup
</button>
</nav>
</form>
</Card>
</div>
);
}
}
export default BackupAccount;