-
Notifications
You must be signed in to change notification settings - Fork 97
/
savedAccounts.js
182 lines (165 loc) · 6.88 KB
/
savedAccounts.js
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
import { Button as ToolBoxButton } from 'react-toolbox/lib/button';
import { Link } from 'react-router-dom';
// import FontIcon from 'react-toolbox/lib/font_icon';
import React from 'react';
import { extractAddress } from '../../utils/api/account';
import { PrimaryButton, SecondaryLightButton } from '../toolbox/buttons/button';
import AccountVisual from '../accountVisual';
import LiskAmount from '../liskAmount';
import BackgroundMaker from '../backgroundMaker';
import networks from '../../constants/networks';
import getNetwork from '../../utils/getNetwork';
import routes from '../../constants/routes';
import plusShapeIcon from '../../assets/images/plus-shape.svg';
import circleImage from '../../assets/images/add-id-oval.svg';
import rectangleOnTheRight from '../../assets/images/add-id-rectangle-1.svg';
import rectangleImage2 from '../../assets/images/add-id-rectangle-2.svg';
import rectangleImage3 from '../../assets/images/add-id-rectangle-3.svg';
import triangleImage from '../../assets/images/add-id-triangle.svg';
import { FontIcon } from '../fontIcon';
import styles from './savedAccounts.css';
class SavedAccounts extends React.Component {
constructor() {
super();
this.state = {
isSecureAppears: {},
};
}
toggleEdit() {
this.setState({
editing: !this.state.editing,
accountSelectedForRemove: null,
});
}
selectForRemove(account) {
this.setState({ accountSelectedForRemove: account });
}
isSelectedForRemove(account) {
const { publicKey, network, address } = this.state.accountSelectedForRemove || {};
return (account.publicKey === publicKey &&
account.network === network &&
account.address === address);
}
handleRemove(account, e) {
if (this.isSelectedForRemove(account)) {
this.props.accountRemoved(account);
} else {
this.selectForRemove(account);
}
e.stopPropagation();
}
handleRemovePassphrase(account, e) {
e.stopPropagation();
const uniqueID = `${account.network}${account.publicKey}`;
const { savedAccounts } = this.props;
const savedActiveAccount = savedAccounts.find(acc => `${acc.network}${acc.passphrase}` === `${account.network}${account.passphrase}`);
if (savedActiveAccount) {
this.props.removePassphrase(account);
}
this.props.removeSavedAccountPassphrase(account);
this.setState({ isSecureAppears: { ...this.state.isSecureAppears, [uniqueID]: true } });
setTimeout(() => {
this.setState({ isSecureAppears: { ...this.state.isSecureAppears, [uniqueID]: false } });
}, 5000);
}
render() {
const {
closeDialog,
accountSwitched,
savedAccounts,
history,
t,
} = this.props;
const switchAccount = (account) => {
if (!this.state.editing) {
accountSwitched(account);
history.push(`${routes.main.path}${routes.dashboard.path}`);
}
};
return (
<div className={`${styles.wrapper} save-account`}>
<BackgroundMaker className={styles.background} />
<h1>
{t('Your Lisk IDs')}
</h1>
<ul className={styles.cardsWrapper} >
<li>
<Link to={`${routes.addAccount.path}?referrer=${routes.main.path}${routes.dashboard.path}/`} >
<div className={`add-lisk-id-card ${styles.card} ${styles.addNew}`} >
<div className={styles.cardIcon}>
<img src={plusShapeIcon} className={styles.plusShapeIcon} />
</div>
<img src={rectangleOnTheRight} className={styles.rectangleOnTheRight} />
<img src={rectangleImage2} className={styles.rectangleImage2} />
<img src={rectangleImage3} className={styles.rectangleImage3} />
<img src={triangleImage} className={styles.triangleImage} />
<img src={circleImage} className={styles.circleImage} />
<h2 className={styles.addTittle} >{t('Add a Lisk ID')}</h2>
</div>
</Link>
</li>
{savedAccounts.map(account => (
<li className={`saved-account-card ${styles.card}
${this.state.editing ? null : styles.clickable}
${this.isSelectedForRemove(account) ? styles.darkBackground : null}`}
key={account.publicKey + account.network}
onClick={ switchAccount.bind(null, account)} >
{(account.passphrase ?
<strong
className={`unlocked ${styles.unlocked}`}
onClick={this.handleRemovePassphrase.bind(this, account)}>
<FontIcon value='unlocked' />
{t('Lock ID')}
</strong> :
null)}
{(this.state.isSecureAppears[`${account.network}${account.publicKey}`] ?
<strong className={`unlockedSecured ${styles.unlockedSecured}`}>
{t('Your ID is now secured!')}
</strong> :
null)}
{(account.network !== networks.mainnet.code ?
<strong className={styles.network}>
{account.address ? account.address : t(getNetwork(account.network).name)}
</strong> :
null)}
<div className={styles.cardIcon}>
<AccountVisual address={extractAddress(account.publicKey)} size={155} sizeS={100}
className={styles.accountVisual} />
</div>
<h2>
<LiskAmount val={account.balance} /> <small>LSK</small>
</h2>
<div className={styles.address} >{extractAddress(account.publicKey)}</div>
{ this.isSelectedForRemove(account) ?
<div className={styles.removeConfirm}>
<h2>{t('You can always get it back.')}</h2>
<a onClick={this.selectForRemove.bind(this)}>{t('Keep it')}</a>
</div> :
null
}
{ this.state.editing ?
<PrimaryButton className='remove-button'
theme={ this.isSelectedForRemove(account) ?
{} :
{ button: styles.removeButton }
}
onClick={this.handleRemove.bind(this, account)}
label={this.isSelectedForRemove(account) ? t('Confirm') : t('Remove')}/> :
null
}
</li>
))}
</ul>
<SecondaryLightButton className='edit-button'
onClick={this.toggleEdit.bind(this)}
theme={{ button: styles.addAcctiveAccountButton }}>
<FontIcon className={styles.editIcon}
value={this.state.editing ? 'checkmark' : 'edit'} />
{this.state.editing ? t('Done') : t('Edit')}
</SecondaryLightButton>
<ToolBoxButton icon={<FontIcon value='close' />} floating onClick={closeDialog} className={`x-button ${styles.closeButton}`} />
</div>
);
}
}
export default SavedAccounts;