From d433677357abb886195781f5e9afbf8fb94e976a Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Thu, 21 Mar 2019 15:26:54 +0000 Subject: [PATCH 1/4] feat: `inpageProvider.autoRefreshOnNetworkChange` to allow dapps to control if it refreshes or not --- app/scripts/inpage.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index c7f0c56696dd..a0d1d3197760 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -91,6 +91,10 @@ inpageProvider.enable = function ({ force } = {}) { }) } +// give the dapps control of a refresh they can toggle this off on the window.ethereum +// this will be default true so it does not break any old apps. +inpageProvider.autoRefreshOnNetworkChange = true; + // add metamask-specific convenience methods inpageProvider._metamask = new Proxy({ /** From 7010734c498feecc25bd2ba3d501e011f3f326f2 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Thu, 21 Mar 2019 15:27:10 +0000 Subject: [PATCH 2/4] feat: check the `autoRefreshOnNetworkChange` before a refresh --- app/scripts/lib/auto-reload.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js index 558391a06448..1371a2041fb0 100644 --- a/app/scripts/lib/auto-reload.js +++ b/app/scripts/lib/auto-reload.js @@ -20,6 +20,10 @@ function setupDappAutoReload (web3, observable) { }) observable.subscribe(function (state) { + // if the auto refresh on network change is false do not + // do anything + if (!web3.ethereum.autoRefreshOnNetworkChange) return + // if reload in progress, no need to check reload logic if (reloadInProgress) return From 817e27afb7ff8444d6295378ae09ebb4ff61b520 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Thu, 21 Mar 2019 16:01:15 +0000 Subject: [PATCH 3/4] fix linting error --- app/scripts/inpage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index a0d1d3197760..68394d1ae743 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -93,7 +93,7 @@ inpageProvider.enable = function ({ force } = {}) { // give the dapps control of a refresh they can toggle this off on the window.ethereum // this will be default true so it does not break any old apps. -inpageProvider.autoRefreshOnNetworkChange = true; +inpageProvider.autoRefreshOnNetworkChange = true // add metamask-specific convenience methods inpageProvider._metamask = new Proxy({ From d54d06414f9f96c56ed630f211a98338e9643699 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Thu, 21 Mar 2019 16:05:47 +0000 Subject: [PATCH 4/4] fix: use `window.ethereum` now `web3.ethereum` --- app/scripts/lib/auto-reload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js index 1371a2041fb0..44fbe847c6a6 100644 --- a/app/scripts/lib/auto-reload.js +++ b/app/scripts/lib/auto-reload.js @@ -22,7 +22,7 @@ function setupDappAutoReload (web3, observable) { observable.subscribe(function (state) { // if the auto refresh on network change is false do not // do anything - if (!web3.ethereum.autoRefreshOnNetworkChange) return + if (!window.ethereum.autoRefreshOnNetworkChange) return // if reload in progress, no need to check reload logic if (reloadInProgress) return