aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2017-01-27 13:18:17 +0800
committerkumavis <aaron@kumavis.me>2017-01-27 13:18:17 +0800
commit832772414e8dba08e0fcfefea59a4e24b1f4a0d3 (patch)
tree667c10b513e02c92b7cde2f24cbd2b2b8b9030ae
parent9616bd826d93a204cb20948dd86ff54fc6d616d2 (diff)
downloadtangerine-wallet-browser-832772414e8dba08e0fcfefea59a4e24b1f4a0d3.tar
tangerine-wallet-browser-832772414e8dba08e0fcfefea59a4e24b1f4a0d3.tar.gz
tangerine-wallet-browser-832772414e8dba08e0fcfefea59a4e24b1f4a0d3.tar.bz2
tangerine-wallet-browser-832772414e8dba08e0fcfefea59a4e24b1f4a0d3.tar.lz
tangerine-wallet-browser-832772414e8dba08e0fcfefea59a4e24b1f4a0d3.tar.xz
tangerine-wallet-browser-832772414e8dba08e0fcfefea59a4e24b1f4a0d3.tar.zst
tangerine-wallet-browser-832772414e8dba08e0fcfefea59a4e24b1f4a0d3.zip
metamask - use web3-stream-provider/handler instead of manual wiring
-rw-r--r--app/scripts/metamask-controller.js31
1 files 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)
}
}
}