diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index e9e64bb68..672502286 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -79,7 +79,12 @@ web3.setProvider = function () { } log.debug('MetaMask - injected web3') -window.ethereum._web3Ref = web3.eth +Object.defineProperty(window.ethereum, '_web3Ref', { + enumerable: false, + writable: true, + configurable: true, + value: web3.eth, +}) // setup dapp auto reload AND proxy web3 setupDappAutoReload(web3, window.ethereum._publicConfigStore) diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js index ceb7e5e3f..ce13ef0ca 100644 --- a/app/scripts/lib/auto-reload.js +++ b/app/scripts/lib/auto-reload.js @@ -8,7 +8,7 @@ export default function setupDappAutoReload (web3, observable) { let lastSeenNetwork let hasBeenWarned = false - global.web3 = new Proxy(web3, { + const web3Proxy = new Proxy(web3, { get: (_web3, key) => { // get the time of use lastTimeUsed = Date.now() @@ -26,6 +26,13 @@ export default function setupDappAutoReload (web3, observable) { }, }) + Object.defineProperty(global, 'web3', { + enumerable: false, + writable: true, + configurable: true, + value: web3Proxy, + }) + observable.subscribe(function (state) { // if the auto refresh on network change is false do not // do anything