diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-01-18 08:22:22 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-01-18 08:24:45 +0800 |
commit | 1ff4894b674bbcbac1998228454129018e4642b6 (patch) | |
tree | 5ddf81cc89253ea6ca8a19f19cee0efe328c2742 /app/scripts | |
parent | 958cbfbde44c201cf71f5dfcb7b1748bb43e597f (diff) | |
download | tangerine-wallet-browser-1ff4894b674bbcbac1998228454129018e4642b6.tar tangerine-wallet-browser-1ff4894b674bbcbac1998228454129018e4642b6.tar.gz tangerine-wallet-browser-1ff4894b674bbcbac1998228454129018e4642b6.tar.bz2 tangerine-wallet-browser-1ff4894b674bbcbac1998228454129018e4642b6.tar.lz tangerine-wallet-browser-1ff4894b674bbcbac1998228454129018e4642b6.tar.xz 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 'app/scripts')
-rw-r--r-- | app/scripts/keyring-controller.js | 5 | ||||
-rw-r--r-- | app/scripts/keyrings/simple.js | 18 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 7 |
3 files changed, 22 insertions, 8 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 4be00a5a5..e609403cc 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -234,7 +234,10 @@ module.exports = class KeyringController extends EventEmitter { addNewKeyring (type, opts) { const Keyring = this.getKeyringClassForType(type) const keyring = new Keyring(opts) - return keyring.getAccounts() + return keyring.deserialize(opts) + .then(() => { + return keyring.getAccounts() + }) .then((accounts) => { this.keyrings.push(keyring) return this.setupAccounts(accounts) diff --git a/app/scripts/keyrings/simple.js b/app/scripts/keyrings/simple.js index d604430b8..46687fcaf 100644 --- a/app/scripts/keyrings/simple.js +++ b/app/scripts/keyrings/simple.js @@ -20,13 +20,19 @@ class SimpleKeyring extends EventEmitter { } deserialize (privateKeys = []) { - this.wallets = privateKeys.map((privateKey) => { - const stripped = ethUtil.stripHexPrefix(privateKey) - const buffer = new Buffer(stripped, 'hex') - const wallet = Wallet.fromPrivateKey(buffer) - return wallet + return new Promise((resolve, reject) => { + try { + this.wallets = privateKeys.map((privateKey) => { + const stripped = ethUtil.stripHexPrefix(privateKey) + const buffer = new Buffer(stripped, 'hex') + const wallet = Wallet.fromPrivateKey(buffer) + return wallet + }) + } catch (e) { + reject(e) + } + resolve() }) - return Promise.resolve() } addAccounts (n = 1) { diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index b94b98eac..629216e42 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -115,7 +115,12 @@ module.exports = class MetamaskController extends EventEmitter { .then((newState) => { cb(null, newState) }) .catch((reason) => { cb(reason) }) }, - addNewKeyring: nodeify(keyringController.addNewKeyring).bind(keyringController), + addNewKeyring: (type, opts, cb) => { + keyringController.addNewKeyring(type, opts) + .then(() => keyringController.fullUpdate()) + .then((newState) => { cb(null, newState) }) + .catch((reason) => { cb(reason) }) + }, addNewAccount: nodeify(keyringController.addNewAccount).bind(keyringController), setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController), saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController), |