aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2016-08-27 08:39:19 +0800
committerkumavis <aaron@kumavis.me>2016-08-27 08:39:19 +0800
commitb7aab955196a7cef2705e8546814b5c6c1830da7 (patch)
tree19c1b72359af5372bb800b2e268ce7f146ddb915
parent23a144fb8b0b214b9c352ee523405d5ecd03046e (diff)
downloadtangerine-wallet-browser-b7aab955196a7cef2705e8546814b5c6c1830da7.tar
tangerine-wallet-browser-b7aab955196a7cef2705e8546814b5c6c1830da7.tar.gz
tangerine-wallet-browser-b7aab955196a7cef2705e8546814b5c6c1830da7.tar.bz2
tangerine-wallet-browser-b7aab955196a7cef2705e8546814b5c6c1830da7.tar.lz
tangerine-wallet-browser-b7aab955196a7cef2705e8546814b5c6c1830da7.tar.xz
tangerine-wallet-browser-b7aab955196a7cef2705e8546814b5c6c1830da7.tar.zst
tangerine-wallet-browser-b7aab955196a7cef2705e8546814b5c6c1830da7.zip
library - basic test server + partial safari fixes
-rw-r--r--library/controller.js (renamed from library/frame.js)2
-rwxr-xr-xlibrary/example.sh4
-rw-r--r--library/example/index.html2
-rw-r--r--library/example/index.js9
-rw-r--r--library/index.js4
-rw-r--r--library/lib/setup-iframe.js3
-rw-r--r--library/lib/setup-provider.js3
-rw-r--r--library/server.js88
-rw-r--r--library/server/index.html (renamed from library/index.html)2
-rw-r--r--package.json5
10 files changed, 114 insertions, 8 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
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"