Skip to content

Commit

Permalink
Merge pull request MetaMask#5102 from whymarrh/fix-account-export-pw-bug
Browse files Browse the repository at this point in the history
Fix export privkey modal password bugs
  • Loading branch information
whymarrh authored Aug 22, 2018
2 parents 171f671 + 743c6e7 commit f495c0e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ui/app/components/modals/account-details-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ AccountDetailsModal.prototype.render = function () {

let exportPrivateKeyFeatureEnabled = true
// This feature is disabled for hardware wallets
if (keyring.type.search('Hardware') !== -1) {
if (keyring && keyring.type.search('Hardware') !== -1) {
exportPrivateKeyFeatureEnabled = false
}

Expand Down
23 changes: 19 additions & 4 deletions ui/app/components/modals/export-private-key-modal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const log = require('loglevel')
const Component = require('react').Component
const PropTypes = require('prop-types')
const h = require('react-hyperscript')
Expand Down Expand Up @@ -31,7 +32,13 @@ function mapStateToPropsFactory () {

function mapDispatchToProps (dispatch) {
return {
exportAccount: (password, address) => dispatch(actions.exportAccount(password, address)),
exportAccount: (password, address) => {
return dispatch(actions.exportAccount(password, address))
.then((res) => {
dispatch(actions.hideWarning())
return res
})
},
showAccountDetailModal: () => dispatch(actions.showModal({ name: 'ACCOUNT_DETAILS' })),
hideModal: () => dispatch(actions.hideModal()),
}
Expand All @@ -44,6 +51,7 @@ function ExportPrivateKeyModal () {
this.state = {
password: '',
privateKey: null,
showWarning: true,
}
}

Expand All @@ -58,7 +66,11 @@ ExportPrivateKeyModal.prototype.exportAccountAndGetPrivateKey = function (passwo
const { exportAccount } = this.props

exportAccount(password, address)
.then(privateKey => this.setState({ privateKey }))
.then(privateKey => this.setState({
privateKey,
showWarning: false,
}))
.catch((e) => log.error(e))
}

ExportPrivateKeyModal.prototype.renderPasswordLabel = function (privateKey) {
Expand Down Expand Up @@ -118,7 +130,10 @@ ExportPrivateKeyModal.prototype.render = function () {
} = this.props
const { name, address } = selectedIdentity

const { privateKey } = this.state
const {
privateKey,
showWarning,
} = this.state

return h(AccountModalContainer, {
selectedIdentity,
Expand All @@ -143,7 +158,7 @@ ExportPrivateKeyModal.prototype.render = function () {

this.renderPasswordInput(privateKey),

!warning ? null : h('span.private-key-password-error', warning),
showWarning && warning ? h('span.private-key-password-error', warning) : null,
]),

h('div.private-key-password-warning', this.context.t('privateKeyWarning')),
Expand Down

0 comments on commit f495c0e

Please sign in to comment.