diff --git a/library/frame.js b/library/controller.js similarity index 97% rename from library/frame.js rename to library/controller.js index db5baf36a..90d849d20 100644 --- a/library/frame.js +++ b/library/controller.js @@ -53,6 +53,8 @@ function initializeZeroClient() { if (err) throw err }) + multiStream.on('data', function(chunk){ console.log(chunk) }) + var providerStream = multiStream.createStream('provider') handleRequestsFromStream(providerStream, provider, logger) diff --git a/library/example.sh b/library/example.sh index 73f9cd20c..09389d404 100755 --- a/library/example.sh +++ b/library/example.sh @@ -1,4 +1,4 @@ # run 2 servers and make sure they close together -beefy frame.js:bundle.js 9001 --live & -beefy example/index.js:bundle.js index.js:zero.js --cwd example/ 9002 --live --open \ No newline at end of file +beefy frame.js:bundle.js 9001 --live -- -t [ babelify --global --presets [ es2015 ] ] & +beefy example/index.js:bundle.js index.js:zero.js --cwd example/ 9002 --live --open -- -t [ babelify --global --presets [ es2015 ] ] \ No newline at end of file diff --git a/library/example/index.html b/library/example/index.html index aa15a4523..47d6da34f 100644 --- a/library/example/index.html +++ b/library/example/index.html @@ -12,6 +12,6 @@ - + \ No newline at end of file diff --git a/library/example/index.js b/library/example/index.js index d24c26f87..bdde2b47f 100644 --- a/library/example/index.js +++ b/library/example/index.js @@ -4,8 +4,10 @@ window.addEventListener('load', web3Detect) function web3Detect() { if (global.web3) { document.body.innerHTML += 'web3 detected!' + console.log('web3 detected!') } else { document.body.innerHTML += 'no web3 detected!' + console.log('no web3 detected!') } startApp() } @@ -13,12 +15,17 @@ function web3Detect() { var primaryAccount = null web3.eth.getAccounts(function(err, addresses){ if (err) throw err + console.log('set address') primaryAccount = addresses[0] }) function startApp(){ + console.log('app started') + document.querySelector('.action-button-1').addEventListener('click', function(){ + console.log('saw click') + console.log('sending tx') web3.eth.sendTransaction({ from: primaryAccount, value: 0, @@ -28,7 +35,9 @@ function startApp(){ }) }) document.querySelector('.action-button-2').addEventListener('click', function(){ + console.log('saw click') setTimeout(function(){ + console.log('sending tx') web3.eth.sendTransaction({ from: primaryAccount, value: 0, diff --git a/library/index.js b/library/index.js index 9991462ab..c98035106 100644 --- a/library/index.js +++ b/library/index.js @@ -6,11 +6,14 @@ const setupProvider = require('./lib/setup-provider.js') // var provider = setupProvider() +console.log('debugger point A') hijackProvider(provider) +console.log('debugger point B') var web3 = new Web3(provider) web3.setProvider = function(){ console.log('MetaMask - overrode web3.setProvider') } +console.log('metamask lib hijacked provider') // // export web3 @@ -35,6 +38,7 @@ function hijackProvider(provider){ var _super = provider.sendAsync.bind(provider) provider.sendAsync = function(payload, cb){ if (payload.method === 'eth_sendTransaction') { + console.log('saw send') shouldPop = true } _super(payload, cb) diff --git a/library/lib/setup-iframe.js b/library/lib/setup-iframe.js index dfb51c676..db67163df 100644 --- a/library/lib/setup-iframe.js +++ b/library/lib/setup-iframe.js @@ -8,10 +8,11 @@ function setupIframe(opts) { opts = opts || {} var frame = Iframe({ src: opts.zeroClientProvider || 'https://zero.metamask.io/', - container: document.head, + container: opts.container || document.head, sandboxAttributes: opts.sandboxAttributes || ['allow-scripts', 'allow-popups'], }) var iframe = frame.iframe + iframe.style.setProperty('display', 'none') var iframeStream = new IframeStream(iframe) return iframeStream diff --git a/library/lib/setup-provider.js b/library/lib/setup-provider.js index ced07e0f0..9efd209cb 100644 --- a/library/lib/setup-provider.js +++ b/library/lib/setup-provider.js @@ -13,8 +13,9 @@ function getProvider(){ console.log('MetaMask ZeroClient - injecting zero-client iframe!') var iframeStream = setupIframe({ - zeroClientProvider: 'http://localhost:9001', + zeroClientProvider: 'http://127.0.0.1:9001', sandboxAttributes: ['allow-scripts', 'allow-popups', 'allow-same-origin'], + container: document.body, }) var inpageProvider = new MetamaskInpageProvider(iframeStream) diff --git a/library/server.js b/library/server.js new file mode 100644 index 000000000..c7fea085f --- /dev/null +++ b/library/server.js @@ -0,0 +1,88 @@ +const express = require('express') +const browserify = require('browserify') +const watchify = require('watchify') +const babelify = require('babelify') +const path = require('path') + +const zeroBundle = createBundle('./index.js') +const controllerBundle = createBundle('./controller.js') +const appBundle = createBundle('./example/index.js') + +// +// Iframe Server +// + +// beefy frame.js:bundle.js 9001 --live -- -t [ babelify --global --presets [ es2015 ] ] + +const iframeServer = express() + +// serve controller bundle +iframeServer.get('/controller.js', function(req, res){ + res.send(controllerBundle.latest) +}) + +// serve static +iframeServer.use(express.static('./server')) + +iframeServer.listen('9001') + + +// +// Dapp Server +// + +// beefy example/index.js:bundle.js index.js:zero.js --cwd example/ 9002 --live --open -- -t [ babelify --global --presets [ es2015 ] ] + +const dappServer = express() + + +// serve metamask-lib bundle +dappServer.get('/zero.js', function(req, res){ + res.send(zeroBundle.latest) +}) + +// serve dapp bundle +dappServer.get('/app.js', function(req, res){ + res.send(appBundle.latest) +}) + +// serve static +dappServer.use(express.static('./example')) + + +dappServer.listen('9002') + + +function createBundle(entryPoint){ + + var bundleContainer = {} + + var bundler = browserify({ + entries: [entryPoint], + cache: {}, + packageCache: {}, + plugin: [watchify], + }) + + var bablePreset = path.resolve(__dirname, '../node_modules/babel-preset-es2015') + + bundler.transform(babelify, { + global: true, + presets: [bablePreset], + }) + + + bundler.on('update', bundle) + bundle() + + return bundleContainer + + function bundle() { + bundler.bundle(function(err, result){ + if (err) throw err + console.log(`Bundle updated! (${entryPoint})`) + bundleContainer.latest = result.toString() + }) + } + +} \ No newline at end of file diff --git a/library/index.html b/library/server/index.html similarity index 88% rename from library/index.html rename to library/server/index.html index 5a4c66544..2308dd98b 100644 --- a/library/index.html +++ b/library/server/index.html @@ -15,6 +15,6 @@ Hello! I am the MetaMask iframe. - + \ No newline at end of file diff --git a/package.json b/package.json index 4c30db1a1..45ddc3dec 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "lint": "gulp lint", "dev": "gulp dev", "dist": "gulp dist", - "test": "npm run fastTest && npm run ci", + "test": "npm run fastTest && npm run ci && npm run lint", "fastTest": "mocha --require test/helper.js --compilers js:babel-register --recursive \"test/unit/**/*.js\"", "watch": "mocha watch --compilers js:babel-register --recursive \"test/unit/**/*.js\"", "ui": "node development/genStates.js && beefy ui-dev.js:bundle.js --live --open --index=./development/index.html --cwd ./", @@ -45,6 +45,7 @@ "eth-store": "^1.1.0", "ethereumjs-tx": "^1.0.0", "ethereumjs-util": "^4.4.0", + "express": "^4.14.0", "gulp-eslint": "^2.0.0", "hat": "0.0.3", "identicon.js": "^1.2.1", @@ -78,7 +79,7 @@ "three.js": "^0.73.2", "through2": "^2.0.1", "vreme": "^3.0.2", - "web3": "^0.17.0-alpha", + "web3": "ethereum/web3.js#260ac6e78a8ce4b2e13f5bb0fdb65f4088585876", "web3-provider-engine": "^8.0.2", "web3-stream-provider": "^2.0.6", "xtend": "^4.0.1"