From 581a0bbe28835ef0f1b79a7b493fca1199fb3e92 Mon Sep 17 00:00:00 2001 From: Zhiting Lin Date: Fri, 12 Jul 2019 14:33:44 +0800 Subject: [PATCH] removed the key alias concept and update the account selection --- src/features/app/components/Container.jsx | 18 +++++++++++------- src/features/initialization/actions.js | 6 +++--- .../components/RestoreMnemonic/RestoreMnemonic.jsx | 10 +--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/features/app/components/Container.jsx b/src/features/app/components/Container.jsx index d66af15..c2e61ec 100644 --- a/src/features/app/components/Container.jsx +++ b/src/features/app/components/Container.jsx @@ -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 {t('main.loading')} } else if (!this.props.configured) { layout = {this.props.children} - } else if (!this.props.accountInit || this.state.noAccountItem){ + } else if (!this.props.accountInit){ layout = {this.props.children} } else{ layout =
{this.props.children}
@@ -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) ) diff --git a/src/features/initialization/actions.js b/src/features/initialization/actions.js index e4756eb..b891a3a 100644 --- a/src/features/initialization/actions.js +++ b/src/features/initialization/actions.js @@ -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 } diff --git a/src/features/shared/components/RestoreMnemonic/RestoreMnemonic.jsx b/src/features/shared/components/RestoreMnemonic/RestoreMnemonic.jsx index 97b33fd..425ddfb 100644 --- a/src/features/shared/components/RestoreMnemonic/RestoreMnemonic.jsx +++ b/src/features/shared/components/RestoreMnemonic/RestoreMnemonic.jsx @@ -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} /> - { 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', ], -- 2.11.0