mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
wip
This commit is contained in:
parent
aea9491f6a
commit
f461bd8812
@ -3,7 +3,7 @@ cleanContextForImports()
|
||||
require('web3/dist/web3.min.js')
|
||||
const log = require('loglevel')
|
||||
const LocalMessageDuplexStream = require('post-message-stream')
|
||||
const setupDappAutoReload = require('./lib/auto-reload.js')
|
||||
const exportWeb3Global = require('./lib/auto-reload.js')
|
||||
const MetamaskInpageProvider = require('./lib/inpage-provider.js')
|
||||
restoreContextAfterImports()
|
||||
|
||||
@ -38,8 +38,25 @@ web3.setProvider = function () {
|
||||
log.debug('MetaMask - overrode web3.setProvider')
|
||||
}
|
||||
log.debug('MetaMask - injected web3')
|
||||
// export global web3, with usage-detection
|
||||
setupDappAutoReload(web3, inpageProvider.publicConfigStore)
|
||||
|
||||
// export global web3, with usage-detection and deprecation warning
|
||||
exportWeb3Global(web3)
|
||||
// let hasBeenWarned = false
|
||||
// global.web3 = new Proxy(web3, {
|
||||
// get: (_web3, key) => {
|
||||
// // show warning once on web3 access
|
||||
// if (!hasBeenWarned && key !== 'currentProvider') {
|
||||
// console.warn('MetaMask: web3 will be deprecated in the near future in favor of the ethereumProvider \nhttps://github.com/MetaMask/faq/blob/master/detecting_metamask.md#web3-deprecation')
|
||||
// hasBeenWarned = true
|
||||
// }
|
||||
// // return value normally
|
||||
// return _web3[key]
|
||||
// },
|
||||
// set: (_web3, key, value) => {
|
||||
// // set value normally
|
||||
// _web3[key] = value
|
||||
// },
|
||||
// })
|
||||
|
||||
// set web3 defaultAccount
|
||||
inpageProvider.publicConfigStore.subscribe(function (state) {
|
||||
|
@ -1,11 +1,9 @@
|
||||
module.exports = setupDappAutoReload
|
||||
module.exports = exportWeb3Global
|
||||
|
||||
function setupDappAutoReload (web3, observable) {
|
||||
function exportWeb3Global (web3) {
|
||||
// export web3 as a global, checking for usage
|
||||
let hasBeenWarned = false
|
||||
let reloadInProgress = false
|
||||
let lastTimeUsed
|
||||
let lastSeenNetwork
|
||||
|
||||
global.web3 = new Proxy(web3, {
|
||||
get: (_web3, key) => {
|
||||
@ -24,38 +22,4 @@ function setupDappAutoReload (web3, observable) {
|
||||
_web3[key] = value
|
||||
},
|
||||
})
|
||||
|
||||
observable.subscribe(function (state) {
|
||||
// if reload in progress, no need to check reload logic
|
||||
if (reloadInProgress) return
|
||||
|
||||
const currentNetwork = state.networkVersion
|
||||
|
||||
// set the initial network
|
||||
if (!lastSeenNetwork) {
|
||||
lastSeenNetwork = currentNetwork
|
||||
return
|
||||
}
|
||||
|
||||
// skip reload logic if web3 not used
|
||||
if (!lastTimeUsed) return
|
||||
|
||||
// if network did not change, exit
|
||||
if (currentNetwork === lastSeenNetwork) return
|
||||
|
||||
// initiate page reload
|
||||
reloadInProgress = true
|
||||
const timeSinceUse = Date.now() - lastTimeUsed
|
||||
// if web3 was recently used then delay the reloading of the page
|
||||
if (timeSinceUse > 500) {
|
||||
triggerReset()
|
||||
} else {
|
||||
setTimeout(triggerReset, 500)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// reload the page
|
||||
function triggerReset () {
|
||||
global.location.reload()
|
||||
}
|
||||
|
13353
package-lock.json
generated
13353
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -118,7 +118,6 @@
|
||||
"fast-levenshtein": "^2.0.6",
|
||||
"file-loader": "^1.1.11",
|
||||
"fuse.js": "^3.2.0",
|
||||
"gulp": "github:gulpjs/gulp#4.0",
|
||||
"gulp-autoprefixer": "^5.0.0",
|
||||
"gulp-debug": "^3.2.0",
|
||||
"gulp-eslint": "^4.0.0",
|
||||
@ -237,7 +236,7 @@
|
||||
"geckodriver": "^1.11.0",
|
||||
"gh-pages": "^1.1.0",
|
||||
"gifencoder": "^1.1.0",
|
||||
"gulp": "github:gulpjs/gulp#6d71a658c61edb3090221579d8f97dbe086ba2ed",
|
||||
"gulp": "github:gulpjs/gulp#4.0",
|
||||
"gulp-babel": "^7.0.0",
|
||||
"gulp-eslint": "^4.0.0",
|
||||
"gulp-json-editor": "^2.2.1",
|
||||
|
Loading…
Reference in New Issue
Block a user