Importing account by json and private key shows error and does not change account if no selectedAddress comes after import.

This commit is contained in:
Dan 2018-05-30 16:43:45 -02:30
parent 389346913b
commit 1c3d2aa18b
4 changed files with 46 additions and 16 deletions

View File

@ -544,10 +544,12 @@ function importNewAccount (strategy, args) {
} }
dispatch(actions.hideLoadingIndication()) dispatch(actions.hideLoadingIndication())
dispatch(actions.updateMetamaskState(newState)) dispatch(actions.updateMetamaskState(newState))
if (newState.selectedAddress) {
dispatch({ dispatch({
type: actions.SHOW_ACCOUNT_DETAIL, type: actions.SHOW_ACCOUNT_DETAIL,
value: newState.selectedAddress, value: newState.selectedAddress,
}) })
}
return newState return newState
} }
} }

View File

@ -99,7 +99,7 @@ class App extends Component {
} = this.props } = this.props
const isLoadingNetwork = network === 'loading' && currentView.name !== 'config' const isLoadingNetwork = network === 'loading' && currentView.name !== 'config'
const loadMessage = loadingMessage || isLoadingNetwork ? const loadMessage = loadingMessage || isLoadingNetwork ?
this.getConnectingLabel() : null this.getConnectingLabel(loadingMessage) : null
log.debug('Main ui render function') log.debug('Main ui render function')
return ( return (
@ -210,7 +210,10 @@ class App extends Component {
} }
} }
getConnectingLabel = function () { getConnectingLabel = function (loadingMessage) {
if (loadingMessage) {
return loadingMessage
}
const { provider } = this.props const { provider } = this.props
const providerName = provider.type const providerName = provider.type

View File

@ -82,18 +82,19 @@ class JsonImportSubview extends Component {
} }
createNewKeychain () { createNewKeychain () {
const { firstAddress, displayWarning, importNewJsonAccount, setSelectedAddress } = this.props
const state = this.state const state = this.state
if (!state) { if (!state) {
const message = this.context.t('validFileImport') const message = this.context.t('validFileImport')
return this.props.displayWarning(message) return displayWarning(message)
} }
const { fileContents } = state const { fileContents } = state
if (!fileContents) { if (!fileContents) {
const message = this.context.t('needImportFile') const message = this.context.t('needImportFile')
return this.props.displayWarning(message) return displayWarning(message)
} }
const passwordInput = document.getElementById('json-password-box') const passwordInput = document.getElementById('json-password-box')
@ -101,12 +102,20 @@ class JsonImportSubview extends Component {
if (!password) { if (!password) {
const message = this.context.t('needImportPassword') const message = this.context.t('needImportPassword')
return this.props.displayWarning(message) return displayWarning(message)
} }
this.props.importNewJsonAccount([ fileContents, password ]) importNewJsonAccount([ fileContents, password ])
// JS runtime requires caught rejections but failures are handled by Redux // JS runtime requires caught rejections but failures are handled by Redux
.catch() .catch()
.then(({ selectedAddress }) => {
if (selectedAddress) {
history.push(DEFAULT_ROUTE)
} else {
displayWarning('Error importing account.')
setSelectedAddress(firstAddress)
}
})
} }
} }
@ -114,14 +123,17 @@ JsonImportSubview.propTypes = {
error: PropTypes.string, error: PropTypes.string,
goHome: PropTypes.func, goHome: PropTypes.func,
displayWarning: PropTypes.func, displayWarning: PropTypes.func,
firstAddress: PropTypes.string,
importNewJsonAccount: PropTypes.func, importNewJsonAccount: PropTypes.func,
history: PropTypes.object, history: PropTypes.object,
setSelectedAddress: PropTypes.func,
t: PropTypes.func, t: PropTypes.func,
} }
const mapStateToProps = state => { const mapStateToProps = state => {
return { return {
error: state.appState.warning, error: state.appState.warning,
firstAddress: Object.keys(state.metamask.accounts)[0],
} }
} }
@ -130,6 +142,7 @@ const mapDispatchToProps = dispatch => {
goHome: () => dispatch(actions.goHome()), goHome: () => dispatch(actions.goHome()),
displayWarning: warning => dispatch(actions.displayWarning(warning)), displayWarning: warning => dispatch(actions.displayWarning(warning)),
importNewJsonAccount: options => dispatch(actions.importNewAccount('JSON File', options)), importNewJsonAccount: options => dispatch(actions.importNewAccount('JSON File', options)),
setSelectedAddress: (address) => dispatch(actions.setSelectedAddress(address)),
} }
} }

View File

@ -21,6 +21,7 @@ module.exports = compose(
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
error: state.appState.warning, error: state.appState.warning,
firstAddress: Object.keys(state.metamask.accounts)[0],
} }
} }
@ -29,7 +30,8 @@ function mapDispatchToProps (dispatch) {
importNewAccount: (strategy, [ privateKey ]) => { importNewAccount: (strategy, [ privateKey ]) => {
return dispatch(actions.importNewAccount(strategy, [ privateKey ])) return dispatch(actions.importNewAccount(strategy, [ privateKey ]))
}, },
displayWarning: () => dispatch(actions.displayWarning(null)), displayWarning: (message) => dispatch(actions.displayWarning(message || null)),
setSelectedAddress: (address) => dispatch(actions.setSelectedAddress(address)),
} }
} }
@ -40,7 +42,7 @@ function PrivateKeyImportView () {
} }
PrivateKeyImportView.prototype.render = function () { PrivateKeyImportView.prototype.render = function () {
const { error } = this.props const { error, displayWarning } = this.props
return ( return (
h('div.new-account-import-form__private-key', [ h('div.new-account-import-form__private-key', [
@ -60,7 +62,10 @@ PrivateKeyImportView.prototype.render = function () {
h('div.new-account-import-form__buttons', {}, [ h('div.new-account-import-form__buttons', {}, [
h('button.btn-secondary--lg.new-account-create-form__button', { h('button.btn-secondary--lg.new-account-create-form__button', {
onClick: () => this.props.history.push(DEFAULT_ROUTE), onClick: () => {
displayWarning(null)
this.props.history.push(DEFAULT_ROUTE)
},
}, [ }, [
this.context.t('cancel'), this.context.t('cancel'),
]), ]),
@ -88,10 +93,17 @@ PrivateKeyImportView.prototype.createKeyringOnEnter = function (event) {
PrivateKeyImportView.prototype.createNewKeychain = function () { PrivateKeyImportView.prototype.createNewKeychain = function () {
const input = document.getElementById('private-key-box') const input = document.getElementById('private-key-box')
const privateKey = input.value const privateKey = input.value
const { importNewAccount, history } = this.props const { importNewAccount, history, displayWarning, setSelectedAddress, firstAddress } = this.props
importNewAccount('Private Key', [ privateKey ]) importNewAccount('Private Key', [ privateKey ])
// JS runtime requires caught rejections but failures are handled by Redux // JS runtime requires caught rejections but failures are handled by Redux
.catch() .catch()
.then(() => history.push(DEFAULT_ROUTE)) .then(({ selectedAddress }) => {
if (selectedAddress) {
history.push(DEFAULT_ROUTE)
} else {
displayWarning('Error importing account.')
setSelectedAddress(firstAddress)
}
})
} }