OSDN Git Service

removed the key alias concept and update the account selection
authorZhiting Lin <zlin035@uottawa.ca>
Fri, 12 Jul 2019 06:33:44 +0000 (14:33 +0800)
committerZhiting Lin <zlin035@uottawa.ca>
Fri, 12 Jul 2019 06:33:44 +0000 (14:33 +0800)
src/features/app/components/Container.jsx
src/features/initialization/actions.js
src/features/shared/components/RestoreMnemonic/RestoreMnemonic.jsx

index d66af15..c2e61ec 100644 (file)
@@ -10,9 +10,6 @@ const CORE_POLLING_TIME = 2 * 1000
 class Container extends React.Component {
   constructor(props) {
     super(props)
-    this.state = {
-      noAccountItem: false
-    }
     this.redirectRoot = this.redirectRoot.bind(this)
   }
 
@@ -29,7 +26,7 @@ class Container extends React.Component {
       return
     }
 
-    if (accountInit && !this.state.noAccountItem) {
+    if (accountInit) {
       if (location.pathname === '/'|| location.pathname.indexOf('initialization') >= 0) {
         this.props.showRoot()
       }
@@ -41,9 +38,13 @@ class Container extends React.Component {
   componentDidMount() {
     this.props.fetchAccountItem().then(resp => {
       if (resp.data.length == 0) {
-        this.setState({noAccountItem: true})
         this.props.updateAccountInit(false)
         this.redirectRoot(this.props)
+      }else{
+        const aliasArray = resp.data.map(account => account.alias)
+        if(!aliasArray.includes(this.props.currentAccount)){
+          this.props.setDefaultAccount()
+        }
       }
     })
     if(this.props.lng === 'zh'){
@@ -67,6 +68,7 @@ class Container extends React.Component {
         nextProps.location.pathname != this.props.location.pathname) {
       this.redirectRoot(nextProps)
     }
+
   }
 
   render() {
@@ -87,7 +89,7 @@ class Container extends React.Component {
       return <Loading>{t('main.loading')}</Loading>
     } else if (!this.props.configured) {
       layout = <Config>{this.props.children}</Config>
-    } else if (!this.props.accountInit || this.state.noAccountItem){
+    } else if (!this.props.accountInit){
       layout = <Config>{this.props.children}</Config>
     } else{
       layout = <Main>{this.props.children}</Main>
@@ -114,12 +116,14 @@ export default connect(
     configKnown: state.core.configKnown,
     configured: true,
     accountInit: state.core.accountInit,
+    currentAccount: state.core.currentAccount
   }),
   (dispatch) => ({
     fetchInfo: options => dispatch(actions.core.fetchCoreInfo(options)),
     showRoot: () => dispatch(actions.app.showRoot),
     showInitialization: () => dispatch(actions.app.showInitialization()),
     updateAccountInit: (param) => dispatch(actions.app.updateAccountInit(param)),
-    fetchAccountItem: () => dispatch(actions.account.fetchItems())
+    fetchAccountItem: () => dispatch(actions.account.fetchItems()),
+    setDefaultAccount:() => dispatch(actions.account.setDefaultAccount())
   })
 )( withI18n() (Container) )
index e4756eb..b891a3a 100644 (file)
@@ -1,12 +1,13 @@
 import { chainClient } from 'utility/environment'
 import {push} from 'react-router-redux'
+import uuid from 'uuid'
 
 const registerKey = (data) => {
   return (dispatch) => {
     if (typeof data.accountAlias == 'string')  data.accountAlias = data.accountAlias.trim()
 
     const keyData = {
-      'alias': `${data.accountAlias}Key`,
+      'alias': `${data.accountAlias}Key-${uuid.v4()}`,
       'password': data.password
     }
 
@@ -73,11 +74,10 @@ const restoreKeystore = (data, success) => {
 
 const restoreMnemonic = (data, success) => {
   return (dispatch) => {
-    if (typeof data.keyAlias == 'string')  data.keyAlias = data.keyAlias.trim()
     if (typeof data.mnemonic == 'string') data.mnemonic = data.mnemonic.trim()
 
     const keyData = {
-      'alias': data.keyAlias,
+      'alias': `key-${uuid.v4()}`,
       'password': data.password,
       'mnemonic': data.mnemonic
     }
index 97b33fd..425ddfb 100644 (file)
@@ -23,7 +23,7 @@ class RestoreMnemonic extends React.Component {
     const t = this.props.t
 
     const {
-      fields: {mnemonic, keyAlias, password, confirmPassword},
+      fields: {mnemonic, password, confirmPassword},
       error,
       handleSubmit,
       submitting
@@ -40,10 +40,6 @@ class RestoreMnemonic extends React.Component {
                 title={t('init.mnemonic')}
                 fieldProps={mnemonic}
               />
-              <TextField
-                title={t('form.keyAlias')}
-                placeholder={t('init.keyPlaceholder')}
-                fieldProps={keyAlias}/>
               <PasswordField
                 title={t('init.keyPassword')}
                 placeholder={t('init.passwordPlaceholder')}
@@ -76,9 +72,6 @@ const validate = (values, props) => {
   if (!values.mnemonic) {
     errors.mnemonic = t('init.mnemonicRequire')
   }
-  if (!values.keyAlias) {
-    errors.keyAlias = t('key.aliasRequired')
-  }
   if (!values.password) {
     errors.password = t('key.passwordRequired')
   } else if (values.password.length < 5) {
@@ -101,7 +94,6 @@ export default withNamespaces('translations')( connect(
   form: 'restoreMnemonic',
   fields: [
     'mnemonic',
-    'keyAlias',
     'password',
     'confirmPassword',
   ],