@@ -22,6 +22,7 @@ import * as backendAPI from '../../api/backend';
2222import { alertUser } from '../../components/alert/Alert' ;
2323import { Button , Input } from '../../components/forms' ;
2424import Logo from '../../components/icon/logo' ;
25+ import { EyeOpenedDark } from '../../components/icon' ;
2526import { GuideWrapper , GuidedContent , Header , Main } from '../../components/layout' ;
2627import { Toggle } from '../../components/toggle/toggle' ;
2728import { Dialog , DialogButtons } from '../../components/dialog/dialog' ;
@@ -34,7 +35,6 @@ import { MobileHeader } from '../settings/components/mobile-header';
3435import Guide from './manage-account-guide' ;
3536import style from './manage-accounts.module.css' ;
3637
37-
3838interface ManageAccountsProps {
3939 deviceIDs : string [ ] ;
4040 hasAccounts : boolean ;
@@ -47,21 +47,20 @@ type TShowTokens = {
4747}
4848
4949interface State {
50- editAccountCode ?: string ;
51- editAccountNewName : string ;
5250 editErrorMessage ?: string ;
5351 accounts : accountAPI . IAccount [ ] ;
5452 showTokens : TShowTokens ;
5553 watchonly ?: boolean ;
54+ currentlyEditedAccount ?: accountAPI . IAccount
5655}
5756
5857class ManageAccounts extends Component < Props , State > {
5958 public readonly state : State = {
60- editAccountNewName : '' ,
6159 editErrorMessage : undefined ,
6260 accounts : [ ] ,
6361 showTokens : { } ,
6462 watchonly : undefined ,
63+ currentlyEditedAccount : undefined
6564 } ;
6665
6766 private fetchAccounts = ( ) => {
@@ -74,7 +73,7 @@ class ManageAccounts extends Component<Props, State> {
7473 }
7574
7675 private renderAccounts = ( accounts : accountAPI . IAccount [ ] ) => {
77- const { watchonly , showTokens } = this . state ;
76+ const { showTokens } = this . state ;
7877 const { t } = this . props ;
7978 return accounts . filter ( account => ! account . isToken ) . map ( account => {
8079 const active = account . active ;
@@ -93,7 +92,8 @@ class ManageAccounts extends Component<Props, State> {
9392 </ div >
9493 < button
9594 className = { style . editBtn }
96- onClick = { ( ) => this . setState ( { editAccountCode : account . code , editAccountNewName : account . name } ) } >
95+ onClick = { ( ) => this . setState ( { currentlyEditedAccount : account } ) }
96+ >
9797 { t ( 'manageAccounts.editAccount' ) }
9898 </ button >
9999 < Toggle
@@ -105,19 +105,6 @@ class ManageAccounts extends Component<Props, State> {
105105 this . toggleAccount ( account . code , ! active )
106106 . then ( ( ) => event . target . disabled = false ) ;
107107 } } />
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 }
121108 { active && account . coinCode === 'eth' ? (
122109 < div className = { style . tokenSection } >
123110 < div className = { `${ style . tokenContainer } ${ tokensVisible ? style . tokenContainerOpen : '' } ` } >
@@ -138,6 +125,41 @@ class ManageAccounts extends Component<Props, State> {
138125 } ) ;
139126 } ;
140127
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+
141163 private toggleAccount = ( accountCode : string , active : boolean ) => {
142164 return backendAPI . setAccountActive ( accountCode , active ) . then ( ( { success, errorMessage } ) => {
143165 if ( success ) {
@@ -224,9 +246,13 @@ class ManageAccounts extends Component<Props, State> {
224246
225247 private updateAccountName = ( event : React . SyntheticEvent ) => {
226248 event . preventDefault ( ) ;
227- const { editAccountCode , editAccountNewName } = this . state ;
249+ const { currentlyEditedAccount } = this . state ;
228250
229- backendAPI . renameAccount ( editAccountCode ! , editAccountNewName ! )
251+ if ( ! currentlyEditedAccount ) {
252+ return ;
253+ }
254+
255+ backendAPI . renameAccount ( currentlyEditedAccount . code , currentlyEditedAccount . name )
230256 . then ( result => {
231257 if ( ! result . success ) {
232258 if ( result . errorCode ) {
@@ -238,16 +264,15 @@ class ManageAccounts extends Component<Props, State> {
238264 }
239265 this . fetchAccounts ( ) ;
240266 this . setState ( {
241- editAccountCode : undefined ,
242- editAccountNewName : '' ,
243267 editErrorMessage : undefined ,
268+ currentlyEditedAccount : undefined ,
244269 } ) ;
245270 } ) ;
246271 } ;
247272
248273 public render ( ) {
249274 const { t, deviceIDs, hasAccounts } = this . props ;
250- const { accounts, editAccountCode , editAccountNewName , editErrorMessage } = this . state ;
275+ const { accounts, editErrorMessage , currentlyEditedAccount , watchonly } = this . state ;
251276 const accountsByKeystore = getAccountsByKeystore ( accounts ) ;
252277 return (
253278 < GuideWrapper >
@@ -264,46 +289,47 @@ class ManageAccounts extends Component<Props, State> {
264289 < View fullscreen = { false } >
265290 < ViewContent >
266291 < 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 } >
277301 < p > { keystore . keystore . name } </ p >
278302 < div className = "box slim divide m-bottom-large" >
279- { this . renderAccounts ( keystore . accounts ) }
303+ { this . renderAccounts ( keystore . accounts ) }
280304 </ div >
281- </ React . Fragment > ) )
282- }
283- { accounts . length === 0 ? t ( 'manageAccounts.noAccounts' ) : null }
284-
305+ </ React . Fragment >
306+ ) )
307+ }
308+ { currentlyEditedAccount && (
285309 < Dialog
286- open = { ! ! ( editAccountCode ) }
287- onClose = { ( ) => this . setState ( { editAccountCode : undefined , editAccountNewName : '' , editErrorMessage : undefined } ) }
310+ open = { ! ! ( currentlyEditedAccount ) }
311+ onClose = { ( ) => this . setState ( { currentlyEditedAccount : undefined } ) }
288312 title = { t ( 'manageAccounts.editAccountNameTitle' ) } >
289313 < form onSubmit = { this . updateAccountName } >
290314 < Message type = "error" hidden = { ! editErrorMessage } >
291315 { editErrorMessage }
292316 </ Message >
293317 < 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 ( ) }
296322 < DialogButtons >
297323 < Button
298- disabled = { ! editAccountNewName }
324+ disabled = { ! currentlyEditedAccount . name }
299325 primary
300326 type = "submit" >
301327 { t ( 'button.update' ) }
302328 </ Button >
303329 </ DialogButtons >
304330 </ form >
305331 </ Dialog >
306- </ >
332+ ) }
307333 </ WithSettingsTabs >
308334 </ ViewContent >
309335 </ View >
0 commit comments