From 2aaec1d9fbaa340ee9971278b6fafd1ad49bdbf2 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Thu, 21 Mar 2019 19:42:23 +0000 Subject: [PATCH] Stop reloading dapps on network change allowing dapps to decide if it should refresh or not (#6330) * feat: `inpageProvider.autoRefreshOnNetworkChange` to allow dapps to control if it refreshes or not * feat: check the `autoRefreshOnNetworkChange` before a refresh * fix linting error * fix: use `window.ethereum` now `web3.ethereum` --- app/scripts/inpage.js | 4 ++++ app/scripts/lib/auto-reload.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index c7f0c5669..68394d1ae 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({ /** diff --git a/app/scripts/lib/auto-reload.js b/app/scripts/lib/auto-reload.js index 558391a06..44fbe847c 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 (!window.ethereum.autoRefreshOnNetworkChange) return + // if reload in progress, no need to check reload logic if (reloadInProgress) return