Merge branch 'master' into buyForm

feature/default_network_editable
Frankie 8 years ago
commit 632465b213
  1. 1
      CHANGELOG.md
  2. 1
      app/scripts/background.js
  3. 3
      app/scripts/config.js
  4. 2
      app/scripts/contentscript.js
  5. 2
      app/scripts/inpage.js
  6. 2
      app/scripts/lib/auto-reload.js
  7. 24
      app/scripts/lib/ensnare.js
  8. 9
      app/scripts/lib/idStore.js
  9. 47
      app/scripts/lib/inpage-provider.js
  10. 56
      app/scripts/lib/local-message-stream.js
  11. 8
      app/scripts/metamask-controller.js
  12. 2
      development/states.js
  13. 189
      development/states/custom-rpc.json
  14. 0
      development/states/pending-crash.json
  15. 3
      mock-dev.js
  16. 4
      package.json
  17. 2
      ui/app/components/network.js
  18. 15
      ui/app/store.js

@ -3,6 +3,7 @@
## Current Master ## Current Master
- Fix various typos. - Fix various typos.
- Make dapp-metamask connection more reliable
## 2.7.3 2016-07-29 ## 2.7.3 2016-07-29

@ -13,6 +13,7 @@ const extension = require('./lib/extension')
const STORAGE_KEY = 'metamask-config' const STORAGE_KEY = 'metamask-config'
const controller = new MetamaskController({ const controller = new MetamaskController({
// User confirmation callbacks: // User confirmation callbacks:
showUnconfirmedMessage, showUnconfirmedMessage,

@ -3,6 +3,8 @@ const TESTNET_RPC_URL = 'https://morden.infura.io/'
const DEFAULT_RPC_URL = TESTNET_RPC_URL const DEFAULT_RPC_URL = TESTNET_RPC_URL
const CLASSIC_RPC_URL = 'https://mainnet-nf.infura.io/' const CLASSIC_RPC_URL = 'https://mainnet-nf.infura.io/'
global.METAMASK_DEBUG = false
module.exports = { module.exports = {
network: { network: {
default: DEFAULT_RPC_URL, default: DEFAULT_RPC_URL,
@ -11,4 +13,3 @@ module.exports = {
classic: CLASSIC_RPC_URL, classic: CLASSIC_RPC_URL,
}, },
} }

@ -1,4 +1,4 @@
const LocalMessageDuplexStream = require('./lib/local-message-stream.js') const LocalMessageDuplexStream = require('post-message-stream')
const PortStream = require('./lib/port-stream.js') const PortStream = require('./lib/port-stream.js')
const ObjectMultiplex = require('./lib/obj-multiplex') const ObjectMultiplex = require('./lib/obj-multiplex')
const extension = require('./lib/extension') const extension = require('./lib/extension')

@ -1,7 +1,7 @@
/*global Web3*/ /*global Web3*/
cleanContextForImports() cleanContextForImports()
require('web3/dist/web3.min.js') require('web3/dist/web3.min.js')
const LocalMessageDuplexStream = require('./lib/local-message-stream.js') const LocalMessageDuplexStream = require('post-message-stream')
const setupDappAutoReload = require('./lib/auto-reload.js') const setupDappAutoReload = require('./lib/auto-reload.js')
const MetamaskInpageProvider = require('./lib/inpage-provider.js') const MetamaskInpageProvider = require('./lib/inpage-provider.js')
restoreContextAfterImports() restoreContextAfterImports()

@ -1,5 +1,5 @@
const once = require('once') const once = require('once')
const ensnare = require('./ensnare.js') const ensnare = require('ensnare')
module.exports = setupDappAutoReload module.exports = setupDappAutoReload

@ -1,24 +0,0 @@
module.exports = ensnare
// creates a proxy object that calls cb everytime the obj's properties/fns are accessed
function ensnare (obj, cb) {
var proxy = {}
Object.keys(obj).forEach(function (key) {
var val = obj[key]
switch (typeof val) {
case 'function':
proxy[key] = function () {
cb()
val.apply(obj, arguments)
}
return
default:
Object.defineProperty(proxy, key, {
get: function () { cb(); return obj[key] },
set: function (val) { cb(); obj[key] = val; return val },
})
return
}
})
return proxy
}

@ -153,8 +153,9 @@ IdentityStore.prototype.getNetwork = function (err) {
this._currentState.network = 'loading' this._currentState.network = 'loading'
return this._didUpdate() return this._didUpdate()
} }
if (global.METAMASK_DEBUG) {
console.log('web3.getNetwork returned ' + network) console.log('web3.getNetwork returned ' + network)
}
this._currentState.network = network this._currentState.network = network
this._didUpdate() this._didUpdate()
}) })
@ -475,7 +476,9 @@ IdentityStore.prototype._restoreFromSeed = function (password, seed, derivedKey)
keyStore.generateNewAddress(derivedKey, 3) keyStore.generateNewAddress(derivedKey, 3)
configManager.setWallet(keyStore.serialize()) configManager.setWallet(keyStore.serialize())
console.log('restored from seed. saved to keystore') if (global.METAMASK_DEBUG) {
console.log('restored from seed. saved to keystore')
}
return keyStore return keyStore
} }

@ -1,9 +1,7 @@
const HttpProvider = require('web3/lib/web3/httpprovider')
const Streams = require('mississippi') const Streams = require('mississippi')
const ObjectMultiplex = require('./obj-multiplex') const ObjectMultiplex = require('./obj-multiplex')
const StreamProvider = require('web3-stream-provider') const StreamProvider = require('web3-stream-provider')
const RemoteStore = require('./remote-store.js').RemoteStore const RemoteStore = require('./remote-store.js').RemoteStore
const MetamaskConfig = require('../config.js')
module.exports = MetamaskInpageProvider module.exports = MetamaskInpageProvider
@ -27,13 +25,6 @@ function MetamaskInpageProvider (connectionStream) {
}) })
self.publicConfigStore = publicConfigStore self.publicConfigStore = publicConfigStore
// connect to sync provider
self.syncProvider = createSyncProvider(publicConfigStore.get('provider'))
// subscribe to publicConfig to update the syncProvider on change
publicConfigStore.subscribe(function (state) {
self.syncProvider = createSyncProvider(state.provider)
})
// connect to async provider // connect to async provider
var asyncProvider = new StreamProvider() var asyncProvider = new StreamProvider()
Streams.pipe(asyncProvider, multiStream.createStream('provider'), asyncProvider, function (err) { Streams.pipe(asyncProvider, multiStream.createStream('provider'), asyncProvider, function (err) {
@ -48,9 +39,9 @@ function MetamaskInpageProvider (connectionStream) {
MetamaskInpageProvider.prototype.send = function (payload) { MetamaskInpageProvider.prototype.send = function (payload) {
const self = this const self = this
let selectedAddress let selectedAddress
let result = null
var result = null
switch (payload.method) { switch (payload.method) {
case 'eth_accounts': case 'eth_accounts':
@ -65,9 +56,10 @@ MetamaskInpageProvider.prototype.send = function (payload) {
result = selectedAddress || '0x0000000000000000000000000000000000000000' result = selectedAddress || '0x0000000000000000000000000000000000000000'
break break
// fallback to normal rpc // throw not-supported Error
default: default:
return self.syncProvider.send(payload) var message = 'The MetaMask Web3 object does not support synchronous methods. See https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#all-async---think-of-metamask-as-a-light-client for details.'
throw new Error(message)
} }
@ -89,35 +81,6 @@ MetamaskInpageProvider.prototype.isConnected = function () {
// util // util
function createSyncProvider (providerConfig) {
providerConfig = providerConfig || {}
let syncProviderUrl
if (providerConfig.rpcTarget) {
syncProviderUrl = providerConfig.rpcTarget
} else {
switch (providerConfig.type) {
case 'testnet':
syncProviderUrl = MetamaskConfig.network.testnet
break
case 'mainnet':
syncProviderUrl = MetamaskConfig.network.mainnet
break
default:
syncProviderUrl = MetamaskConfig.network.default
}
}
const provider = new HttpProvider(syncProviderUrl)
// Stubbing out the send method to throw on sync methods:
provider.send = function() {
var message = 'The MetaMask Web3 object does not support synchronous methods. See https://github.com/MetaMask/faq#all-async---think-of-metamask-as-a-light-client for details.'
throw new Error(message)
}
return provider
}
function remoteStoreWithLocalStorageCache (storageKey) { function remoteStoreWithLocalStorageCache (storageKey) {
// read local cache // read local cache
var initState = JSON.parse(localStorage[storageKey] || '{}') var initState = JSON.parse(localStorage[storageKey] || '{}')

@ -1,56 +0,0 @@
const Duplex = require('readable-stream').Duplex
const inherits = require('util').inherits
module.exports = LocalMessageDuplexStream
inherits(LocalMessageDuplexStream, Duplex)
function LocalMessageDuplexStream (opts) {
Duplex.call(this, {
objectMode: true,
})
// this._origin = opts.origin
this._name = opts.name
this._target = opts.target
// console.log('LocalMessageDuplexStream ('+this._name+') - initialized...')
window.addEventListener('message', this._onMessage.bind(this), false)
}
// private
LocalMessageDuplexStream.prototype._onMessage = function (event) {
var msg = event.data
// console.log('LocalMessageDuplexStream ('+this._name+') - heard message...', event)
// validate message
if (event.origin !== location.origin) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (event.origin !== location.origin) ')
if (typeof msg !== 'object') return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (typeof msg !== "object") ')
if (msg.target !== this._name) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (msg.target !== this._name) ', msg.target, this._name)
if (!msg.data) return // console.log('LocalMessageDuplexStream ('+this._name+') - rejected - (!msg.data) ')
// console.log('LocalMessageDuplexStream ('+this._name+') - accepted', msg.data)
// forward message
try {
this.push(msg.data)
} catch (err) {
this.emit('error', err)
}
}
// stream plumbing
LocalMessageDuplexStream.prototype._read = noop
LocalMessageDuplexStream.prototype._write = function (data, encoding, cb) {
// console.log('LocalMessageDuplexStream ('+this._name+') - sending message...')
var message = {
target: this._target,
data: data,
}
window.postMessage(message, location.origin)
cb()
}
// util
function noop () {}

@ -94,7 +94,9 @@ module.exports = class MetamaskController {
function logger (err, request, response) { function logger (err, request, response) {
if (err) return console.error(err) if (err) return console.error(err)
if (!request.isMetamaskInternal) { if (!request.isMetamaskInternal) {
console.log(`RPC (${originDomain}):`, request, '->', response) if (global.METAMASK_DEBUG) {
console.log(`RPC (${originDomain}):`, request, '->', response)
}
if (response.error) { if (response.error) {
console.error('Error in RPC response:\n', response.error) console.error('Error in RPC response:\n', response.error)
} }
@ -218,7 +220,9 @@ module.exports = class MetamaskController {
// Log blocks // Log blocks
processBlock (block) { processBlock (block) {
console.log(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`) if (global.METAMASK_DEBUG) {
console.log(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`)
}
this.verifyNetwork() this.verifyNetwork()
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -19,6 +19,7 @@ const Root = require('./ui/app/root')
const configureStore = require('./ui/app/store') const configureStore = require('./ui/app/store')
const actions = require('./ui/app/actions') const actions = require('./ui/app/actions')
const states = require('./development/states') const states = require('./development/states')
const Selector = require('./development/selector')
const MetamaskController = require('./app/scripts/metamask-controller') const MetamaskController = require('./app/scripts/metamask-controller')
const extension = require('./development/mockExtension') const extension = require('./development/mockExtension')
@ -139,6 +140,8 @@ render(
}, },
}, 'Reset State'), }, 'Reset State'),
h(Selector, { actions, selectedKey: selectedView, states, store }),
h('.mock-app-root', { h('.mock-app-root', {
style: { style: {
height: '500px', height: '500px',

@ -35,6 +35,7 @@
"debounce": "^1.0.0", "debounce": "^1.0.0",
"dnode": "^1.2.2", "dnode": "^1.2.2",
"end-of-stream": "^1.1.0", "end-of-stream": "^1.1.0",
"ensnare": "^1.0.0",
"eth-bin-to-ops": "^1.0.0", "eth-bin-to-ops": "^1.0.0",
"eth-lightwallet": "^2.3.3", "eth-lightwallet": "^2.3.3",
"eth-query": "^1.0.3", "eth-query": "^1.0.3",
@ -53,6 +54,7 @@
"once": "^1.3.3", "once": "^1.3.3",
"pojo-migrator": "^2.1.0", "pojo-migrator": "^2.1.0",
"polyfill-crypto.getrandomvalues": "^1.0.0", "polyfill-crypto.getrandomvalues": "^1.0.0",
"post-message-stream": "^1.0.0",
"pumpify": "^1.3.4", "pumpify": "^1.3.4",
"react": "^15.0.2", "react": "^15.0.2",
"react-addons-css-transition-group": "^15.0.2", "react-addons-css-transition-group": "^15.0.2",
@ -72,7 +74,7 @@
"vreme": "^3.0.2", "vreme": "^3.0.2",
"web3": "ethereum/web3.js#0.16.0", "web3": "ethereum/web3.js#0.16.0",
"web3-provider-engine": "^7.8.3", "web3-provider-engine": "^7.8.3",
"web3-stream-provider": "^2.0.5", "web3-stream-provider": "^2.0.6",
"xtend": "^4.0.1" "xtend": "^4.0.1"
}, },
"devDependencies": { "devDependencies": {

@ -23,7 +23,7 @@ Network.prototype.render = function () {
if (networkNumber === 'loading') { if (networkNumber === 'loading') {
return h('img', { return h('img.network-indicator', {
title: 'Attempting to connect to blockchain.', title: 'Attempting to connect to blockchain.',
onClick: (event) => this.props.onClick(event), onClick: (event) => this.props.onClick(event),
style: { style: {

@ -1,17 +1,20 @@
const createStore = require('redux').createStore const createStore = require('redux').createStore
const applyMiddleware = require('redux').applyMiddleware const applyMiddleware = require('redux').applyMiddleware
const thunkMiddleware = require('redux-thunk') const thunkMiddleware = require('redux-thunk')
// const createLogger = require('redux-logger')
const rootReducer = require('./reducers') const rootReducer = require('./reducers')
const createLogger = require('redux-logger')
global.METAMASK_DEBUG = false
module.exports = configureStore module.exports = configureStore
// const loggerMiddleware = createLogger() const loggerMiddleware = createLogger({
predicate: () => global.METAMASK_DEBUG,
})
const middlewares = [thunkMiddleware, loggerMiddleware]
const createStoreWithMiddleware = applyMiddleware( const createStoreWithMiddleware = applyMiddleware(...middlewares)(createStore)
thunkMiddleware
// // loggerMiddleware
)(createStore)
function configureStore (initialState) { function configureStore (initialState) {
return createStoreWithMiddleware(rootReducer, initialState) return createStoreWithMiddleware(rootReducer, initialState)

Loading…
Cancel
Save