2016-05-05 03:08:31 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-09-12 01:22:20 +02:00
|
|
|
const exportAsFile = require('../util').exportAsFile
|
2016-05-23 03:01:47 +02:00
|
|
|
const copyToClipboard = require('copy-to-clipboard')
|
2016-05-05 03:08:31 +02:00
|
|
|
const actions = require('../actions')
|
2016-10-04 22:26:51 +02:00
|
|
|
const ethUtil = require('ethereumjs-util')
|
2017-03-21 16:53:34 +01:00
|
|
|
const connect = require('react-redux').connect
|
2016-05-05 03:08:31 +02:00
|
|
|
|
2017-03-21 16:53:34 +01:00
|
|
|
module.exports = connect(mapStateToProps)(ExportAccountView)
|
2016-05-05 03:08:31 +02:00
|
|
|
|
|
|
|
inherits(ExportAccountView, Component)
|
2016-06-21 22:18:32 +02:00
|
|
|
function ExportAccountView () {
|
2016-05-05 03:08:31 +02:00
|
|
|
Component.call(this)
|
|
|
|
}
|
|
|
|
|
2017-03-21 16:53:34 +01:00
|
|
|
function mapStateToProps (state) {
|
|
|
|
return {
|
|
|
|
warning: state.appState.warning,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
ExportAccountView.prototype.render = function () {
|
2017-09-12 01:13:28 +02:00
|
|
|
const state = this.props
|
|
|
|
const accountDetail = state.accountDetail
|
|
|
|
const nickname = state.identities[state.address].name
|
2016-05-05 03:08:31 +02:00
|
|
|
|
|
|
|
if (!accountDetail) return h('div')
|
2017-09-12 01:13:28 +02:00
|
|
|
const accountExport = accountDetail.accountExport
|
2016-05-05 03:08:31 +02:00
|
|
|
|
2017-09-12 01:13:28 +02:00
|
|
|
const notExporting = accountExport === 'none'
|
|
|
|
const exportRequested = accountExport === 'requested'
|
|
|
|
const accountExported = accountExport === 'completed'
|
2016-05-05 03:08:31 +02:00
|
|
|
|
|
|
|
if (notExporting) return h('div')
|
|
|
|
|
|
|
|
if (exportRequested) {
|
2017-09-12 01:13:28 +02:00
|
|
|
const warning = `Export private keys at your own risk.`
|
2016-05-14 01:31:49 +02:00
|
|
|
return (
|
|
|
|
h('div', {
|
|
|
|
style: {
|
2017-03-21 16:53:34 +01:00
|
|
|
display: 'inline-block',
|
|
|
|
textAlign: 'center',
|
2016-05-14 01:31:49 +02:00
|
|
|
},
|
2017-03-21 16:53:34 +01:00
|
|
|
},
|
|
|
|
[
|
|
|
|
h('div', {
|
|
|
|
key: 'exporting',
|
|
|
|
style: {
|
|
|
|
margin: '0 20px',
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
h('p.error', warning),
|
|
|
|
h('input#exportAccount.sizing-input', {
|
2017-03-22 22:46:51 +01:00
|
|
|
type: 'password',
|
2017-03-21 16:53:34 +01:00
|
|
|
placeholder: 'confirm password',
|
|
|
|
onKeyPress: this.onExportKeyPress.bind(this),
|
|
|
|
style: {
|
|
|
|
position: 'relative',
|
|
|
|
top: '1.5px',
|
|
|
|
marginBottom: '7px',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
]),
|
|
|
|
h('div', {
|
|
|
|
key: 'buttons',
|
|
|
|
style: {
|
|
|
|
margin: '0 20px',
|
|
|
|
},
|
2016-06-21 22:18:32 +02:00
|
|
|
},
|
2017-03-21 16:53:34 +01:00
|
|
|
[
|
|
|
|
h('button', {
|
|
|
|
onClick: () => this.onExportKeyPress({ key: 'Enter', preventDefault: () => {} }),
|
|
|
|
style: {
|
|
|
|
marginRight: '10px',
|
|
|
|
},
|
|
|
|
}, 'Submit'),
|
|
|
|
h('button', {
|
|
|
|
onClick: () => this.props.dispatch(actions.backToAccountDetail(this.props.address)),
|
|
|
|
}, 'Cancel'),
|
|
|
|
]),
|
|
|
|
(this.props.warning) && (
|
|
|
|
h('span.error', {
|
|
|
|
style: {
|
|
|
|
margin: '20px',
|
|
|
|
},
|
|
|
|
}, this.props.warning.split('-'))
|
|
|
|
),
|
|
|
|
])
|
2016-05-14 01:31:49 +02:00
|
|
|
)
|
2016-05-05 03:08:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (accountExported) {
|
2017-09-12 01:13:28 +02:00
|
|
|
const plainKey = ethUtil.stripHexPrefix(accountDetail.privateKey)
|
|
|
|
|
2016-05-05 03:08:31 +02:00
|
|
|
return h('div.privateKey', {
|
2016-10-04 22:26:51 +02:00
|
|
|
style: {
|
|
|
|
margin: '0 20px',
|
|
|
|
},
|
2016-05-05 03:08:31 +02:00
|
|
|
}, [
|
|
|
|
h('label', 'Your private key (click to copy):'),
|
|
|
|
h('p.error.cursor-pointer', {
|
|
|
|
style: {
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
overflow: 'hidden',
|
|
|
|
webkitUserSelect: 'text',
|
2017-08-04 01:00:44 +02:00
|
|
|
maxWidth: '275px',
|
2016-05-05 03:08:31 +02:00
|
|
|
},
|
2016-06-21 22:18:32 +02:00
|
|
|
onClick: function (event) {
|
2016-10-04 22:26:51 +02:00
|
|
|
copyToClipboard(ethUtil.stripHexPrefix(accountDetail.privateKey))
|
2016-06-21 22:18:32 +02:00
|
|
|
},
|
2017-09-12 01:13:28 +02:00
|
|
|
}, plainKey),
|
2016-05-05 03:08:31 +02:00
|
|
|
h('button', {
|
2016-06-21 22:18:32 +02:00
|
|
|
onClick: () => this.props.dispatch(actions.backToAccountDetail(this.props.address)),
|
2016-05-05 03:08:31 +02:00
|
|
|
}, 'Done'),
|
2017-09-12 01:13:28 +02:00
|
|
|
h('button', {
|
2017-09-12 01:52:35 +02:00
|
|
|
style: {
|
2017-09-12 01:40:45 +02:00
|
|
|
marginLeft: '10px',
|
|
|
|
},
|
2017-09-12 01:52:35 +02:00
|
|
|
onClick: () => exportAsFile(`MetaMask ${nickname} Private Key`, plainKey),
|
2017-09-12 01:13:28 +02:00
|
|
|
}, 'Save as File'),
|
2016-05-05 03:08:31 +02:00
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
ExportAccountView.prototype.onExportKeyPress = function (event) {
|
2016-05-05 03:08:31 +02:00
|
|
|
if (event.key !== 'Enter') return
|
|
|
|
event.preventDefault()
|
|
|
|
|
2017-09-12 01:13:28 +02:00
|
|
|
const input = document.getElementById('exportAccount').value
|
2017-03-21 16:53:34 +01:00
|
|
|
this.props.dispatch(actions.exportAccount(input, this.props.address))
|
2016-05-05 03:08:31 +02:00
|
|
|
}
|