nifty-wallet/old-ui/app/components/account-export.js

170 lines
4.5 KiB
JavaScript
Raw Normal View History

2017-11-14 08:04:23 -08:00
const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const exportAsFile = require('../util').exportAsFile
2017-11-15 09:35:18 -08:00
const actions = require('../../../ui/app/actions')
2017-11-14 08:04:23 -08:00
const ethUtil = require('ethereumjs-util')
const connect = require('react-redux').connect
const CopyButton = require('./copyButton')
2017-11-14 08:04:23 -08:00
module.exports = connect(mapStateToProps)(ExportAccountView)
inherits(ExportAccountView, Component)
function ExportAccountView () {
Component.call(this)
}
function mapStateToProps (state) {
return {
warning: state.appState.warning,
}
}
ExportAccountView.prototype.render = function () {
const state = this.props
const accountDetail = state.accountDetail
const nickname = state.identities[state.address].name
if (!accountDetail) return h('div')
const accountExport = accountDetail.accountExport
const notExporting = accountExport === 'none'
const exportRequested = accountExport === 'requested'
const accountExported = accountExport === 'completed'
if (notExporting) return h('div')
if (exportRequested) {
2018-07-26 13:31:11 -07:00
const warning = `Export private keys at your own risk`
2017-11-14 08:04:23 -08:00
return (
h('div', {
style: {
display: 'inline-block',
2018-07-26 13:31:11 -07:00
textAlign: 'right',
width: '100%',
2017-11-14 08:04:23 -08:00
},
},
[
h('div', {
key: 'exporting',
style: {
2018-07-26 13:31:11 -07:00
margin: '0 30px',
2017-11-14 08:04:23 -08:00
},
}, [
2018-07-27 09:54:23 -07:00
h('p.error', {
2018-07-26 13:31:11 -07:00
style: {
color: '#333333',
marginBottom: '0px',
marginTop: '30px',
2018-07-27 09:54:23 -07:00
},
2018-07-26 13:31:11 -07:00
}, warning),
2017-11-14 08:04:23 -08:00
h('input#exportAccount.sizing-input', {
type: 'password',
2018-07-26 13:31:11 -07:00
placeholder: 'Confirm Password',
2017-11-14 08:04:23 -08:00
onKeyPress: this.onExportKeyPress.bind(this),
style: {
position: 'relative',
2018-07-26 13:31:11 -07:00
top: '27px',
marginBottom: '20px',
width: '100%',
padding: '10px',
2017-11-14 08:04:23 -08:00
},
}),
]),
h('div', {
key: 'buttons',
style: {
2018-07-26 13:31:11 -07:00
margin: '25px 30px',
2017-11-14 08:04:23 -08:00
},
},
[
2018-07-26 04:42:04 -07:00
h('button.btn-violet', {
onClick: () => this.props.dispatch(actions.backToAccountDetail(this.props.address)),
2017-11-14 08:04:23 -08:00
}, 'Cancel'),
2018-07-26 04:42:04 -07:00
h('button', {
onClick: () => this.onExportKeyPress({ key: 'Enter', preventDefault: () => {} }),
}, 'Submit'),
2017-11-14 08:04:23 -08:00
]),
(this.props.warning) && (
2018-08-07 06:23:56 -07:00
h('div', {style: {
margin: '0 30px',
}},
[
h('div.error', this.props.warning.split('-')),
]
)
2017-11-14 08:04:23 -08:00
),
])
)
}
if (accountExported) {
const plainKey = ethUtil.stripHexPrefix(accountDetail.privateKey)
return h('div.privateKey', {
style: {
2018-07-26 13:31:11 -07:00
margin: '30px 30px',
width: '100%',
textAlign: 'center',
2017-11-14 08:04:23 -08:00
},
}, [
2018-07-26 13:31:11 -07:00
h('label', {
style: {
textAlign: 'center',
fontFamily: 'Nunito Semibold',
2018-07-27 09:54:23 -07:00
},
}, 'Your private key'),
h('div.flex-row', [
2018-08-06 11:11:06 -07:00
h('p', {
style: {
paddingTop: '25px',
textOverflow: 'ellipsis',
overflow: 'hidden',
webkitUserSelect: 'text',
maxWidth: '275px',
color: '#333333',
textAlign: 'center',
marginBottom: '0px',
},
}, plainKey),
h('div', {
style: {
paddingTop: '25px',
},
}, h(CopyButton, {
value: accountDetail.privateKey,
})
),
]),
2018-07-26 13:31:11 -07:00
h('div', {
2017-11-14 08:04:23 -08:00
style: {
2018-07-26 13:31:11 -07:00
textAlign: 'right',
marginTop: '30px',
2018-07-27 09:54:23 -07:00
},
2018-07-26 13:31:11 -07:00
}, [
h('button.btn-violet', {
onClick: () => exportAsFile(`Nifty Wallet ${nickname} Private Key`, plainKey),
}, 'Save as File'),
h('button', {
style: {
marginLeft: '10px',
},
onClick: () => this.props.dispatch(actions.backToAccountDetail(this.props.address)),
}, 'Done'),
2018-07-27 09:54:23 -07:00
]),
2017-11-14 08:04:23 -08:00
])
}
}
ExportAccountView.prototype.componentWillUnmount = function () {
this.props.dispatch(actions.displayWarning(''))
}
2017-11-14 08:04:23 -08:00
ExportAccountView.prototype.onExportKeyPress = function (event) {
if (event.key !== 'Enter') return
event.preventDefault()
const input = document.getElementById('exportAccount').value
this.props.dispatch(actions.exportAccount(input, this.props.address))
}