1- import React , { useState , useCallback , useMemo } from 'react'
1+ import React , { useState , useCallback , useMemo , useEffect } from 'react'
22import { RouteComponentProps } from 'react-router-dom'
33import { Stack , DefaultButton , PrimaryButton , TextField } from 'office-ui-fabric-react'
44import { useTranslation } from 'react-i18next'
55import { showOpenDialog } from 'services/remote'
66import { importWalletWithKeystore } from 'states/stateProvider/actionCreators'
77import { StateWithDispatch } from 'states/stateProvider/reducer'
88import { useGoBack } from 'utils/hooks'
9+ import generateWalletName from 'utils/generateWalletName'
910
1011const defaultFields = {
1112 path : '' ,
@@ -23,6 +24,16 @@ const ImportKeystore = (props: React.PropsWithoutRef<StateWithDispatch & RouteCo
2324 const [ fields , setFields ] = useState ( defaultFields )
2425 const goBack = useGoBack ( history )
2526
27+ useEffect ( ( ) => {
28+ if ( fields . name === '' ) {
29+ const name = generateWalletName ( wallets , wallets . length + 1 , t )
30+ setFields ( {
31+ ...fields ,
32+ name,
33+ } )
34+ }
35+ } , [ wallets , fields , setFields , t ] )
36+
2637 const exsitingNames = useMemo ( ( ) => {
2738 return wallets . map ( w => w . name )
2839 } , [ wallets ] )
@@ -39,11 +50,9 @@ const ImportKeystore = (props: React.PropsWithoutRef<StateWithDispatch & RouteCo
3950 return
4051 }
4152 const filePath = filePaths [ 0 ]
42- const filename = filePath . split ( '/' ) . pop ( ) || 'Imported wallet'
4353 setFields ( {
4454 ...fields ,
4555 path : filePath ,
46- name : filename ,
4756 } )
4857 } ,
4958 } )
0 commit comments