A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/app/scripts/lib/auto-reload.js

35 lines
919 B

const once = require('once')
const ensnare = require('ensnare')
module.exports = setupDappAutoReload
9 years ago
function setupDappAutoReload (web3, controlStream) {
// export web3 as a global, checking for usage
var pageIsUsingWeb3 = false
var resetWasRequested = false
9 years ago
global.web3 = ensnare(web3, once(function () {
// if web3 usage happened after a reset request, trigger reset late
if (resetWasRequested) return triggerReset()
// mark web3 as used
pageIsUsingWeb3 = true
// reset web3 reference
global.web3 = web3
}))
// listen for reset requests from metamask
9 years ago
controlStream.once('data', function () {
resetWasRequested = true
// ignore if web3 was not used
if (!pageIsUsingWeb3) return
// reload after short timeout
triggerReset()
})
// reload the page
9 years ago
function triggerReset () {
setTimeout(function () {
global.location.reload()
}, 500)
}
9 years ago
}