1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-23 18:41:38 +01:00
metamask-extension/ui/app/components/account-export.js

104 lines
2.9 KiB
JavaScript
Raw Normal View History

const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const copyToClipboard = require('copy-to-clipboard')
const actions = require('../actions')
const ethUtil = require('ethereumjs-util')
module.exports = ExportAccountView
inherits(ExportAccountView, Component)
2016-06-21 22:18:32 +02:00
function ExportAccountView () {
Component.call(this)
}
2016-06-21 22:18:32 +02:00
ExportAccountView.prototype.render = function () {
console.log('EXPORT VIEW')
console.dir(this.props)
var state = this.props
var accountDetail = state.accountDetail
if (!accountDetail) return h('div')
var accountExport = accountDetail.accountExport
var notExporting = accountExport === 'none'
var exportRequested = accountExport === 'requested'
var accountExported = accountExport === 'completed'
if (notExporting) return h('div')
if (exportRequested) {
var warning = `Exporting your private key is very dangerous,
and you should only do it if you know what you're doing.`
var confirmation = `If you're absolutely sure, type "I understand" below and
submit.`
2016-05-14 01:31:49 +02:00
return (
h('div', {
key: 'exporting',
style: {
margin: '0 20px',
},
}, [
h('p.error', warning),
h('p', confirmation),
2016-06-12 19:22:03 +02:00
h('input#exportAccount.sizing-input', {
2016-05-14 01:31:49 +02:00
onKeyPress: this.onExportKeyPress.bind(this),
2016-06-12 19:22:03 +02:00
style: {
position: 'relative',
top: '1.5px',
2016-06-21 22:18:32 +02:00
},
2016-05-14 01:31:49 +02:00
}),
h('button', {
onClick: () => this.onExportKeyPress({ key: 'Enter', preventDefault: () => {} }),
}, 'Submit'),
h('button', {
2016-06-21 22:18:32 +02:00
onClick: () => this.props.dispatch(actions.backToAccountDetail(this.props.address)),
2016-05-14 01:31:49 +02:00
}, 'Cancel'),
])
)
}
if (accountExported) {
return h('div.privateKey', {
style: {
margin: '0 20px',
},
}, [
h('label', 'Your private key (click to copy):'),
h('p.error.cursor-pointer', {
style: {
textOverflow: 'ellipsis',
overflow: 'hidden',
webkitUserSelect: 'text',
width: '100%',
},
2016-06-21 22:18:32 +02:00
onClick: function (event) {
copyToClipboard(ethUtil.stripHexPrefix(accountDetail.privateKey))
2016-06-21 22:18:32 +02:00
},
}, ethUtil.stripHexPrefix(accountDetail.privateKey)),
h('button', {
2016-06-21 22:18:32 +02:00
onClick: () => this.props.dispatch(actions.backToAccountDetail(this.props.address)),
}, 'Done'),
])
}
}
2016-06-21 22:18:32 +02:00
ExportAccountView.prototype.onExportKeyPress = function (event) {
if (event.key !== 'Enter') return
event.preventDefault()
var input = document.getElementById('exportAccount')
if (input.value === 'I understand') {
this.props.dispatch(actions.exportAccount(this.props.address))
} else {
input.value = ''
input.placeholder = 'Please retype "I understand" exactly.'
}
}
2016-06-21 22:18:32 +02:00
ExportAccountView.prototype.exportAccount = function (address) {
this.props.dispatch(actions.exportAccount(address))
}