Merge pull request #1309 from MetaMask/mascara2
Mascara - various fixesfeature/default_network_editable
commit
dd6b4505f4
@ -0,0 +1,19 @@ |
||||
module.exports = getBuyEthUrl |
||||
|
||||
function getBuyEthUrl({ network, amount, address }){ |
||||
let url |
||||
switch (network) { |
||||
case '1': |
||||
url = `https://buy.coinbase.com/?code=9ec56d01-7e81-5017-930c-513daa27bb6a&amount=${amount}&address=${address}&crypto_currency=ETH` |
||||
break |
||||
|
||||
case '3': |
||||
url = 'https://faucet.metamask.io/' |
||||
break |
||||
|
||||
case '42': |
||||
url = 'https://github.com/kovan-testnet/faucet' |
||||
break |
||||
} |
||||
return url |
||||
} |
@ -0,0 +1,24 @@ |
||||
|
||||
class SwPlatform { |
||||
|
||||
//
|
||||
// Public
|
||||
//
|
||||
|
||||
reload () { |
||||
// you cant actually do this
|
||||
global.location.reload() |
||||
} |
||||
|
||||
openWindow ({ url }) { |
||||
// this doesnt actually work
|
||||
global.open(url, '_blank') |
||||
} |
||||
|
||||
getVersion () { |
||||
return '<unable to read version>' |
||||
} |
||||
|
||||
} |
||||
|
||||
module.exports = SwPlatform |
@ -0,0 +1,22 @@ |
||||
|
||||
class WindowPlatform { |
||||
|
||||
//
|
||||
// Public
|
||||
//
|
||||
|
||||
reload () { |
||||
global.location.reload() |
||||
} |
||||
|
||||
openWindow ({ url }) { |
||||
global.open(url, '_blank') |
||||
} |
||||
|
||||
getVersion () { |
||||
return '<unable to read version>' |
||||
} |
||||
|
||||
} |
||||
|
||||
module.exports = WindowPlatform |
@ -0,0 +1,31 @@ |
||||
const express = require('express') |
||||
const createMetamascaraServer = require('../server/') |
||||
const createBundle = require('../server/util').createBundle |
||||
const serveBundle = require('../server/util').serveBundle |
||||
|
||||
//
|
||||
// Iframe Server
|
||||
//
|
||||
|
||||
const mascaraServer = createMetamascaraServer() |
||||
|
||||
// start the server
|
||||
const mascaraPort = 9001 |
||||
mascaraServer.listen(mascaraPort) |
||||
console.log(`Mascara service listening on port ${mascaraPort}`) |
||||
|
||||
|
||||
//
|
||||
// Dapp Server
|
||||
//
|
||||
|
||||
const dappServer = express() |
||||
|
||||
// serve dapp bundle
|
||||
serveBundle(dappServer, '/app.js', createBundle(require.resolve('./app.js'))) |
||||
dappServer.use(express.static(__dirname + '/app/')) |
||||
|
||||
// start the server
|
||||
const dappPort = '9002' |
||||
dappServer.listen(dappPort) |
||||
console.log(`Dapp listening on port ${dappPort}`) |
@ -1,103 +0,0 @@ |
||||
const express = require('express') |
||||
const browserify = require('browserify') |
||||
const watchify = require('watchify') |
||||
const babelify = require('babelify') |
||||
|
||||
const zeroBundle = createBundle('./src/mascara.js') |
||||
const controllerBundle = createBundle('./src/dapp-connection.js') |
||||
const popupBundle = createBundle('./src/popup.js') |
||||
const swBuild = createBundle('./src/background.js') |
||||
|
||||
const appBundle = createBundle('./example/index.js') |
||||
|
||||
//
|
||||
// Iframe Server
|
||||
//
|
||||
|
||||
const iframeServer = express() |
||||
|
||||
// serve popup window
|
||||
iframeServer.get('/popup/scripts/popup.js', function(req, res){ |
||||
res.send(popupBundle.latest) |
||||
}) |
||||
iframeServer.use('/popup', express.static('../dist/chrome')) |
||||
|
||||
// serve controller bundle
|
||||
iframeServer.get('/controller.js', function(req, res){ |
||||
res.send(controllerBundle.latest) |
||||
}) |
||||
iframeServer.get('/popup/sw-build.js', function(req, res){ |
||||
console.log('/sw-build.js') |
||||
res.setHeader('Content-Type', 'application/javascript') |
||||
res.send(swBuild.latest) |
||||
}) |
||||
|
||||
// serve background controller
|
||||
iframeServer.use(express.static('./server')) |
||||
|
||||
// start the server
|
||||
const mascaraPort = 9001 |
||||
iframeServer.listen(mascaraPort) |
||||
console.log(`Mascara service listening on port ${mascaraPort}`) |
||||
|
||||
|
||||
//
|
||||
// Dapp Server
|
||||
//
|
||||
|
||||
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')) |
||||
|
||||
// start the server
|
||||
const dappPort = '9002' |
||||
dappServer.listen(dappPort) |
||||
console.log(`Dapp listening on port ${dappPort}`) |
||||
|
||||
//
|
||||
// util
|
||||
//
|
||||
|
||||
function serveBundle(entryPoint){ |
||||
const bundle = createBundle(entryPoint) |
||||
return function(req, res){ |
||||
res.send(bundle.latest) |
||||
} |
||||
} |
||||
|
||||
function createBundle(entryPoint){ |
||||
|
||||
var bundleContainer = {} |
||||
|
||||
var bundler = browserify({ |
||||
entries: [entryPoint], |
||||
cache: {}, |
||||
packageCache: {}, |
||||
plugin: [watchify], |
||||
}) |
||||
|
||||
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() |
||||
}) |
||||
} |
||||
|
||||
} |
@ -0,0 +1,32 @@ |
||||
const express = require('express') |
||||
const createBundle = require('./util').createBundle |
||||
const serveBundle = require('./util').serveBundle |
||||
|
||||
module.exports = createMetamascaraServer |
||||
|
||||
|
||||
function createMetamascaraServer(){ |
||||
|
||||
// start bundlers
|
||||
const metamascaraBundle = createBundle('./src/mascara.js') |
||||
const proxyBundle = createBundle('./src/proxy.js') |
||||
const uiBundle = createBundle('./src/ui.js') |
||||
const backgroundBuild = createBundle('./src/background.js') |
||||
|
||||
// serve bundles
|
||||
const server = express() |
||||
// ui window
|
||||
serveBundle(server, '/ui.js', uiBundle) |
||||
server.use(express.static(__dirname+'/../ui/')) |
||||
server.use(express.static(__dirname+'/../../dist/chrome')) |
||||
// metamascara
|
||||
serveBundle(server, '/metamascara.js', metamascaraBundle) |
||||
// proxy
|
||||
serveBundle(server, '/proxy/proxy.js', proxyBundle) |
||||
server.use('/proxy/', express.static(__dirname+'/../proxy')) |
||||
// background
|
||||
serveBundle(server, '/background.js', backgroundBuild) |
||||
|
||||
return server |
||||
|
||||
} |
@ -0,0 +1,45 @@ |
||||
const browserify = require('browserify') |
||||
const watchify = require('watchify') |
||||
|
||||
module.exports = { |
||||
serveBundle, |
||||
createBundle, |
||||
} |
||||
|
||||
|
||||
function serveBundle(server, path, bundle){ |
||||
server.get(path, function(req, res){ |
||||
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8') |
||||
res.send(bundle.latest) |
||||
}) |
||||
} |
||||
|
||||
function createBundle(entryPoint){ |
||||
|
||||
var bundleContainer = {} |
||||
|
||||
var bundler = browserify({ |
||||
entries: [entryPoint], |
||||
cache: {}, |
||||
packageCache: {}, |
||||
plugin: [watchify], |
||||
}) |
||||
|
||||
bundler.on('update', bundle) |
||||
bundle() |
||||
|
||||
return bundleContainer |
||||
|
||||
function bundle() { |
||||
bundler.bundle(function(err, result){ |
||||
if (err) { |
||||
console.log(`Bundle failed! (${entryPoint})`) |
||||
console.error(err) |
||||
return |
||||
} |
||||
console.log(`Bundle updated! (${entryPoint})`) |
||||
bundleContainer.latest = result.toString() |
||||
}) |
||||
} |
||||
|
||||
} |
@ -0,0 +1,11 @@ |
||||
<!doctype html> |
||||
<html> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>MetaMask Plugin</title> |
||||
</head> |
||||
<body> |
||||
<div id="app-content"></div> |
||||
<script src="./ui.js" type="text/javascript" charset="utf-8"></script> |
||||
</body> |
||||
</html> |
Loading…
Reference in new issue