mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge branch 'master' into i#495CustomGasField
This commit is contained in:
commit
b200f74d5f
@ -1,4 +1,5 @@
|
|||||||
const LocalMessageDuplexStream = require('post-message-stream')
|
const LocalMessageDuplexStream = require('post-message-stream')
|
||||||
|
const PongStream = require('ping-pong-stream/pong')
|
||||||
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')
|
||||||
@ -51,17 +52,20 @@ function setupStreams(){
|
|||||||
// forward communication plugin->inpage
|
// forward communication plugin->inpage
|
||||||
pageStream.pipe(pluginStream).pipe(pageStream)
|
pageStream.pipe(pluginStream).pipe(pageStream)
|
||||||
|
|
||||||
// connect contentscript->inpage reload stream
|
// setup local multistream channels
|
||||||
var mx = ObjectMultiplex()
|
var mx = ObjectMultiplex()
|
||||||
mx.on('error', console.error)
|
mx.on('error', console.error)
|
||||||
mx.pipe(pageStream)
|
mx.pipe(pageStream).pipe(mx)
|
||||||
var reloadStream = mx.createStream('reload')
|
|
||||||
reloadStream.on('error', console.error)
|
// connect ping stream
|
||||||
|
var pongStream = new PongStream({ objectMode: true })
|
||||||
|
pongStream.pipe(mx.createStream('pingpong')).pipe(pongStream)
|
||||||
|
|
||||||
|
// ignore unused channels (handled by background)
|
||||||
|
mx.ignoreStream('provider')
|
||||||
|
mx.ignoreStream('publicConfig')
|
||||||
|
mx.ignoreStream('reload')
|
||||||
|
|
||||||
// if we lose connection with the plugin, trigger tab refresh
|
|
||||||
pluginStream.on('close', function () {
|
|
||||||
reloadStream.write({ method: 'reset' })
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldInjectWeb3(){
|
function shouldInjectWeb3(){
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
cleanContextForImports()
|
cleanContextForImports()
|
||||||
require('web3/dist/web3.min.js')
|
require('web3/dist/web3.min.js')
|
||||||
const LocalMessageDuplexStream = require('post-message-stream')
|
const LocalMessageDuplexStream = require('post-message-stream')
|
||||||
|
const PingStream = require('ping-pong-stream/ping')
|
||||||
|
const endOfStream = require('end-of-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()
|
||||||
@ -29,13 +31,22 @@ web3.setProvider = function () {
|
|||||||
console.log('MetaMask - overrode web3.setProvider')
|
console.log('MetaMask - overrode web3.setProvider')
|
||||||
}
|
}
|
||||||
console.log('MetaMask - injected web3')
|
console.log('MetaMask - injected web3')
|
||||||
|
// export global web3, with usage-detection reload fn
|
||||||
|
var triggerReload = setupDappAutoReload(web3)
|
||||||
|
|
||||||
//
|
// listen for reset requests from metamask
|
||||||
// export global web3 with auto dapp reload
|
|
||||||
//
|
|
||||||
|
|
||||||
var reloadStream = inpageProvider.multiStream.createStream('reload')
|
var reloadStream = inpageProvider.multiStream.createStream('reload')
|
||||||
setupDappAutoReload(web3, reloadStream)
|
reloadStream.once('data', triggerReload)
|
||||||
|
|
||||||
|
// setup ping timeout autoreload
|
||||||
|
// LocalMessageDuplexStream does not self-close, so reload if pingStream fails
|
||||||
|
var pingChannel = inpageProvider.multiStream.createStream('pingpong')
|
||||||
|
var pingStream = new PingStream({ objectMode: true })
|
||||||
|
// wait for first successful reponse
|
||||||
|
metamaskStream.once('data', function(){
|
||||||
|
pingStream.pipe(pingChannel).pipe(pingStream)
|
||||||
|
})
|
||||||
|
endOfStream(pingStream, triggerReload)
|
||||||
|
|
||||||
// set web3 defaultAcount
|
// set web3 defaultAcount
|
||||||
inpageProvider.publicConfigStore.subscribe(function (state) {
|
inpageProvider.publicConfigStore.subscribe(function (state) {
|
||||||
|
@ -3,7 +3,7 @@ const ensnare = require('ensnare')
|
|||||||
|
|
||||||
module.exports = setupDappAutoReload
|
module.exports = setupDappAutoReload
|
||||||
|
|
||||||
function setupDappAutoReload (web3, controlStream) {
|
function setupDappAutoReload (web3) {
|
||||||
// export web3 as a global, checking for usage
|
// export web3 as a global, checking for usage
|
||||||
var pageIsUsingWeb3 = false
|
var pageIsUsingWeb3 = false
|
||||||
var resetWasRequested = false
|
var resetWasRequested = false
|
||||||
@ -16,19 +16,19 @@ function setupDappAutoReload (web3, controlStream) {
|
|||||||
global.web3 = web3
|
global.web3 = web3
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// listen for reset requests from metamask
|
return handleResetRequest
|
||||||
controlStream.once('data', function () {
|
|
||||||
|
function handleResetRequest() {
|
||||||
resetWasRequested = true
|
resetWasRequested = true
|
||||||
// ignore if web3 was not used
|
// ignore if web3 was not used
|
||||||
if (!pageIsUsingWeb3) return
|
if (!pageIsUsingWeb3) return
|
||||||
// reload after short timeout
|
// reload after short timeout
|
||||||
triggerReset()
|
setTimeout(triggerReset, 500)
|
||||||
})
|
|
||||||
|
|
||||||
// reload the page
|
|
||||||
function triggerReset () {
|
|
||||||
setTimeout(function () {
|
|
||||||
global.location.reload()
|
|
||||||
}, 500)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reload the page
|
||||||
|
function triggerReset () {
|
||||||
|
global.location.reload()
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
const Streams = require('mississippi')
|
const Streams = require('mississippi')
|
||||||
const ObjectMultiplex = require('./obj-multiplex')
|
|
||||||
const StreamProvider = require('web3-stream-provider')
|
const StreamProvider = require('web3-stream-provider')
|
||||||
|
const ObjectMultiplex = require('./obj-multiplex')
|
||||||
const RemoteStore = require('./remote-store.js').RemoteStore
|
const RemoteStore = require('./remote-store.js').RemoteStore
|
||||||
|
|
||||||
module.exports = MetamaskInpageProvider
|
module.exports = MetamaskInpageProvider
|
||||||
@ -11,8 +11,9 @@ function MetamaskInpageProvider (connectionStream) {
|
|||||||
// setup connectionStream multiplexing
|
// setup connectionStream multiplexing
|
||||||
var multiStream = ObjectMultiplex()
|
var multiStream = ObjectMultiplex()
|
||||||
Streams.pipe(connectionStream, multiStream, connectionStream, function (err) {
|
Streams.pipe(connectionStream, multiStream, connectionStream, function (err) {
|
||||||
console.warn('MetamaskInpageProvider - lost connection to MetaMask')
|
let warningMsg = 'MetamaskInpageProvider - lost connection to MetaMask'
|
||||||
if (err) throw err
|
if (err) warningMsg += '\n' + err.stack
|
||||||
|
console.warn(warningMsg)
|
||||||
})
|
})
|
||||||
self.multiStream = multiStream
|
self.multiStream = multiStream
|
||||||
|
|
||||||
@ -20,16 +21,18 @@ function MetamaskInpageProvider (connectionStream) {
|
|||||||
var publicConfigStore = remoteStoreWithLocalStorageCache('MetaMask-Config')
|
var publicConfigStore = remoteStoreWithLocalStorageCache('MetaMask-Config')
|
||||||
var storeStream = publicConfigStore.createStream()
|
var storeStream = publicConfigStore.createStream()
|
||||||
Streams.pipe(storeStream, multiStream.createStream('publicConfig'), storeStream, function (err) {
|
Streams.pipe(storeStream, multiStream.createStream('publicConfig'), storeStream, function (err) {
|
||||||
console.warn('MetamaskInpageProvider - lost connection to MetaMask publicConfig')
|
let warningMsg = 'MetamaskInpageProvider - lost connection to MetaMask publicConfig'
|
||||||
if (err) throw err
|
if (err) warningMsg += '\n' + err.stack
|
||||||
|
console.warn(warningMsg)
|
||||||
})
|
})
|
||||||
self.publicConfigStore = publicConfigStore
|
self.publicConfigStore = publicConfigStore
|
||||||
|
|
||||||
// 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) {
|
||||||
console.warn('MetamaskInpageProvider - lost connection to MetaMask provider')
|
let warningMsg = 'MetamaskInpageProvider - lost connection to MetaMask provider'
|
||||||
if (err) throw err
|
if (err) warningMsg += '\n' + err.stack
|
||||||
|
console.warn(warningMsg)
|
||||||
})
|
})
|
||||||
asyncProvider.on('error', console.error.bind(console))
|
asyncProvider.on('error', console.error.bind(console))
|
||||||
self.asyncProvider = asyncProvider
|
self.asyncProvider = asyncProvider
|
||||||
|
@ -10,9 +10,9 @@ function ObjectMultiplex (opts) {
|
|||||||
var data = chunk.data
|
var data = chunk.data
|
||||||
var substream = mx.streams[name]
|
var substream = mx.streams[name]
|
||||||
if (!substream) {
|
if (!substream) {
|
||||||
console.warn('orphaned data for stream ' + name)
|
console.warn(`orphaned data for stream "${name}"`)
|
||||||
} else {
|
} else {
|
||||||
substream.push(data)
|
if (substream.push) substream.push(data)
|
||||||
}
|
}
|
||||||
return cb()
|
return cb()
|
||||||
})
|
})
|
||||||
@ -36,5 +36,9 @@ function ObjectMultiplex (opts) {
|
|||||||
}
|
}
|
||||||
return substream
|
return substream
|
||||||
}
|
}
|
||||||
|
// ignore streams (dont display orphaned data warning)
|
||||||
|
mx.ignoreStream = function (name) {
|
||||||
|
mx.streams[name] = true
|
||||||
|
}
|
||||||
return mx
|
return mx
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,7 @@ PortDuplexStream.prototype._write = function (msg, encoding, cb) {
|
|||||||
}
|
}
|
||||||
cb()
|
cb()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
// console.error(err)
|
||||||
// this.emit('error', err)
|
|
||||||
cb(new Error('PortDuplexStream - disconnected'))
|
cb(new Error('PortDuplexStream - disconnected'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -281,9 +281,9 @@ module.exports = class MetamaskController {
|
|||||||
checkTOSChange () {
|
checkTOSChange () {
|
||||||
try {
|
try {
|
||||||
const storedHash = this.configManager.getTOSHash() || 0
|
const storedHash = this.configManager.getTOSHash() || 0
|
||||||
if (storedHash !== global.newTOSHash) {
|
if (storedHash !== global.TOS_HASH) {
|
||||||
this.resetDisclaimer()
|
this.resetDisclaimer()
|
||||||
this.setTOSHash(global.newTOSHash)
|
this.setTOSHash(global.TOS_HASH)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error in checking TOS change.')
|
console.error('Error in checking TOS change.')
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
"mississippi": "^1.2.0",
|
"mississippi": "^1.2.0",
|
||||||
"multiplex": "^6.7.0",
|
"multiplex": "^6.7.0",
|
||||||
"once": "^1.3.3",
|
"once": "^1.3.3",
|
||||||
|
"ping-pong-stream": "^1.0.0",
|
||||||
"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",
|
"post-message-stream": "^1.0.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user