mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Keep privateKey out of state and clear it after closing export private key modal.
This commit is contained in:
parent
01816e1b22
commit
10345a12c2
@ -106,6 +106,7 @@ var actions = {
|
|||||||
exportAccount: exportAccount,
|
exportAccount: exportAccount,
|
||||||
SHOW_PRIVATE_KEY: 'SHOW_PRIVATE_KEY',
|
SHOW_PRIVATE_KEY: 'SHOW_PRIVATE_KEY',
|
||||||
showPrivateKey: showPrivateKey,
|
showPrivateKey: showPrivateKey,
|
||||||
|
exportAccountComplete,
|
||||||
SAVE_ACCOUNT_LABEL: 'SAVE_ACCOUNT_LABEL',
|
SAVE_ACCOUNT_LABEL: 'SAVE_ACCOUNT_LABEL',
|
||||||
saveAccountLabel: saveAccountLabel,
|
saveAccountLabel: saveAccountLabel,
|
||||||
// tx conf screen
|
// tx conf screen
|
||||||
@ -984,27 +985,39 @@ function exportAccount (password, address) {
|
|||||||
dispatch(self.showLoadingIndication())
|
dispatch(self.showLoadingIndication())
|
||||||
|
|
||||||
log.debug(`background.submitPassword`)
|
log.debug(`background.submitPassword`)
|
||||||
background.submitPassword(password, function (err) {
|
return new Promise((resolve, reject) => {
|
||||||
if (err) {
|
background.submitPassword(password, function (err) {
|
||||||
log.error('Error in submiting password.')
|
|
||||||
dispatch(self.hideLoadingIndication())
|
|
||||||
return dispatch(self.displayWarning('Incorrect Password.'))
|
|
||||||
}
|
|
||||||
log.debug(`background.exportAccount`)
|
|
||||||
background.exportAccount(address, function (err, result) {
|
|
||||||
dispatch(self.hideLoadingIndication())
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
log.error(err)
|
log.error('Error in submiting password.')
|
||||||
return dispatch(self.displayWarning('Had a problem exporting the account.'))
|
dispatch(self.hideLoadingIndication())
|
||||||
|
dispatch(self.displayWarning('Incorrect Password.'))
|
||||||
|
return reject(err)
|
||||||
}
|
}
|
||||||
|
log.debug(`background.exportAccount`)
|
||||||
|
return background.exportAccount(address, function (err, result) {
|
||||||
|
dispatch(self.hideLoadingIndication())
|
||||||
|
|
||||||
dispatch(self.showPrivateKey(result))
|
if (err) {
|
||||||
|
log.error(err)
|
||||||
|
dispatch(self.displayWarning('Had a problem exporting the account.'))
|
||||||
|
return reject(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(self.exportAccountComplete())
|
||||||
|
|
||||||
|
return resolve(result)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exportAccountComplete() {
|
||||||
|
return {
|
||||||
|
type: actions.EXPORT_ACCOUNT,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function showPrivateKey (key) {
|
function showPrivateKey (key) {
|
||||||
return {
|
return {
|
||||||
type: actions.SHOW_PRIVATE_KEY,
|
type: actions.SHOW_PRIVATE_KEY,
|
||||||
|
@ -31,12 +31,20 @@ function ExportPrivateKeyModal () {
|
|||||||
Component.call(this)
|
Component.call(this)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
password: ''
|
password: '',
|
||||||
|
privateKey: null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = connect(mapStateToProps, mapDispatchToProps)(ExportPrivateKeyModal)
|
module.exports = connect(mapStateToProps, mapDispatchToProps)(ExportPrivateKeyModal)
|
||||||
|
|
||||||
|
ExportPrivateKeyModal.prototype.exportAccountAndGetPrivateKey = function (password, address) {
|
||||||
|
const { exportAccount } = this.props
|
||||||
|
|
||||||
|
exportAccount(password, address)
|
||||||
|
.then(privateKey => this.setState({ privateKey }))
|
||||||
|
}
|
||||||
|
|
||||||
ExportPrivateKeyModal.prototype.renderPasswordLabel = function (privateKey) {
|
ExportPrivateKeyModal.prototype.renderPasswordLabel = function (privateKey) {
|
||||||
return h('span.private-key-password-label', privateKey
|
return h('span.private-key-password-label', privateKey
|
||||||
? 'This is your private key (click to copy)'
|
? 'This is your private key (click to copy)'
|
||||||
@ -68,15 +76,13 @@ ExportPrivateKeyModal.prototype.renderButton = function (className, onClick, lab
|
|||||||
}, label)
|
}, label)
|
||||||
}
|
}
|
||||||
|
|
||||||
ExportPrivateKeyModal.prototype.renderButtons = function (privateKey, password, address) {
|
ExportPrivateKeyModal.prototype.renderButtons = function (privateKey, password, address, hideModal) {
|
||||||
const { hideModal, exportAccount } = this.props
|
|
||||||
|
|
||||||
return h('div.export-private-key-buttons', {}, [
|
return h('div.export-private-key-buttons', {}, [
|
||||||
!privateKey && this.renderButton('btn-clear btn-cancel', () => hideModal(), 'Cancel'),
|
!privateKey && this.renderButton('btn-clear btn-cancel', () => hideModal(), 'Cancel'),
|
||||||
|
|
||||||
(privateKey
|
(privateKey
|
||||||
? this.renderButton('btn-clear', () => hideModal(), 'Done')
|
? this.renderButton('btn-clear', () => hideModal(), 'Done')
|
||||||
: this.renderButton('btn-clear', () => exportAccount(this.state.password, address), 'Download')
|
: this.renderButton('btn-clear', () => this.exportAccountAndGetPrivateKey(this.state.password, address), 'Download')
|
||||||
),
|
),
|
||||||
|
|
||||||
])
|
])
|
||||||
@ -86,7 +92,6 @@ ExportPrivateKeyModal.prototype.render = function () {
|
|||||||
const {
|
const {
|
||||||
selectedIdentity,
|
selectedIdentity,
|
||||||
network,
|
network,
|
||||||
privateKey,
|
|
||||||
warning,
|
warning,
|
||||||
showAccountDetailModal,
|
showAccountDetailModal,
|
||||||
hideModal,
|
hideModal,
|
||||||
@ -94,6 +99,8 @@ ExportPrivateKeyModal.prototype.render = function () {
|
|||||||
} = this.props
|
} = this.props
|
||||||
const { name, address } = selectedIdentity
|
const { name, address } = selectedIdentity
|
||||||
|
|
||||||
|
const { privateKey } = this.state
|
||||||
|
|
||||||
return h(AccountModalContainer, {
|
return h(AccountModalContainer, {
|
||||||
showBackButton: previousModalState === 'ACCOUNT_DETAILS',
|
showBackButton: previousModalState === 'ACCOUNT_DETAILS',
|
||||||
backButtonAction: () => showAccountDetailModal(),
|
backButtonAction: () => showAccountDetailModal(),
|
||||||
@ -124,7 +131,7 @@ ExportPrivateKeyModal.prototype.render = function () {
|
|||||||
account.`
|
account.`
|
||||||
),
|
),
|
||||||
|
|
||||||
this.renderButtons(privateKey, this.state.password, address),
|
this.renderButtons(privateKey, this.state.password, address, hideModal),
|
||||||
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user