migrate to new ui + provider

feature/default_network_editable
kumavis 9 years ago
parent 709d93b5a1
commit 3eaf027e30
  1. 5
      Gruntfile.js
  2. 49
      TODO
  3. 2
      app/manifest.json
  4. 17
      app/popup.html
  5. 28
      app/scripts/background.js
  6. 149
      app/scripts/lib/metamask-provider.js
  7. 14
      app/scripts/popup.js
  8. 8
      package.json

@ -148,7 +148,7 @@ module.exports = function (grunt) {
dest: '<%= config.dist %>', dest: '<%= config.dist %>',
src: [ src: [
'*.{ico,png,txt}', '*.{ico,png,txt}',
'images/{,*/}*.{webp,gif}', 'images/{,*/}*.*',
'{,*/}*.html', '{,*/}*.html',
'styles/{,*/}*.css', 'styles/{,*/}*.css',
'styles/fonts/{,*/}*.*', 'styles/fonts/{,*/}*.*',
@ -164,7 +164,6 @@ module.exports = function (grunt) {
cwd: '<%= config.app %>', cwd: '<%= config.app %>',
dest: '<%= config.dist %>', dest: '<%= config.dist %>',
src: [ src: [
'images/{,*/}*.*',
'scripts/chromereload.js', 'scripts/chromereload.js',
] ]
}] }]
@ -278,7 +277,7 @@ module.exports = function (grunt) {
'clean', 'clean',
'concurrent:dist', 'concurrent:dist',
'uglify', 'uglify',
'copy:dist', 'copy:basic',
'chromeManifest:dist', 'chromeManifest:dist',
'compress', 'compress',
]); ]);

49
TODO

@ -0,0 +1,49 @@
TODO
### plugin
- [ ] ui
- [ ] designer
- [ ] design
- [ ] stack
- [x] frontend
- [ ] build tools
- [ ] data source
- [x] geth node
- [ ] rpc proxy
- [x] geth node
- [ ] whitelist
- [ ] (perf) proxy-level caching
- [ ] (perf) block listener websocket
- [ ] provider engine
- [x] top-level cache
- [x] top-level current block
- [x] subproviders should act like normal providers
- [x] return in payload wrapper
- [ ] subprovider implementations
- [x] static
- [ ] filters
- [x] block
- [x] log
- [ ] pendingTx
- [x] rpc
- [x] vm
- [x] tx signing
- [ ] dev ops
- [ ] test api load
- [ ] publish plugin to store
- [ ] external info
- [ ] soft launch email
- [ ] consensys blog post?
(2) dapp fallback lib
iframe wrapper api
data source
?
(3) browser-browser
(4) mobile extension / app

@ -1,6 +1,6 @@
{ {
"name": "__MSG_appName__", "name": "__MSG_appName__",
"version": "0.0.49", "version": "0.1.0",
"manifest_version": 2, "manifest_version": 2,
"description": "__MSG_appDescription__", "description": "__MSG_appDescription__",
"icons": { "icons": {

@ -2,23 +2,10 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Typo Blaster</title> <title>MetaMask Plugin</title>
<style>
body {
min-width: 357px;
overflow-x: hidden;
}
img {
margin: 5px;
border: 2px solid black;
vertical-align: middle;
width: 75px;
height: 75px;
}
</style>
</head> </head>
<body> <body>
<div id="app-content"></div>
<script src="./scripts/popup.js" type="text/javascript" charset="utf-8"></script> <script src="./scripts/popup.js" type="text/javascript" charset="utf-8"></script>
</body> </body>
</html> </html>

@ -1,34 +1,10 @@
const ZeroClientProvider = require('web3-provider-engine') const MetaMaskProvider = require('./lib/metamask-provider')
// const PortStream = require('./lib/port-stream.js') // const PortStream = require('./lib/port-stream.js')
const identitiesUrl = 'https://alpha.metamask.io/identities/' const identitiesUrl = 'https://alpha.metamask.io/identities/'
// var unsignedTxs = {} // var unsignedTxs = {}
var zeroClient = new ZeroClientProvider({ var zeroClient = MetaMaskProvider()
rpcUrl: 'https://rawrpc.metamask.io/',
})
// // setup badge click handler
// chrome.browserAction.onClicked.addListener(function(activeTab) {
// // chrome.tabs.create({ url: identitiesUrl })
// tabbernackle()
// })
// function tabbernackle(){
// chrome.tabs.create({
// url: 'about:blank',//chrome.extension.getURL('dialog.html'),
// active: false
// }, function(tab) {
// // After the tab has been created, open a window to inject the tab
// chrome.windows.create({
// tabId: tab.id,
// type: 'panel',
// focused: true
// // incognito, top, left, ...
// });
// });
// }
// setup messaging // setup messaging
chrome.runtime.onConnect.addListener(connectRemote) chrome.runtime.onConnect.addListener(connectRemote)

@ -1,122 +1,55 @@
var HttpProvider = require('web3/lib/web3/httpprovider.js') const ProviderEngine = require('web3-provider-engine')
var ethUtils = require('ethereumjs-util') const CacheSubprovider = require('web3-provider-engine/subproviders/cache.js')
var async = require('async') const StaticSubprovider = require('web3-provider-engine/subproviders/static.js')
const FilterSubprovider = require('web3-provider-engine/subproviders/filters.js')
const VmSubprovider = require('web3-provider-engine/subproviders/vm.js')
const LightWalletSubprovider = require('web3-provider-engine/subproviders/lightwallet.js')
const RpcSubprovider = require('web3-provider-engine/subproviders/rpc.js')
module.exports = MetamaskProvider module.exports = metamaskProvider
function metamaskProvider(opts){
function MetamaskProvider(forwardPayload, host) { var engine = new ProviderEngine()
this.handlers = []
this.forwardPayload = forwardPayload
this.http = new HttpProvider(host)
}
MetamaskProvider.prototype.send = function (payload) {
if (Array.isArray(payload)) {
return payload.map( this.handlePayload.bind(this) )
} else {
return this.handlePayload( payload )
}
}
MetamaskProvider.prototype.sendAsync = function (payload, cb) {
if (Array.isArray(payload)) {
async.map( payload, this.handlePayload.bind(this), cb )
} else {
this.handlePayload( payload, cb )
}
}
MetamaskProvider.prototype.handlePayload = function (payload, cb) {
var _this = this
var isSync = !cb
var resolvedSync = true
var result = undefined
// TODO - this should be injected from Vapor dapp starts
var exposedAccounts = ['0xa06ef3ed1ce41ade87f764de6ce8095c569d6d57']
switch (payload.method) { // cache layer
engine.addProvider(new CacheSubprovider())
case 'web3_sha3': // static results
var inputHex = stripHexStringPrefix(payload.params[0]) engine.addProvider(new StaticSubprovider({
var hash = '0x'+ethUtils.sha3(new Buffer(inputHex, 'hex')).toString('hex') web3_clientVersion: 'MetaMask-ProviderEngine/v0.0.0/javascript',
return handleResult(null, wrapResponse(payload, hash)) net_listening: true,
eth_hashrate: '0x0',
eth_mining: false,
eth_syncing: true,
})
case 'eth_sendTransaction': // filters
this.forwardPayload(payload) engine.addProvider(new FilterSubprovider())
return handleResult(null, wrapResponse(payload, ''))
case 'eth_coinbase': // vm
var currentAddress = exposedAccounts[0] engine.addProvider(new VmSubprovider())
return handleResult(null, wrapResponse(payload, currentAddress))
case 'eth_accounts': // id mgmt
return handleResult(null, wrapResponse(payload, exposedAccounts)) engine.addProvider(new LightWalletSubprovider())
case 'eth_gasPrice': // data source
// TODO - this should be dynamically set somehow engine.addProvider(new RpcSubprovider({
var gasPrice = '0x01' rpcUrl: 'https://testrpc.metamask.io/',
return handleResult(null, wrapResponse(payload, [gasPrice])) }))
case 'eth_call': // log new blocks
var params = payload.params engine.on('block', function(block){
// default 'from' to default account // lazy hack - move caching and current block to engine
var args = params[0] engine.currentBlock = block
if (!args.from) { console.log('================================')
var currentAddress = exposedAccounts[0] console.log('BLOCK CHANGED:', '#'+block.number.toString('hex'), '0x'+block.hash.toString('hex'))
args.from = currentAddress console.log('================================')
} })
// default block to latest
params[1] = params[1] || 'latest'
// turn on debug trace
params[2] = global.DEBUG_RPC
return handleNormally()
default: // start polling for blocks
return handleNormally() engine.start()
}
resolvedSync = false
function handleNormally(){
if (isSync) {
return handleResult(null, _this.http.send(payload))
} else {
_this.http.sendAsync(payload, handleResult)
}
}
// helper for normalizing handling of sync+async responses
function handleResult(err, resp) {
if (isSync) {
return resp
} else {
if (resolvedSync) {
process.nextTick(cb.bind(null, err, resp))
} else {
cb(err, resp)
}
}
}
}
function wrapResponse(payload, result){
return {
jsonrpc: payload.jsonrpc,
id: payload.id,
result: result,
}
}
function stripHexStringPrefix(hex) { return engine
if (!hex) {
return hex
}
if (hex.slice(0, 2) === '0x') {
return hex.slice(2);
} else {
return hex;
}
} }

@ -1 +1,13 @@
document.body.innerHTML = "real talk" const MetaMaskUi = require('metamask-ui')
const MetaMaskUiCss = require('metamask-ui/css')
const injectCss = require('inject-css')
var container = document.getElementById('app-content')
var css = MetaMaskUiCss()
injectCss(css)
var app = MetaMaskUi({
container: container,
})

@ -2,13 +2,15 @@
"name": "metamask-crx", "name": "metamask-crx",
"version": "0.0.0", "version": "0.0.0",
"public": false, "public": false,
"scripts": {
"start": "grunt dev",
"build": "grunt build"
},
"dependencies": { "dependencies": {
"async": "^1.4.0", "async": "^1.4.0",
"blockapps-web3": "git://github.com/kumavis/blockapps-web3.git#9c1ee8e99efe277804fc47d8b11142abbc46180c",
"ethereumjs-tx": "^0.6.7", "ethereumjs-tx": "^0.6.7",
"ethereumjs-util": "^1.3.5", "ethereumjs-util": "^1.3.5",
"object.entries": "^1.0.2", "inject-css": "^0.1.1",
"readable-stream": "^2.0.5",
"web3": "^0.15.1", "web3": "^0.15.1",
"web3-provider-engine": "^1.2.0" "web3-provider-engine": "^1.2.0"
}, },

Loading…
Cancel
Save