diff options
author | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-06-13 06:48:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-13 06:48:17 +0800 |
commit | 73a9aaa8338c2d8a2960a79f02369caaa21b3c95 (patch) | |
tree | fb39d41db91c831202dc0b057231b77ed1308210 | |
parent | 0740dd6a5b89defd5f5ba27fa38c7004243f0ce2 (diff) | |
parent | bb201d7c4aec5c8bb72615aaf2880a806a2bd138 (diff) | |
download | tangerine-wallet-browser-73a9aaa8338c2d8a2960a79f02369caaa21b3c95.tar tangerine-wallet-browser-73a9aaa8338c2d8a2960a79f02369caaa21b3c95.tar.gz tangerine-wallet-browser-73a9aaa8338c2d8a2960a79f02369caaa21b3c95.tar.bz2 tangerine-wallet-browser-73a9aaa8338c2d8a2960a79f02369caaa21b3c95.tar.lz tangerine-wallet-browser-73a9aaa8338c2d8a2960a79f02369caaa21b3c95.tar.xz tangerine-wallet-browser-73a9aaa8338c2d8a2960a79f02369caaa21b3c95.tar.zst tangerine-wallet-browser-73a9aaa8338c2d8a2960a79f02369caaa21b3c95.zip |
Merge pull request #4558 from MetaMask/stop-reload-on-network-change
Stop reload on network change
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | app/scripts/inpage.js | 21 | ||||
-rw-r--r-- | app/scripts/lib/auto-reload.js | 61 |
3 files changed, 20 insertions, 65 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fef15109..3f9413c8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## Current Master -- Fix bug where account reset did not work with custom RPC providers. +- Fix bug where account reset did not work with custom RPC providers +- Stop reloading browser page on Ethereum network change ## 4.7.4 Tue Jun 05 2018 diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index 6d16eebd4..070f5d247 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -3,7 +3,6 @@ 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 MetamaskInpageProvider = require('./lib/inpage-provider.js') restoreContextAfterImports() @@ -38,8 +37,24 @@ 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 +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) { diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js deleted file mode 100644 index cce31c3d2..000000000 --- a/app/scripts/lib/auto-reload.js +++ /dev/null @@ -1,61 +0,0 @@ -module.exports = setupDappAutoReload - -function setupDappAutoReload (web3, observable) { - // 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) => { - // 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 - } - // get the time of use - lastTimeUsed = Date.now() - // return value normally - return _web3[key] - }, - set: (_web3, key, value) => { - // set value normally - _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() -} |