mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge branch 'master' into buyForm
This commit is contained in:
commit
632465b213
@ -3,6 +3,7 @@
|
||||
## Current Master
|
||||
|
||||
- Fix various typos.
|
||||
- Make dapp-metamask connection more reliable
|
||||
|
||||
## 2.7.3 2016-07-29
|
||||
|
||||
|
@ -13,6 +13,7 @@ const extension = require('./lib/extension')
|
||||
|
||||
const STORAGE_KEY = 'metamask-config'
|
||||
|
||||
|
||||
const controller = new MetamaskController({
|
||||
// User confirmation callbacks:
|
||||
showUnconfirmedMessage,
|
||||
|
@ -3,6 +3,8 @@ const TESTNET_RPC_URL = 'https://morden.infura.io/'
|
||||
const DEFAULT_RPC_URL = TESTNET_RPC_URL
|
||||
const CLASSIC_RPC_URL = 'https://mainnet-nf.infura.io/'
|
||||
|
||||
global.METAMASK_DEBUG = false
|
||||
|
||||
module.exports = {
|
||||
network: {
|
||||
default: DEFAULT_RPC_URL,
|
||||
@ -11,4 +13,3 @@ module.exports = {
|
||||
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 ObjectMultiplex = require('./lib/obj-multiplex')
|
||||
const extension = require('./lib/extension')
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*global Web3*/
|
||||
cleanContextForImports()
|
||||
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 MetamaskInpageProvider = require('./lib/inpage-provider.js')
|
||||
restoreContextAfterImports()
|
||||
|
@ -1,5 +1,5 @@
|
||||
const once = require('once')
|
||||
const ensnare = require('./ensnare.js')
|
||||
const ensnare = require('ensnare')
|
||||
|
||||
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'
|
||||
return this._didUpdate()
|
||||
}
|
||||
|
||||
if (global.METAMASK_DEBUG) {
|
||||
console.log('web3.getNetwork returned ' + network)
|
||||
}
|
||||
this._currentState.network = network
|
||||
this._didUpdate()
|
||||
})
|
||||
@ -475,7 +476,9 @@ IdentityStore.prototype._restoreFromSeed = function (password, seed, derivedKey)
|
||||
|
||||
keyStore.generateNewAddress(derivedKey, 3)
|
||||
configManager.setWallet(keyStore.serialize())
|
||||
if (global.METAMASK_DEBUG) {
|
||||
console.log('restored from seed. saved to keystore')
|
||||
}
|
||||
return keyStore
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
const HttpProvider = require('web3/lib/web3/httpprovider')
|
||||
const Streams = require('mississippi')
|
||||
const ObjectMultiplex = require('./obj-multiplex')
|
||||
const StreamProvider = require('web3-stream-provider')
|
||||
const RemoteStore = require('./remote-store.js').RemoteStore
|
||||
const MetamaskConfig = require('../config.js')
|
||||
|
||||
module.exports = MetamaskInpageProvider
|
||||
|
||||
@ -27,13 +25,6 @@ function MetamaskInpageProvider (connectionStream) {
|
||||
})
|
||||
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
|
||||
var asyncProvider = new StreamProvider()
|
||||
Streams.pipe(asyncProvider, multiStream.createStream('provider'), asyncProvider, function (err) {
|
||||
@ -48,9 +39,9 @@ function MetamaskInpageProvider (connectionStream) {
|
||||
|
||||
MetamaskInpageProvider.prototype.send = function (payload) {
|
||||
const self = this
|
||||
let selectedAddress
|
||||
|
||||
var result = null
|
||||
let selectedAddress
|
||||
let result = null
|
||||
switch (payload.method) {
|
||||
|
||||
case 'eth_accounts':
|
||||
@ -65,9 +56,10 @@ MetamaskInpageProvider.prototype.send = function (payload) {
|
||||
result = selectedAddress || '0x0000000000000000000000000000000000000000'
|
||||
break
|
||||
|
||||
// fallback to normal rpc
|
||||
// throw not-supported Error
|
||||
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
|
||||
|
||||
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) {
|
||||
// read local cache
|
||||
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) {
|
||||
if (err) return console.error(err)
|
||||
if (!request.isMetamaskInternal) {
|
||||
if (global.METAMASK_DEBUG) {
|
||||
console.log(`RPC (${originDomain}):`, request, '->', response)
|
||||
}
|
||||
if (response.error) {
|
||||
console.error('Error in RPC response:\n', response.error)
|
||||
}
|
||||
@ -218,7 +220,9 @@ module.exports = class MetamaskController {
|
||||
|
||||
// Log blocks
|
||||
processBlock (block) {
|
||||
if (global.METAMASK_DEBUG) {
|
||||
console.log(`BLOCK CHANGED: #${block.number.toString('hex')} 0x${block.hash.toString('hex')}`)
|
||||
}
|
||||
this.verifyNetwork()
|
||||
}
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
189
development/states/custom-rpc.json
Normal file
189
development/states/custom-rpc.json
Normal file
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 actions = require('./ui/app/actions')
|
||||
const states = require('./development/states')
|
||||
const Selector = require('./development/selector')
|
||||
const MetamaskController = require('./app/scripts/metamask-controller')
|
||||
const extension = require('./development/mockExtension')
|
||||
|
||||
@ -139,6 +140,8 @@ render(
|
||||
},
|
||||
}, 'Reset State'),
|
||||
|
||||
h(Selector, { actions, selectedKey: selectedView, states, store }),
|
||||
|
||||
h('.mock-app-root', {
|
||||
style: {
|
||||
height: '500px',
|
||||
|
@ -35,6 +35,7 @@
|
||||
"debounce": "^1.0.0",
|
||||
"dnode": "^1.2.2",
|
||||
"end-of-stream": "^1.1.0",
|
||||
"ensnare": "^1.0.0",
|
||||
"eth-bin-to-ops": "^1.0.0",
|
||||
"eth-lightwallet": "^2.3.3",
|
||||
"eth-query": "^1.0.3",
|
||||
@ -53,6 +54,7 @@
|
||||
"once": "^1.3.3",
|
||||
"pojo-migrator": "^2.1.0",
|
||||
"polyfill-crypto.getrandomvalues": "^1.0.0",
|
||||
"post-message-stream": "^1.0.0",
|
||||
"pumpify": "^1.3.4",
|
||||
"react": "^15.0.2",
|
||||
"react-addons-css-transition-group": "^15.0.2",
|
||||
@ -72,7 +74,7 @@
|
||||
"vreme": "^3.0.2",
|
||||
"web3": "ethereum/web3.js#0.16.0",
|
||||
"web3-provider-engine": "^7.8.3",
|
||||
"web3-stream-provider": "^2.0.5",
|
||||
"web3-stream-provider": "^2.0.6",
|
||||
"xtend": "^4.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -23,7 +23,7 @@ Network.prototype.render = function () {
|
||||
|
||||
if (networkNumber === 'loading') {
|
||||
|
||||
return h('img', {
|
||||
return h('img.network-indicator', {
|
||||
title: 'Attempting to connect to blockchain.',
|
||||
onClick: (event) => this.props.onClick(event),
|
||||
style: {
|
||||
|
@ -1,17 +1,20 @@
|
||||
const createStore = require('redux').createStore
|
||||
const applyMiddleware = require('redux').applyMiddleware
|
||||
const thunkMiddleware = require('redux-thunk')
|
||||
// const createLogger = require('redux-logger')
|
||||
const rootReducer = require('./reducers')
|
||||
const createLogger = require('redux-logger')
|
||||
|
||||
global.METAMASK_DEBUG = false
|
||||
|
||||
module.exports = configureStore
|
||||
|
||||
// const loggerMiddleware = createLogger()
|
||||
const loggerMiddleware = createLogger({
|
||||
predicate: () => global.METAMASK_DEBUG,
|
||||
})
|
||||
|
||||
const createStoreWithMiddleware = applyMiddleware(
|
||||
thunkMiddleware
|
||||
// // loggerMiddleware
|
||||
)(createStore)
|
||||
const middlewares = [thunkMiddleware, loggerMiddleware]
|
||||
|
||||
const createStoreWithMiddleware = applyMiddleware(...middlewares)(createStore)
|
||||
|
||||
function configureStore (initialState) {
|
||||
return createStoreWithMiddleware(rootReducer, initialState)
|
||||
|
Loading…
Reference in New Issue
Block a user