From 2f79781ab9fbdde018fc921da9be0b3411ed8cad Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 20:17:36 -0800 Subject: metamask controller - adopt clearSeedWords from keyring controller --- app/scripts/keyring-controller.js | 11 ----------- app/scripts/metamask-controller.js | 13 +++++++++---- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 0a1965782..61840af4c 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -154,17 +154,6 @@ module.exports = class KeyringController extends EventEmitter { .then(this.fullUpdate.bind(this)) } - // ClearSeedWordCache - // - // returns Promise( @string currentSelectedAccount ) - // - // Removes the current vault's seed words from the UI's state tree, - // ensuring they are only ever available in the background process. - clearSeedWordCache () { - this.configManager.setSeedWords(null) - return Promise.resolve(this.configManager.getSelectedAccount()) - } - // Set Locked // returns Promise( @object state ) // diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 3e6ce0a2e..83dc2a9b9 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -146,7 +146,14 @@ module.exports = class MetamaskController extends EventEmitter { promiseToCallback(this.keyringController.fullUpdate())(cb) }) }, - clearSeedWordCache: nodeify(keyringController.clearSeedWordCache).bind(keyringController), + // ClearSeedWordCache + // + // Removes the primary account's seed words from the UI's state tree, + // ensuring they are only ever available in the background process. + clearSeedWordCache: (cb) => { + this.configManager.setSeedWords(null) + cb(null, this.configManager.getSelectedAccount()) + }, setLocked: nodeify(keyringController.setLocked).bind(keyringController), submitPassword: (password, cb) => { this.migrateOldVaultIfAny(password) @@ -321,9 +328,7 @@ module.exports = class MetamaskController extends EventEmitter { setupPublicConfig (outStream) { pipe( this.publicConfigStore, - outStream, - // cleanup on disconnect - () => this.publicConfigStore.unpipe(outStream) + outStream ) } -- cgit From fc3a53ec7b2af538d5e9748173fb11b5a09a4e84 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 20:18:28 -0800 Subject: background - stream disconnection fix --- app/scripts/background.js | 7 +++---- app/scripts/lib/stream-utils.js | 9 +++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/scripts/background.js b/app/scripts/background.js index 18882e5d5..744a0caee 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -122,17 +122,16 @@ function setupController (initState) { // remote features // - function setupControllerConnection (stream) { - controller.stream = stream + function setupControllerConnection (outStream) { var api = controller.getApi() var dnode = Dnode(api) - stream.pipe(dnode).pipe(stream) + outStream.pipe(dnode).pipe(outStream) dnode.on('remote', (remote) => { // push updates to popup var sendUpdate = remote.sendUpdate.bind(remote) controller.on('update', sendUpdate) // teardown on disconnect - eos(stream, () => { + eos(outStream, () => { controller.removeListener('update', sendUpdate) popupIsOpen = false }) diff --git a/app/scripts/lib/stream-utils.js b/app/scripts/lib/stream-utils.js index 1b7b89d14..ba79990cc 100644 --- a/app/scripts/lib/stream-utils.js +++ b/app/scripts/lib/stream-utils.js @@ -1,4 +1,5 @@ const Through = require('through2') +const endOfStream = require('end-of-stream') const ObjectMultiplex = require('./obj-multiplex') module.exports = { @@ -24,11 +25,11 @@ function jsonStringifyStream () { function setupMultiplex (connectionStream) { var mx = ObjectMultiplex() connectionStream.pipe(mx).pipe(connectionStream) - mx.on('error', function (err) { - console.error(err) + endOfStream(mx, function (err) { + if (err) console.error(err) }) - connectionStream.on('error', function (err) { - console.error(err) + endOfStream(connectionStream, function (err) { + if (err) console.error(err) mx.destroy() }) return mx -- cgit From 2113979be7ee257c2650916c2c48f68c6390ef1f Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 20:52:46 -0800 Subject: metamask controller - adopt setup*Communication from background --- app/scripts/background.js | 52 ++++++++------------------------------ app/scripts/metamask-controller.js | 33 ++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 44 deletions(-) diff --git a/app/scripts/background.js b/app/scripts/background.js index 744a0caee..da9c4f24b 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -1,6 +1,5 @@ const urlUtil = require('url') -const Dnode = require('dnode') -const eos = require('end-of-stream') +const endOfStream = require('end-of-stream') const asyncQ = require('async-q') const pipe = require('pump') const LocalStorageStore = require('obs-store/lib/localStorage') @@ -10,7 +9,6 @@ const migrations = require('./migrations/') const PortStream = require('./lib/port-stream.js') const notification = require('./lib/notifications.js') const messageManager = require('./lib/message-manager') -const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex const MetamaskController = require('./metamask-controller') const extension = require('./lib/extension') const firstTimeState = require('./first-time-state') @@ -93,51 +91,21 @@ function setupController (initState) { var portStream = new PortStream(remotePort) if (isMetaMaskInternalProcess) { // communication with popup - popupIsOpen = remotePort.name === 'popup' - setupTrustedCommunication(portStream, 'MetaMask', remotePort.name) + popupIsOpen = popupIsOpen || (remotePort.name === 'popup') + controller.setupTrustedCommunication(portStream, 'MetaMask', remotePort.name) + // record popup as closed + if (remotePort.name === 'popup') { + endOfStream(portStream, () => { + popupIsOpen = false + }) + } } else { // communication with page var originDomain = urlUtil.parse(remotePort.sender.url).hostname - setupUntrustedCommunication(portStream, originDomain) + controller.setupUntrustedCommunication(portStream, originDomain) } } - function setupUntrustedCommunication (connectionStream, originDomain) { - // setup multiplexing - var mx = setupMultiplex(connectionStream) - // connect features - controller.setupProviderConnection(mx.createStream('provider'), originDomain) - controller.setupPublicConfig(mx.createStream('publicConfig')) - } - - function setupTrustedCommunication (connectionStream, originDomain) { - // setup multiplexing - var mx = setupMultiplex(connectionStream) - // connect features - setupControllerConnection(mx.createStream('controller')) - controller.setupProviderConnection(mx.createStream('provider'), originDomain) - } - - // - // remote features - // - - function setupControllerConnection (outStream) { - var api = controller.getApi() - var dnode = Dnode(api) - outStream.pipe(dnode).pipe(outStream) - dnode.on('remote', (remote) => { - // push updates to popup - var sendUpdate = remote.sendUpdate.bind(remote) - controller.on('update', sendUpdate) - // teardown on disconnect - eos(outStream, () => { - controller.removeListener('update', sendUpdate) - popupIsOpen = false - }) - }) - } - // // User Interface setup // diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 83dc2a9b9..1429c02ca 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -2,11 +2,13 @@ const EventEmitter = require('events') const extend = require('xtend') const promiseToCallback = require('promise-to-callback') const pipe = require('pump') +const Dnode = require('dnode') const ObservableStore = require('obs-store') const storeTransform = require('obs-store/lib/transform') const EthStore = require('./lib/eth-store') const EthQuery = require('eth-query') const MetaMaskProvider = require('web3-provider-engine/zero.js') +const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex const KeyringController = require('./keyring-controller') const NoticeController = require('./notice-controller') const messageManager = require('./lib/message-manager') @@ -202,8 +204,35 @@ module.exports = class MetamaskController extends EventEmitter { } } - setupProviderConnection (stream, originDomain) { - stream.on('data', this.onRpcRequest.bind(this, stream, originDomain)) + setupUntrustedCommunication (connectionStream, originDomain) { + // setup multiplexing + var mx = setupMultiplex(connectionStream) + // connect features + this.setupProviderConnection(mx.createStream('provider'), originDomain) + this.setupPublicConfig(mx.createStream('publicConfig')) + } + + setupTrustedCommunication (connectionStream, originDomain) { + // setup multiplexing + var mx = setupMultiplex(connectionStream) + // connect features + this.setupControllerConnection(mx.createStream('controller')) + this.setupProviderConnection(mx.createStream('provider'), originDomain) + } + + setupControllerConnection (outStream) { + const api = this.getApi() + const dnode = Dnode(api) + outStream.pipe(dnode).pipe(outStream) + dnode.on('remote', (remote) => { + // push updates to popup + const sendUpdate = remote.sendUpdate.bind(remote) + this.on('update', sendUpdate) + }) + } + + setupProviderConnection (outStream, originDomain) { + outStream.on('data', this.onRpcRequest.bind(this, outStream, originDomain)) } onRpcRequest (stream, originDomain, request) { -- cgit From 9616bd826d93a204cb20948dd86ff54fc6d616d2 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 20:53:48 -0800 Subject: test - lint first --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 67bd3b209..bf4b3986c 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "dev": "gulp dev --debug", "disc": "gulp disc --debug", "dist": "gulp dist --disableLiveReload", - "test": "npm run fastTest && npm run ci && npm run lint", + "test": "npm run lint && npm run fastTest && npm run ci", "fastTest": "METAMASK_ENV=test mocha --require test/helper.js --compilers js:babel-register --recursive \"test/unit/**/*.js\"", "watch": "mocha watch --compilers js:babel-register --recursive \"test/unit/**/*.js\"", "genStates": "node development/genStates.js", -- cgit From 832772414e8dba08e0fcfefea59a4e24b1f4a0d3 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 21:18:17 -0800 Subject: metamask - use web3-stream-provider/handler instead of manual wiring --- app/scripts/metamask-controller.js | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 1429c02ca..ec5fd498b 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -7,6 +7,7 @@ const ObservableStore = require('obs-store') const storeTransform = require('obs-store/lib/transform') const EthStore = require('./lib/eth-store') const EthQuery = require('eth-query') +const streamIntoProvider = require('web3-stream-provider/handler') const MetaMaskProvider = require('web3-provider-engine/zero.js') const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex const KeyringController = require('./keyring-controller') @@ -232,31 +233,15 @@ module.exports = class MetamaskController extends EventEmitter { } setupProviderConnection (outStream, originDomain) { - outStream.on('data', this.onRpcRequest.bind(this, outStream, originDomain)) - } - - onRpcRequest (stream, originDomain, request) { - // handle rpc request - this.provider.sendAsync(request, function onPayloadHandled (err, response) { - logger(err, request, response) - if (response) { - try { - stream.write(response) - } catch (err) { - logger(err) - } - } - }) - + streamIntoProvider(outStream, originDomain, logger) function logger (err, request, response) { if (err) return console.error(err) - if (!request.isMetamaskInternal) { - if (global.METAMASK_DEBUG) { - console.log(`RPC (${originDomain}):`, request, '->', response) - } - if (response.error) { - console.error('Error in RPC response:\n', response.error) - } + if (response.error) { + console.error('Error in RPC response:\n', response.error) + } + if (request.isMetamaskInternal) return + if (global.METAMASK_DEBUG) { + console.log(`RPC (${originDomain}):`, request, '->', response) } } } -- cgit From fc1b11e373851ad4ab3a3f74e7d6850aebe6ba82 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 21:19:09 -0800 Subject: metamask - organize into sections --- app/scripts/metamask-controller.js | 110 ++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 49 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index ec5fd498b..841e35db2 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -98,6 +98,63 @@ module.exports = class MetamaskController extends EventEmitter { this.txManager.on('update', this.sendUpdate.bind(this)) } + // + // Constructor helpers + // + + initializeProvider () { + let provider = MetaMaskProvider({ + static: { + eth_syncing: false, + web3_clientVersion: `MetaMask/v${version}`, + }, + rpcUrl: this.configManager.getCurrentRpcAddress(), + // account mgmt + getAccounts: (cb) => { + let selectedAccount = this.configManager.getSelectedAccount() + let result = selectedAccount ? [selectedAccount] : [] + cb(null, result) + }, + // tx signing + processTransaction: (txParams, cb) => this.newUnapprovedTransaction(txParams, cb), + // msg signing + approveMessage: this.newUnsignedMessage.bind(this), + signMessage: (...args) => { + this.keyringController.signMessage(...args) + this.sendUpdate() + }, + }) + return provider + } + + initPublicConfigStore () { + // get init state + const publicConfigStore = new ObservableStore() + + // sync publicConfigStore with transform + pipe( + this.store, + storeTransform(selectPublicState), + publicConfigStore + ) + + function selectPublicState(state) { + const result = { selectedAccount: undefined } + try { + result.selectedAccount = state.config.selectedAccount + } catch (_) { + // thats fine, im sure it will be there next time... + } + return result + } + + return publicConfigStore + } + + // + // Constructor helpers + // + getState () { return this.keyringController.getState() .then((keyringControllerState) => { @@ -114,6 +171,10 @@ module.exports = class MetamaskController extends EventEmitter { }) } + // + // Remote Features + // + getApi () { const keyringController = this.keyringController const txManager = this.txManager @@ -253,55 +314,6 @@ module.exports = class MetamaskController extends EventEmitter { }) } - initializeProvider () { - let provider = MetaMaskProvider({ - static: { - eth_syncing: false, - web3_clientVersion: `MetaMask/v${version}`, - }, - rpcUrl: this.configManager.getCurrentRpcAddress(), - // account mgmt - getAccounts: (cb) => { - let selectedAccount = this.configManager.getSelectedAccount() - let result = selectedAccount ? [selectedAccount] : [] - cb(null, result) - }, - // tx signing - processTransaction: (txParams, cb) => this.newUnapprovedTransaction(txParams, cb), - // msg signing - approveMessage: this.newUnsignedMessage.bind(this), - signMessage: (...args) => { - this.keyringController.signMessage(...args) - this.sendUpdate() - }, - }) - return provider - } - - initPublicConfigStore () { - // get init state - const publicConfigStore = new ObservableStore() - - // sync publicConfigStore with transform - pipe( - this.store, - storeTransform(selectPublicState), - publicConfigStore - ) - - function selectPublicState(state) { - const result = { selectedAccount: undefined } - try { - result.selectedAccount = state.config.selectedAccount - } catch (_) { - // thats fine, im sure it will be there next time... - } - return result - } - - return publicConfigStore - } - newUnapprovedTransaction (txParams, cb) { const self = this self.txManager.addUnapprovedTransaction(txParams, (err, txMeta) => { -- cgit From 9ab836284360607277d33513e11857d683e0708a Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 22:30:12 -0800 Subject: metamask controller - cleanup remote api --- app/scripts/metamask-controller.js | 177 +++++++++++++++++++++---------------- ui/app/actions.js | 3 +- 2 files changed, 101 insertions(+), 79 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 841e35db2..3ff29b202 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -152,7 +152,7 @@ module.exports = class MetamaskController extends EventEmitter { } // - // Constructor helpers + // State Management // getState () { @@ -181,87 +181,49 @@ module.exports = class MetamaskController extends EventEmitter { const noticeController = this.noticeController return { - getState: nodeify(this.getState.bind(this)), - setRpcTarget: this.setRpcTarget.bind(this), - setProviderType: this.setProviderType.bind(this), - useEtherscanProvider: this.useEtherscanProvider.bind(this), - agreeToDisclaimer: this.agreeToDisclaimer.bind(this), - resetDisclaimer: this.resetDisclaimer.bind(this), - setCurrentFiat: this.setCurrentFiat.bind(this), - setTOSHash: this.setTOSHash.bind(this), - checkTOSChange: this.checkTOSChange.bind(this), - setGasMultiplier: this.setGasMultiplier.bind(this), - markAccountsFound: this.markAccountsFound.bind(this), - - // forward directly to keyringController - createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController), - createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController), - // Adds the current vault's seed words to the UI's state tree. - // - // Used when creating a first vault, to allow confirmation. - // Also used when revealing the seed words in the confirmation view. - placeSeedWords: (cb) => { - const primaryKeyring = keyringController.getKeyringsByType('HD Key Tree')[0] - if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found')) - primaryKeyring.serialize() - .then((serialized) => { - const seedWords = serialized.mnemonic - this.configManager.setSeedWords(seedWords) - promiseToCallback(this.keyringController.fullUpdate())(cb) - }) - }, - // ClearSeedWordCache - // - // Removes the primary account's seed words from the UI's state tree, - // ensuring they are only ever available in the background process. - clearSeedWordCache: (cb) => { - this.configManager.setSeedWords(null) - cb(null, this.configManager.getSelectedAccount()) - }, - setLocked: nodeify(keyringController.setLocked).bind(keyringController), - submitPassword: (password, cb) => { - this.migrateOldVaultIfAny(password) - .then(keyringController.submitPassword.bind(keyringController, password)) - .then((newState) => { cb(null, newState) }) - .catch((reason) => { cb(reason) }) - }, - addNewKeyring: (type, opts, cb) => { - keyringController.addNewKeyring(type, opts) - .then(() => keyringController.fullUpdate()) - .then((newState) => { cb(null, newState) }) - .catch((reason) => { cb(reason) }) - }, - addNewAccount: (cb) => { - const primaryKeyring = keyringController.getKeyringsByType('HD Key Tree')[0] - if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found')) - promiseToCallback(keyringController.addNewAccount(primaryKeyring))(cb) - }, - importAccountWithStrategy: (strategy, args, cb) => { - accountImporter.importAccount(strategy, args) - .then((privateKey) => { - return keyringController.addNewKeyring('Simple Key Pair', [ privateKey ]) - }) - .then(keyring => keyring.getAccounts()) - .then((accounts) => keyringController.setSelectedAccount(accounts[0])) - .then(() => { cb(null, keyringController.fullUpdate()) }) - .catch((reason) => { cb(reason) }) - }, - setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController), - saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController), - exportAccount: nodeify(keyringController.exportAccount).bind(keyringController), - - // signing methods - approveTransaction: txManager.approveTransaction.bind(txManager), - cancelTransaction: txManager.cancelTransaction.bind(txManager), - signMessage: keyringController.signMessage.bind(keyringController), - cancelMessage: keyringController.cancelMessage.bind(keyringController), - + // etc + getState: nodeify(this.getState.bind(this)), + setRpcTarget: this.setRpcTarget.bind(this), + setProviderType: this.setProviderType.bind(this), + useEtherscanProvider: this.useEtherscanProvider.bind(this), + agreeToDisclaimer: this.agreeToDisclaimer.bind(this), + resetDisclaimer: this.resetDisclaimer.bind(this), + setCurrentFiat: this.setCurrentFiat.bind(this), + setTOSHash: this.setTOSHash.bind(this), + checkTOSChange: this.checkTOSChange.bind(this), + setGasMultiplier: this.setGasMultiplier.bind(this), + markAccountsFound: this.markAccountsFound.bind(this), // coinbase buyEth: this.buyEth.bind(this), // shapeshift createShapeShiftTx: this.createShapeShiftTx.bind(this), + + // primary HD keyring management + addNewAccount: this.addNewAccount.bind(this), + placeSeedWords: this.placeSeedWords.bind(this), + clearSeedWordCache: this.clearSeedWordCache.bind(this), + importAccountWithStrategy: this.importAccountWithStrategy.bind(this), + + // vault management + submitPassword: this.submitPassword.bind(this), + + // KeyringController + setLocked: nodeify(keyringController.setLocked).bind(keyringController), + createNewVaultAndKeychain: nodeify(keyringController.createNewVaultAndKeychain).bind(keyringController), + createNewVaultAndRestore: nodeify(keyringController.createNewVaultAndRestore).bind(keyringController), + addNewKeyring: nodeify(keyringController.addNewKeyring).bind(keyringController), + setSelectedAccount: nodeify(keyringController.setSelectedAccount).bind(keyringController), + saveAccountLabel: nodeify(keyringController.saveAccountLabel).bind(keyringController), + exportAccount: nodeify(keyringController.exportAccount).bind(keyringController), + + // signing methods + approveTransaction: txManager.approveTransaction.bind(txManager), + cancelTransaction: txManager.cancelTransaction.bind(txManager), + signMessage: keyringController.signMessage.bind(keyringController), + cancelMessage: keyringController.cancelMessage.bind(keyringController), + // notices - checkNotices: noticeController.updateNoticesList.bind(noticeController), + checkNotices: noticeController.updateNoticesList.bind(noticeController), markNoticeRead: noticeController.markNoticeRead.bind(noticeController), } } @@ -314,6 +276,67 @@ module.exports = class MetamaskController extends EventEmitter { }) } + // + // Vault Management + // + + submitPassword (password, cb) { + this.migrateOldVaultIfAny(password) + .then(this.keyringController.submitPassword.bind(this.keyringController, password)) + .then((newState) => { cb(null, newState) }) + .catch((reason) => { cb(reason) }) + } + + // + // Opinionated Keyring Management + // + + addNewAccount (cb) { + const primaryKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0] + if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found')) + promiseToCallback(this.keyringController.addNewAccount(primaryKeyring))(cb) + } + + // Adds the current vault's seed words to the UI's state tree. + // + // Used when creating a first vault, to allow confirmation. + // Also used when revealing the seed words in the confirmation view. + placeSeedWords (cb) { + const primaryKeyring = this.keyringController.getKeyringsByType('HD Key Tree')[0] + if (!primaryKeyring) return cb(new Error('MetamaskController - No HD Key Tree found')) + primaryKeyring.serialize() + .then((serialized) => { + const seedWords = serialized.mnemonic + this.configManager.setSeedWords(seedWords) + promiseToCallback(this.keyringController.fullUpdate())(cb) + }) + } + + // ClearSeedWordCache + // + // Removes the primary account's seed words from the UI's state tree, + // ensuring they are only ever available in the background process. + clearSeedWordCache (cb) { + this.configManager.setSeedWords(null) + cb(null, this.configManager.getSelectedAccount()) + } + + importAccountWithStrategy (strategy, args, cb) { + accountImporter.importAccount(strategy, args) + .then((privateKey) => { + return this.keyringController.addNewKeyring('Simple Key Pair', [ privateKey ]) + }) + .then(keyring => keyring.getAccounts()) + .then((accounts) => this.keyringController.setSelectedAccount(accounts[0])) + .then(() => { cb(null, this.keyringController.fullUpdate()) }) + .catch((reason) => { cb(reason) }) + } + + + // + // Identity Management + // + newUnapprovedTransaction (txParams, cb) { const self = this self.txManager.addUnapprovedTransaction(txParams, (err, txMeta) => { diff --git a/ui/app/actions.js b/ui/app/actions.js index 78af80886..a0fed265f 100644 --- a/ui/app/actions.js +++ b/ui/app/actions.js @@ -270,10 +270,9 @@ function requestRevealSeed (password) { function addNewKeyring (type, opts) { return (dispatch) => { dispatch(actions.showLoadingIndication()) - background.addNewKeyring(type, opts, (err, newState) => { + background.addNewKeyring(type, opts, (err) => { dispatch(actions.hideLoadingIndication()) if (err) return dispatch(actions.displayWarning(err.message)) - dispatch(actions.updateMetamaskState(newState)) dispatch(actions.showAccountsPage()) }) } -- cgit From acdd168fbc973310b1da165c800c0833a51edaac Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 22:30:46 -0800 Subject: lint -ignore extra spaces before values in obj expression --- .eslintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc b/.eslintrc index 84f65bea4..17a59d22d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -48,7 +48,7 @@ "handle-callback-err": [1, "^(err|error)$" ], "indent": [2, 2, { "SwitchCase": 1 }], "jsx-quotes": [2, "prefer-single"], - "key-spacing": [2, { "beforeColon": false, "afterColon": true }], + "key-spacing": 1, "keyword-spacing": [2, { "before": true, "after": true }], "new-cap": [2, { "newIsCap": true, "capIsNew": false }], "new-parens": 2, -- cgit From 95b846ba070e84f0f413ad126d590bb656b6e408 Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 22:31:06 -0800 Subject: keymanager - small clean --- app/scripts/keyring-controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js index 61840af4c..a4bee8ae1 100644 --- a/app/scripts/keyring-controller.js +++ b/app/scripts/keyring-controller.js @@ -204,8 +204,8 @@ module.exports = class KeyringController extends EventEmitter { this.keyrings.push(keyring) return this.setupAccounts(accounts) }) - .then(() => { return this.password }) - .then(this.persistAllKeyrings.bind(this)) + .then(() => this.persistAllKeyrings()) + .then(() => this.fullUpdate()) .then(() => { return keyring }) -- cgit From efcd22905a585d8c2ae55ec4e8bd6d9b027b740d Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 26 Jan 2017 23:03:11 -0800 Subject: metamask - fix setupProviderConnection --- app/scripts/metamask-controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 3ff29b202..3ce9c2373 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -256,7 +256,7 @@ module.exports = class MetamaskController extends EventEmitter { } setupProviderConnection (outStream, originDomain) { - streamIntoProvider(outStream, originDomain, logger) + streamIntoProvider(outStream, this.provider, logger) function logger (err, request, response) { if (err) return console.error(err) if (response.error) { -- cgit