diff options
author | kumavis <kumavis@users.noreply.github.com> | 2018-06-13 14:22:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-13 14:22:09 +0800 |
commit | 5032d6e4c593bfe9dbbac34357651151ec1964c3 (patch) | |
tree | e551235eb1a9dfec38544c5811ce37bd7c7df37e /app/scripts | |
parent | 013d8451c82fd26d201c5dc52b434eaf5d255906 (diff) | |
parent | 73a9aaa8338c2d8a2960a79f02369caaa21b3c95 (diff) | |
download | tangerine-wallet-browser-5032d6e4c593bfe9dbbac34357651151ec1964c3.tar tangerine-wallet-browser-5032d6e4c593bfe9dbbac34357651151ec1964c3.tar.gz tangerine-wallet-browser-5032d6e4c593bfe9dbbac34357651151ec1964c3.tar.bz2 tangerine-wallet-browser-5032d6e4c593bfe9dbbac34357651151ec1964c3.tar.lz tangerine-wallet-browser-5032d6e4c593bfe9dbbac34357651151ec1964c3.tar.xz tangerine-wallet-browser-5032d6e4c593bfe9dbbac34357651151ec1964c3.tar.zst tangerine-wallet-browser-5032d6e4c593bfe9dbbac34357651151ec1964c3.zip |
Merge branch 'develop' into nonce-tracker-mutex-fix
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/inpage.js | 21 | ||||
-rw-r--r-- | app/scripts/lib/auto-reload.js | 61 |
2 files changed, 18 insertions, 64 deletions
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() -} |