testing continues

feature/default_network_editable
kumavis 9 years ago
parent 72a747165d
commit 09644408c2
  1. 5
      app/scripts/background.js
  2. 1
      app/scripts/contentscript.js
  3. 28
      app/scripts/lib/stream-provider.js
  4. 2
      package.json

@ -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('-------------------------------')

@ -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')

@ -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

@ -10,7 +10,7 @@
"object.entries": "^1.0.2",
"readable-stream": "^2.0.5",
"web3": "^0.15.1",
"web3-provider-engine": "^1.0.0"
"web3-provider-engine": "^1.1.0"
},
"devDependencies": {
"grunt": "~0.4.1",

Loading…
Cancel
Save