From 2ceac1f27f1a19cfd0ee1847526bf442c2051126 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Wed, 21 Aug 2019 11:15:57 -0300 Subject: Add warning about reload on network change We are soon removing the automatic refresh on network change behavior. A warning has been added to ensure sites know about this upcoming change. Any site that calls `.enable` is advised to use a `networkChanged` event handler to reload manually if they rely upon that behavior. They are also advised to set the flag `autoRefreshOnNetworkChange` to `false` to opt-out of the reload behavior early. This warning might be irritating for certain sites, as they might be indifferent to whether or not the site reloads, and not eager to set a flag to opt-in early just to silence the warning. However there was no other obvious way to warning the right people about this change, as any warning prior to an actual reload would only be seen by the few people that set their browser console to preserve logs. Relates to #3599 --- app/scripts/inpage.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/scripts/inpage.js b/app/scripts/inpage.js index a94787b05..31e6a1f49 100644 --- a/app/scripts/inpage.js +++ b/app/scripts/inpage.js @@ -61,8 +61,19 @@ const inpageProvider = new MetamaskInpageProvider(metamaskStream) // set a high max listener count to avoid unnecesary warnings inpageProvider.setMaxListeners(100) +let warnedOfAutoRefreshDeprecation = false // augment the provider with its enable method inpageProvider.enable = function ({ force } = {}) { + if ( + !warnedOfAutoRefreshDeprecation && + inpageProvider.autoRefreshOnNetworkChange + ) { + console.warn(`MetaMask: MetaMask will soon stop reloading pages on network change. +If you rely upon this behavior, add a 'networkChanged' event handler to trigger the reload manually: https://metamask.github.io/metamask-docs/API_Reference/Ethereum_Provider#ethereum.on(eventname%2C-callback) +Set 'ethereum.autoRefreshOnNetworkChange' to 'false' to silence this warning: https://metamask.github.io/metamask-docs/API_Reference/Ethereum_Provider#ethereum.autorefreshonnetworkchange' +`) + warnedOfAutoRefreshDeprecation = true + } return new Promise((resolve, reject) => { inpageProvider.sendAsync({ method: 'eth_requestAccounts', params: [force] }, (error, response) => { if (error || response.error) { -- cgit