Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
Only resolve ENS on mainnet (MetaMask#7944)
Browse files Browse the repository at this point in the history
The ENS resolver will now bail on any network other than mainnet.
  • Loading branch information
Gudahtt authored and yqrashawn committed Feb 3, 2020
1 parent 7d2dc79 commit ecc91e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 2 additions & 3 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,8 @@ function setupController (initState, initLangCode) {
})

// setupEnsIpfsResolver({
// getIpfsGateway: controller.preferencesController.getIpfsGateway.bind(
// controller.preferencesController
// ),
// getCurrentNetwork: controller.getCurrentNetwork,
// getIpfsGateway: controller.preferencesController.getIpfsGateway.bind(controller.preferencesController),
// provider: controller.provider,
// })

Expand Down
6 changes: 4 additions & 2 deletions app/scripts/lib/ens-ipfs/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const supportedTopLevelDomains = ['eth']

export default setupEnsIpfsResolver

function setupEnsIpfsResolver ({ provider, getIpfsGateway }) {
function setupEnsIpfsResolver ({ provider, getCurrentNetwork, getIpfsGateway }) {

// install listener
const urlPatterns = supportedTopLevelDomains.map(tld => `*://*.${tld}/*`)
extension.webRequest.onErrorOccurred.addListener(webRequestDidFail, {
Expand All @@ -25,7 +26,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
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,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
Expand Down

0 comments on commit ecc91e4

Please sign in to comment.