diff options
testing continues
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/background.js | 5 | ||||
-rw-r--r-- | app/scripts/contentscript.js | 1 | ||||
-rw-r--r-- | app/scripts/lib/stream-provider.js | 28 |
3 files changed, 22 insertions, 12 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js index c439558c8..8efe79207 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -1,4 +1,4 @@ -const ZeroClientProvider = require('web3-provider-skeleton') +const ZeroClientProvider = require('web3-provider-engine') // const PortStream = require('./lib/port-stream.js') const identitiesUrl = 'https://alpha.metamask.io/identities/' @@ -21,7 +21,8 @@ function connectRemote(remotePort){ function onRpcRequest(remotePort, payload){ zeroClient.sendAsync(payload, function onPayloadHandled(err, response){ if (err) throw err - // console.log('MetaMaskPlugin - RPC complete:', payload, '->', response) + console.log('MetaMaskPlugin - RPC complete:', payload, '->', response) + if (response.result === true) debugger // if (typeof response !== 'object') { // if (!response) { // console.warn('-------------------------------') diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index cce5c1274..065c9f7d0 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -1,7 +1,6 @@ const LocalMessageDuplexStream = require('./lib/local-message-stream.js') const PortStream = require('./lib/port-stream.js') -console.log('content script!') // inject in-page script var scriptTag = document.createElement('script') diff --git a/app/scripts/lib/stream-provider.js b/app/scripts/lib/stream-provider.js index 3e7f443c8..b0a922397 100644 --- a/app/scripts/lib/stream-provider.js +++ b/app/scripts/lib/stream-provider.js @@ -11,7 +11,7 @@ function StreamProvider(){ objectMode: true, }) - this._handlers = {} + this._payloads = {} } // public @@ -21,19 +21,29 @@ StreamProvider.prototype.send = function(payload){ } StreamProvider.prototype.sendAsync = function(payload, callback){ -// console.log('StreamProvider - sending payload', payload) - this._handlers[payload.id] = callback + // console.log('StreamProvider - sending payload', payload) + this._payloads[payload.id] = [payload, callback] + // console.log('payload for plugin:', payload) this.push(payload) } // private -StreamProvider.prototype._onResponse = function(payload){ -// console.log('StreamProvider - got response', payload) - var callback = this._handlers[payload.id] - if (!callback) throw new Error('StreamProvider - Unknown response id') - delete this._handlers[payload.id] - callback(null, payload) +StreamProvider.prototype._onResponse = function(response){ + // console.log('StreamProvider - got response', payload) + var data = this._payloads[response.id] + if (!data) throw new Error('StreamProvider - Unknown response id') + delete this._payloads[response.id] + var payload = data[0] + var callback = data[1] + + // logging + var res = Array.isArray(response) ? response : [response] + ;(Array.isArray(payload) ? payload : [payload]).forEach(function(payload, index){ + console.log('plugin response:', payload.id, payload.method, payload.params, '->', res[index].result) + }) + + callback(null, response) } // stream plumbing |