aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/modals
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2017-09-20 20:32:18 +0800
committerChi Kei Chan <chikeichan@gmail.com>2017-09-27 00:05:29 +0800
commit7102772c3a4a73d594ccc20e760defa2999f2d3f (patch)
tree5514016e0b816cf60c7a2b108d635fdced84c4f6 /ui/app/components/modals
parentd1737777f0fcc78cf034c52aa1fb039f40eca4e2 (diff)
downloadtangerine-wallet-browser-7102772c3a4a73d594ccc20e760defa2999f2d3f.tar
tangerine-wallet-browser-7102772c3a4a73d594ccc20e760defa2999f2d3f.tar.gz
tangerine-wallet-browser-7102772c3a4a73d594ccc20e760defa2999f2d3f.tar.bz2
tangerine-wallet-browser-7102772c3a4a73d594ccc20e760defa2999f2d3f.tar.lz
tangerine-wallet-browser-7102772c3a4a73d594ccc20e760defa2999f2d3f.tar.xz
tangerine-wallet-browser-7102772c3a4a73d594ccc20e760defa2999f2d3f.tar.zst
tangerine-wallet-browser-7102772c3a4a73d594ccc20e760defa2999f2d3f.zip
Connect export key modal to state and enable actions.
Diffstat (limited to 'ui/app/components/modals')
-rw-r--r--ui/app/components/modals/export-private-key-modal.js85
1 files changed, 72 insertions, 13 deletions
diff --git a/ui/app/components/modals/export-private-key-modal.js b/ui/app/components/modals/export-private-key-modal.js
index 28b988f5a..b1d551781 100644
--- a/ui/app/components/modals/export-private-key-modal.js
+++ b/ui/app/components/modals/export-private-key-modal.js
@@ -2,6 +2,7 @@ const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const connect = require('react-redux').connect
+const ethUtil = require('ethereumjs-util')
const actions = require('../../actions')
const AccountModalContainer = require('./account-modal-container')
const { getSelectedIdentity } = require('../../selectors')
@@ -9,20 +10,83 @@ const ReadOnlyInput = require('../readonly-input')
function mapStateToProps (state) {
return {
+ warning: state.appState.warning,
+ privateKey: state.appState.accountDetail.privateKey,
network: state.metamask.network,
selectedIdentity: getSelectedIdentity(state),
}
}
+function mapDispatchToProps (dispatch) {
+ return {
+ exportAccount: (password, address) => dispatch(actions.exportAccount(password, address)),
+ hideModal: () => dispatch(actions.hideModal()),
+ }
+}
+
inherits(ExportPrivateKeyModal, Component)
function ExportPrivateKeyModal () {
Component.call(this)
+
+ this.state = {
+ password: ''
+ }
+}
+
+module.exports = connect(mapStateToProps, mapDispatchToProps)(ExportPrivateKeyModal)
+
+ExportPrivateKeyModal.prototype.renderPasswordLabel = function (privateKey) {
+ return h('span.private-key-password-label', privateKey
+ ? 'This is your private key (click to copy)'
+ : 'Type Your Password'
+ )
+}
+
+ExportPrivateKeyModal.prototype.renderPasswordInput = function (privateKey) {
+ const plainKey = privateKey && ethUtil.stripHexPrefix(privateKey)
+
+ return privateKey
+ ? h(ReadOnlyInput, {
+ wrapperClass: 'private-key-password-display-wrapper',
+ inputClass: 'private-key-password-display-textarea',
+ textarea: true,
+ value: plainKey,
+ })
+ : h('input.private-key-password-input', {
+ type: 'password',
+ placeholder: 'Type password',
+ onChange: event => this.setState({ password: event.target.value })
+ })
+}
+
+ExportPrivateKeyModal.prototype.renderButton = function (className, onClick, label) {
+ return h('button', {
+ className,
+ onClick,
+ }, label)
}
-module.exports = connect(mapStateToProps)(ExportPrivateKeyModal)
+ExportPrivateKeyModal.prototype.renderButtons = function (privateKey, password, address) {
+ const { hideModal, exportAccount } = this.props
+
+ 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')
+ ),
+
+ ])
+}
ExportPrivateKeyModal.prototype.render = function () {
- const { selectedIdentity, network } = this.props
+ const {
+ selectedIdentity,
+ network,
+ privateKey,
+ warning,
+ } = this.props
const { name, address } = selectedIdentity
return h(AccountModalContainer, {}, [
@@ -31,7 +95,7 @@ ExportPrivateKeyModal.prototype.render = function () {
h(ReadOnlyInput, {
wrapperClass: 'ellip-address-wrapper',
- inputClass: 'ellip-address',
+ inputClass: 'qr-ellip-address ellip-address',
value: address,
}),
@@ -40,12 +104,11 @@ ExportPrivateKeyModal.prototype.render = function () {
h('span.modal-body-title', 'Download Private Keys'),
h('div.private-key-password', {}, [
- h('span.private-key-password-label', 'Type Your Password'),
+ this.renderPasswordLabel(privateKey),
+
+ this.renderPasswordInput(privateKey),
- h('input.private-key-password-input', {
- type: 'password',
- placeholder: 'Type password',
- }),
+ !warning ? null : h('span.private-key-password-error', warning),
]),
h('div.private-key-password-warning', `Warning: Never disclose this key.
@@ -53,11 +116,7 @@ ExportPrivateKeyModal.prototype.render = function () {
account.`
),
- h('div.export-private-key-buttons', {}, [
- h('button.btn-clear.btn-cancel', {}, 'Cancel'),
-
- h('button.btn-clear', 'Download'),
- ]),
+ this.renderButtons(privateKey, this.state.password, address),
])
}