From ee415058ccb3c78f480611343402f2a0b331381f Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Wed, 29 Jan 2020 20:57:14 -0400 Subject: [PATCH] Only resolve ENS on mainnet (#7944) The ENS resolver will now bail on any network other than mainnet. --- app/scripts/background.js | 1 + app/scripts/lib/ens-ipfs/setup.js | 5 +++-- app/scripts/metamask-controller.js | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/scripts/background.js b/app/scripts/background.js index bee63e711..774d04691 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -254,6 +254,7 @@ function setupController (initState, initLangCode) { }) setupEnsIpfsResolver({ + getCurrentNetwork: controller.getCurrentNetwork, getIpfsGateway: controller.preferencesController.getIpfsGateway.bind(controller.preferencesController), provider: controller.provider, }) diff --git a/app/scripts/lib/ens-ipfs/setup.js b/app/scripts/lib/ens-ipfs/setup.js index 3221cd62a..ee04b9340 100644 --- a/app/scripts/lib/ens-ipfs/setup.js +++ b/app/scripts/lib/ens-ipfs/setup.js @@ -6,7 +6,7 @@ const supportedTopLevelDomains = ['eth'] export default setupEnsIpfsResolver -function setupEnsIpfsResolver ({ provider, getIpfsGateway }) { +function setupEnsIpfsResolver ({ provider, getCurrentNetwork, getIpfsGateway }) { // install listener const urlPatterns = supportedTopLevelDomains.map(tld => `*://*.${tld}/*`) @@ -23,7 +23,8 @@ function setupEnsIpfsResolver ({ provider, getIpfsGateway }) { async function webRequestDidFail (details) { const { tabId, url } = details // ignore requests that are not associated with tabs - if (tabId === -1) { + // only attempt ENS resolution on mainnet + if (tabId === -1 || getCurrentNetwork() !== '1') { return } // parse ens name diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 5bbc54ccd..4fe9903ea 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -675,6 +675,10 @@ export default class MetamaskController extends EventEmitter { }) } + getCurrentNetwork = () => { + return this.networkController.store.getState().network + } + /** * Collects all the information that we want to share * with the mobile client for syncing purposes