aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/app/actions.js39
-rw-r--r--ui/app/components/modals/export-private-key-modal.js21
2 files changed, 40 insertions, 20 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index 63d22238b..0b860ee63 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -106,6 +106,7 @@ var actions = {
exportAccount: exportAccount,
SHOW_PRIVATE_KEY: 'SHOW_PRIVATE_KEY',
showPrivateKey: showPrivateKey,
+ exportAccountComplete,
SAVE_ACCOUNT_LABEL: 'SAVE_ACCOUNT_LABEL',
saveAccountLabel: saveAccountLabel,
// tx conf screen
@@ -984,27 +985,39 @@ function exportAccount (password, address) {
dispatch(self.showLoadingIndication())
log.debug(`background.submitPassword`)
- background.submitPassword(password, function (err) {
- if (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())
-
+ return new Promise((resolve, reject) => {
+ background.submitPassword(password, function (err) {
if (err) {
- log.error(err)
- return dispatch(self.displayWarning('Had a problem exporting the account.'))
+ log.error('Error in submiting password.')
+ 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())
+
+ if (err) {
+ log.error(err)
+ dispatch(self.displayWarning('Had a problem exporting the account.'))
+ return reject(err)
+ }
- dispatch(self.showPrivateKey(result))
+ dispatch(self.exportAccountComplete())
+
+ return resolve(result)
+ })
})
})
}
}
+function exportAccountComplete() {
+ return {
+ type: actions.EXPORT_ACCOUNT,
+ }
+}
+
function showPrivateKey (key) {
return {
type: actions.SHOW_PRIVATE_KEY,
diff --git a/ui/app/components/modals/export-private-key-modal.js b/ui/app/components/modals/export-private-key-modal.js
index 4bb34f8c6..ddc7f1352 100644
--- a/ui/app/components/modals/export-private-key-modal.js
+++ b/ui/app/components/modals/export-private-key-modal.js
@@ -31,12 +31,20 @@ function ExportPrivateKeyModal () {
Component.call(this)
this.state = {
- password: ''
+ password: '',
+ privateKey: null,
}
}
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) {
return h('span.private-key-password-label', privateKey
? 'This is your private key (click to copy)'
@@ -68,15 +76,13 @@ ExportPrivateKeyModal.prototype.renderButton = function (className, onClick, lab
}, label)
}
-ExportPrivateKeyModal.prototype.renderButtons = function (privateKey, password, address) {
- const { hideModal, exportAccount } = this.props
-
+ExportPrivateKeyModal.prototype.renderButtons = function (privateKey, password, address, hideModal) {
return h('div.export-private-key-buttons', {}, [
!privateKey && this.renderButton('btn-clear btn-cancel', () => hideModal(), 'Cancel'),
(privateKey
? 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 {
selectedIdentity,
network,
- privateKey,
warning,
showAccountDetailModal,
hideModal,
@@ -94,6 +99,8 @@ ExportPrivateKeyModal.prototype.render = function () {
} = this.props
const { name, address } = selectedIdentity
+ const { privateKey } = this.state
+
return h(AccountModalContainer, {
showBackButton: previousModalState === 'ACCOUNT_DETAILS',
backButtonAction: () => showAccountDetailModal(),
@@ -124,7 +131,7 @@ ExportPrivateKeyModal.prototype.render = function () {
account.`
),
- this.renderButtons(privateKey, this.state.password, address),
+ this.renderButtons(privateKey, this.state.password, address, hideModal),
])
}