diff options
library - basic test server + partial safari fixes
Diffstat (limited to 'library')
-rw-r--r-- | library/controller.js (renamed from library/frame.js) | 2 | ||||
-rwxr-xr-x | library/example.sh | 4 | ||||
-rw-r--r-- | library/example/index.html | 2 | ||||
-rw-r--r-- | library/example/index.js | 9 | ||||
-rw-r--r-- | library/index.js | 4 | ||||
-rw-r--r-- | library/lib/setup-iframe.js | 3 | ||||
-rw-r--r-- | library/lib/setup-provider.js | 3 | ||||
-rw-r--r-- | library/server.js | 88 | ||||
-rw-r--r-- | library/server/index.html (renamed from library/index.html) | 2 |
9 files changed, 111 insertions, 6 deletions
diff --git a/library/frame.js b/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 @@ <button class="action-button-1">SYNC TX</button> <button class="action-button-2">ASYNC TX</button> <script src="./zero.js"></script> - <script src="./bundle.js"></script> + <script src="./app.js"></script> </body> </html>
\ 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 index 5a4c66544..2308dd98b 100644 --- a/library/index.html +++ b/library/server/index.html @@ -15,6 +15,6 @@ <body> Hello! I am the MetaMask iframe. - <script src="/bundle.js"></script> + <script src="/controller.js"></script> </body> </html>
\ No newline at end of file |