@@ -22,6 +22,7 @@ import * as backendAPI from '../../api/backend';
22
22
import { alertUser } from '../../components/alert/Alert' ;
23
23
import { Button , Input } from '../../components/forms' ;
24
24
import Logo from '../../components/icon/logo' ;
25
+ import { EyeOpenedDark } from '../../components/icon' ;
25
26
import { GuideWrapper , GuidedContent , Header , Main } from '../../components/layout' ;
26
27
import { Toggle } from '../../components/toggle/toggle' ;
27
28
import { Dialog , DialogButtons } from '../../components/dialog/dialog' ;
@@ -34,7 +35,6 @@ import { MobileHeader } from '../settings/components/mobile-header';
34
35
import Guide from './manage-account-guide' ;
35
36
import style from './manage-accounts.module.css' ;
36
37
37
-
38
38
interface ManageAccountsProps {
39
39
deviceIDs : string [ ] ;
40
40
hasAccounts : boolean ;
@@ -47,21 +47,20 @@ type TShowTokens = {
47
47
}
48
48
49
49
interface State {
50
- editAccountCode ?: string ;
51
- editAccountNewName : string ;
52
50
editErrorMessage ?: string ;
53
51
accounts : accountAPI . IAccount [ ] ;
54
52
showTokens : TShowTokens ;
55
53
watchonly ?: boolean ;
54
+ currentlyEditedAccount ?: accountAPI . IAccount
56
55
}
57
56
58
57
class ManageAccounts extends Component < Props , State > {
59
58
public readonly state : State = {
60
- editAccountNewName : '' ,
61
59
editErrorMessage : undefined ,
62
60
accounts : [ ] ,
63
61
showTokens : { } ,
64
62
watchonly : undefined ,
63
+ currentlyEditedAccount : undefined
65
64
} ;
66
65
67
66
private fetchAccounts = ( ) => {
@@ -74,7 +73,7 @@ class ManageAccounts extends Component<Props, State> {
74
73
}
75
74
76
75
private renderAccounts = ( accounts : accountAPI . IAccount [ ] ) => {
77
- const { watchonly , showTokens } = this . state ;
76
+ const { showTokens } = this . state ;
78
77
const { t } = this . props ;
79
78
return accounts . filter ( account => ! account . isToken ) . map ( account => {
80
79
const active = account . active ;
@@ -93,7 +92,8 @@ class ManageAccounts extends Component<Props, State> {
93
92
</ div >
94
93
< button
95
94
className = { style . editBtn }
96
- onClick = { ( ) => this . setState ( { editAccountCode : account . code , editAccountNewName : account . name } ) } >
95
+ onClick = { ( ) => this . setState ( { currentlyEditedAccount : account } ) }
96
+ >
97
97
{ t ( 'manageAccounts.editAccount' ) }
98
98
</ button >
99
99
< Toggle
@@ -105,19 +105,6 @@ class ManageAccounts extends Component<Props, State> {
105
105
this . toggleAccount ( account . code , ! active )
106
106
. then ( ( ) => event . target . disabled = false ) ;
107
107
} } />
108
- { watchonly ? ( < >
109
- Hide account (TODO: move this to the edit dialog):
110
- < Toggle
111
- checked = { ! account . watch }
112
- className = { style . toggle }
113
- id = { account . code }
114
- onChange = { async ( event ) => {
115
- event . target . disabled = true ;
116
- await this . setWatch ( account . code , ! account . watch ) ;
117
- event . target . disabled = false ;
118
- } } />
119
- </ >
120
- ) : null }
121
108
{ active && account . coinCode === 'eth' ? (
122
109
< div className = { style . tokenSection } >
123
110
< div className = { `${ style . tokenContainer } ${ tokensVisible ? style . tokenContainerOpen : '' } ` } >
@@ -138,6 +125,41 @@ class ManageAccounts extends Component<Props, State> {
138
125
} ) ;
139
126
} ;
140
127
128
+ private renderWatchOnlyToggle = ( ) => {
129
+ const { t } = this . props ;
130
+ const { currentlyEditedAccount } = this . state ;
131
+ if ( ! currentlyEditedAccount ) {
132
+ return ;
133
+ }
134
+
135
+ return (
136
+ < div className = "flex flex-column" >
137
+ < div className = { style . watchOnlyContainer } >
138
+ < div className = "flex" >
139
+ < EyeOpenedDark width = { 18 } height = { 18 } />
140
+ < p className = { style . watchOnlyTitle } > { t ( 'manageAccounts.hideAccount' ) } </ p >
141
+ </ div >
142
+ < Toggle
143
+ checked = { ! currentlyEditedAccount . watch }
144
+ className = { style . toggle }
145
+ id = { currentlyEditedAccount . code }
146
+ onChange = { async ( event ) => {
147
+ event . target . disabled = true ;
148
+ await this . setWatch ( currentlyEditedAccount . code , ! currentlyEditedAccount . watch ) ;
149
+ this . setState ( { currentlyEditedAccount : { ...currentlyEditedAccount , watch : ! currentlyEditedAccount . watch } } ) ;
150
+ event . target . disabled = false ;
151
+ } }
152
+ />
153
+ </ div >
154
+ < p className = { style . watchOnlyNote } > { t ( 'manageAccounts.hideAccountDescription' ) } </ p >
155
+ {
156
+ ! currentlyEditedAccount . watch && < div className = { style . watchOnlyAccountHidden } >
157
+ < p > { t ( 'manageAccounts.accountHidden' ) } </ p >
158
+ </ div >
159
+ }
160
+ </ div > ) ;
161
+ } ;
162
+
141
163
private toggleAccount = ( accountCode : string , active : boolean ) => {
142
164
return backendAPI . setAccountActive ( accountCode , active ) . then ( ( { success, errorMessage } ) => {
143
165
if ( success ) {
@@ -224,9 +246,13 @@ class ManageAccounts extends Component<Props, State> {
224
246
225
247
private updateAccountName = ( event : React . SyntheticEvent ) => {
226
248
event . preventDefault ( ) ;
227
- const { editAccountCode , editAccountNewName } = this . state ;
249
+ const { currentlyEditedAccount } = this . state ;
228
250
229
- backendAPI . renameAccount ( editAccountCode ! , editAccountNewName ! )
251
+ if ( ! currentlyEditedAccount ) {
252
+ return ;
253
+ }
254
+
255
+ backendAPI . renameAccount ( currentlyEditedAccount . code , currentlyEditedAccount . name )
230
256
. then ( result => {
231
257
if ( ! result . success ) {
232
258
if ( result . errorCode ) {
@@ -238,16 +264,15 @@ class ManageAccounts extends Component<Props, State> {
238
264
}
239
265
this . fetchAccounts ( ) ;
240
266
this . setState ( {
241
- editAccountCode : undefined ,
242
- editAccountNewName : '' ,
243
267
editErrorMessage : undefined ,
268
+ currentlyEditedAccount : undefined ,
244
269
} ) ;
245
270
} ) ;
246
271
} ;
247
272
248
273
public render ( ) {
249
274
const { t, deviceIDs, hasAccounts } = this . props ;
250
- const { accounts, editAccountCode , editAccountNewName , editErrorMessage } = this . state ;
275
+ const { accounts, editErrorMessage , currentlyEditedAccount , watchonly } = this . state ;
251
276
const accountsByKeystore = getAccountsByKeystore ( accounts ) ;
252
277
return (
253
278
< GuideWrapper >
@@ -264,46 +289,47 @@ class ManageAccounts extends Component<Props, State> {
264
289
< View fullscreen = { false } >
265
290
< ViewContent >
266
291
< WithSettingsTabs deviceIDs = { deviceIDs } hideMobileMenu hasAccounts = { hasAccounts } >
267
- < >
268
- < Button
269
- className = { style . addAccountBtn }
270
- primary
271
- onClick = { ( ) => route ( '/add-account' , true ) } >
272
- { t ( 'addAccount.title' ) }
273
- </ Button >
274
-
275
- {
276
- accountsByKeystore . map ( keystore => ( < React . Fragment key = { keystore . keystore . rootFingerprint } >
292
+ < Button
293
+ className = { style . addAccountBtn }
294
+ primary
295
+ onClick = { ( ) => route ( '/add-account' , true ) } >
296
+ { t ( 'addAccount.title' ) }
297
+ </ Button >
298
+ {
299
+ accountsByKeystore . map ( keystore => (
300
+ < React . Fragment key = { keystore . keystore . rootFingerprint } >
277
301
< p > { keystore . keystore . name } </ p >
278
302
< div className = "box slim divide m-bottom-large" >
279
- { this . renderAccounts ( keystore . accounts ) }
303
+ { this . renderAccounts ( keystore . accounts ) }
280
304
</ div >
281
- </ React . Fragment > ) )
282
- }
283
- { accounts . length === 0 ? t ( 'manageAccounts.noAccounts' ) : null }
284
-
305
+ </ React . Fragment >
306
+ ) )
307
+ }
308
+ { currentlyEditedAccount && (
285
309
< Dialog
286
- open = { ! ! ( editAccountCode ) }
287
- onClose = { ( ) => this . setState ( { editAccountCode : undefined , editAccountNewName : '' , editErrorMessage : undefined } ) }
310
+ open = { ! ! ( currentlyEditedAccount ) }
311
+ onClose = { ( ) => this . setState ( { currentlyEditedAccount : undefined } ) }
288
312
title = { t ( 'manageAccounts.editAccountNameTitle' ) } >
289
313
< form onSubmit = { this . updateAccountName } >
290
314
< Message type = "error" hidden = { ! editErrorMessage } >
291
315
{ editErrorMessage }
292
316
</ Message >
293
317
< Input
294
- onInput = { e => this . setState ( { editAccountNewName : e . target . value } ) }
295
- value = { editAccountNewName } />
318
+ onInput = { e => this . setState ( { currentlyEditedAccount : { ...currentlyEditedAccount , name : e . target . value } } ) }
319
+ value = { currentlyEditedAccount . name }
320
+ />
321
+ { watchonly && this . renderWatchOnlyToggle ( ) }
296
322
< DialogButtons >
297
323
< Button
298
- disabled = { ! editAccountNewName }
324
+ disabled = { ! currentlyEditedAccount . name }
299
325
primary
300
326
type = "submit" >
301
327
{ t ( 'button.update' ) }
302
328
</ Button >
303
329
</ DialogButtons >
304
330
</ form >
305
331
</ Dialog >
306
- </ >
332
+ ) }
307
333
</ WithSettingsTabs >
308
334
</ ViewContent >
309
335
</ View >
0 commit comments