mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
library - basic test server + partial safari fixes
This commit is contained in:
parent
23a144fb8b
commit
b7aab95519
@ -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)
|
||||
|
@ -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
|
||||
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 ] ]
|
@ -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>
|
@ -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,
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
88
library/server.js
Normal file
88
library/server.js
Normal file
@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,6 @@
|
||||
|
||||
<body>
|
||||
Hello! I am the MetaMask iframe.
|
||||
<script src="/bundle.js"></script>
|
||||
<script src="/controller.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user