aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/accounts/import/private-key.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-01-18 08:22:22 +0800
committerDan Finlay <dan@danfinlay.com>2017-01-18 08:24:45 +0800
commit1ff4894b674bbcbac1998228454129018e4642b6 (patch)
tree5ddf81cc89253ea6ca8a19f19cee0efe328c2742 /ui/app/accounts/import/private-key.js
parent958cbfbde44c201cf71f5dfcb7b1748bb43e597f (diff)
downloadtangerine-wallet-browser-1ff4894b674bbcbac1998228454129018e4642b6.tar.gz
tangerine-wallet-browser-1ff4894b674bbcbac1998228454129018e4642b6.tar.zst
tangerine-wallet-browser-1ff4894b674bbcbac1998228454129018e4642b6.zip
Allow importing of private key strings
Fixes #1021 A top-right menu item now allows `Account Import`. It has a menu (with one item for now) that allows importing a private key string. Errors are displayed, and a success navigates the user to their account list, where the imported account is labeled `LOOSE`.
Diffstat (limited to 'ui/app/accounts/import/private-key.js')
-rw-r--r--ui/app/accounts/import/private-key.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/ui/app/accounts/import/private-key.js b/ui/app/accounts/import/private-key.js
new file mode 100644
index 000000000..6b988a76b
--- /dev/null
+++ b/ui/app/accounts/import/private-key.js
@@ -0,0 +1,69 @@
+const inherits = require('util').inherits
+const Component = require('react').Component
+const h = require('react-hyperscript')
+const connect = require('react-redux').connect
+const type = 'Simple Key Pair'
+const actions = require('../../actions')
+
+module.exports = connect(mapStateToProps)(PrivateKeyImportView)
+
+function mapStateToProps (state) {
+ return {
+ error: state.appState.warning,
+ }
+}
+
+inherits(PrivateKeyImportView, Component)
+function PrivateKeyImportView () {
+ Component.call(this)
+}
+
+PrivateKeyImportView.prototype.render = function () {
+ const { error } = this.props
+
+ return (
+ h('div', {
+ style: {
+ display: 'flex',
+ flexDirection: 'column',
+ alignItems: 'center',
+ padding: '5px 15px 0px 15px',
+ },
+ }, [
+ h('span', 'Paste your private key string here'),
+
+ h('input.large-input.letter-spacey', {
+ type: 'password',
+ id: 'private-key-box',
+ onKeyPress: this.createKeyringOnEnter.bind(this),
+ style: {
+ width: 260,
+ marginTop: 12,
+ },
+ }),
+
+ h('button.primary', {
+ onClick: this.createNewKeychain.bind(this),
+ style: {
+ margin: 12,
+ },
+ }, 'Import'),
+
+ error ? h('span.warning', error) : null,
+ ])
+ )
+}
+
+PrivateKeyImportView.prototype.createKeyringOnEnter = function (event) {
+ if (event.key === 'Enter') {
+ event.preventDefault()
+ this.createNewKeychain()
+ }
+}
+
+PrivateKeyImportView.prototype.createNewKeychain = function () {
+ const input = document.getElementById('private-key-box')
+ const privateKey = input.value
+ this.props.dispatch(actions.addNewKeyring(type, [ privateKey ]))
+}
+