aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/background.js
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-05-23 09:02:27 +0800
committerkumavis <aaron@kumavis.me>2016-05-23 09:02:27 +0800
commit2a62d63b4f70bea12126e4b15d78ebbf9dbddefb (patch)
tree6292c1261538162f5bd0001e0258324186a4d623 /app/scripts/background.js
parent41df7bb8f622e1fdd9e1bb2b1687347e5f359c47 (diff)
downloadtangerine-wallet-browser-2a62d63b4f70bea12126e4b15d78ebbf9dbddefb.tar
tangerine-wallet-browser-2a62d63b4f70bea12126e4b15d78ebbf9dbddefb.tar.gz
tangerine-wallet-browser-2a62d63b4f70bea12126e4b15d78ebbf9dbddefb.tar.bz2
tangerine-wallet-browser-2a62d63b4f70bea12126e4b15d78ebbf9dbddefb.tar.lz
tangerine-wallet-browser-2a62d63b4f70bea12126e4b15d78ebbf9dbddefb.tar.xz
tangerine-wallet-browser-2a62d63b4f70bea12126e4b15d78ebbf9dbddefb.tar.zst
tangerine-wallet-browser-2a62d63b4f70bea12126e4b15d78ebbf9dbddefb.zip
deps - use web3-stream-provider module
Diffstat (limited to 'app/scripts/background.js')
-rw-r--r--app/scripts/background.js34
1 files changed, 12 insertions, 22 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index f79047db4..8c6adff04 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -1,11 +1,12 @@
const Dnode = require('dnode')
-const ObjectMultiplex = require('./lib/obj-multiplex')
const eos = require('end-of-stream')
const combineStreams = require('pumpify')
const extend = require('xtend')
const EthStore = require('eth-store')
-const PortStream = require('./lib/port-stream.js')
const MetaMaskProvider = require('web3-provider-engine/zero.js')
+const handleRequestsFromStream = require('web3-stream-provider/handler')
+const ObjectMultiplex = require('./lib/obj-multiplex')
+const PortStream = require('./lib/port-stream.js')
const IdentityStore = require('./lib/idStore')
const createTxNotification = require('./lib/notifications.js').createTxNotification
const createMsgNotification = require('./lib/notifications.js').createMsgNotification
@@ -132,25 +133,6 @@ function storeSetFromObj(store, obj){
}
-
-// handle rpc requests
-function onRpcRequest(remoteStream, payload){
- // console.log('MetaMaskPlugin - incoming payload:', payload)
- provider.sendAsync(payload, function onPayloadHandled(err, response){
- // provider engine errors are included in response objects
- if (!payload.isMetamaskInternal) {
- console.log('MetaMaskPlugin - RPC complete:', payload, '->', response)
- if (response.error) console.error('Error in RPC response:\n'+response.error.message)
- }
- try {
- remoteStream.write(response)
- } catch (err) {
- console.error(err)
- }
- })
-}
-
-
//
// remote features
//
@@ -161,7 +143,15 @@ function setupPublicConfig(stream){
}
function setupProviderConnection(stream){
- stream.on('data', onRpcRequest.bind(null, stream))
+ handleRequestsFromStream(stream, provider, logger)
+
+ function logger(err, request, response){
+ if (err) return console.error(err.stack)
+ if (!request.isMetamaskInternal) {
+ console.log('MetaMaskPlugin - RPC complete:', request, '->', response)
+ if (response.error) console.error('Error in RPC response:\n'+response.error.message)
+ }
+ }
}
function setupControllerConnection(stream){