diff --git a/app/scripts/lib/ens-ipfs/setup.js b/app/scripts/lib/ens-ipfs/setup.js index 77052b05e483..be997cdf1e98 100644 --- a/app/scripts/lib/ens-ipfs/setup.js +++ b/app/scripts/lib/ens-ipfs/setup.js @@ -58,18 +58,21 @@ export default function setupEnsIpfsResolver({ const ipfsGateway = getIpfsGateway(); const useAddressBarEnsResolution = getUseAddressBarEnsResolution(); - if (!useAddressBarEnsResolution || ipfsGateway === '') { - return; - } + const ensSiteUrl = `https://app.ens.domains/name/${name}`; - browser.tabs.update(tabId, { url: `loading.html` }); + // We cannot show this if useAddressBarEnsResolution is off... + if (useAddressBarEnsResolution && ipfsGateway) { + browser.tabs.update(tabId, { url: 'loading.html' }); + } - let url = `https://app.ens.domains/name/${name}`; + let url = ensSiteUrl; // If we're testing ENS domain resolution support, // we assume the ENS domains URL if (process.env.IN_TEST) { - browser.tabs.update(tabId, { url }); + if (useAddressBarEnsResolution || ipfsGateway) { + browser.tabs.update(tabId, { url }); + } return; } @@ -79,6 +82,12 @@ export default function setupEnsIpfsResolver({ name, }); if (type === 'ipfs-ns' || type === 'ipns-ns') { + // If the ENS is via IPFS and that setting is disabled, + // Do not resolve the ENS + if (ipfsGateway === '') { + url = null; + return; + } const resolvedUrl = `https://${hash}.${type.slice( 0, 4, @@ -121,7 +130,15 @@ export default function setupEnsIpfsResolver({ } catch (err) { console.warn(err); } finally { - browser.tabs.update(tabId, { url }); + // Only forward to destination URL if a URL exists and + // useAddressBarEnsResolution is properly + if ( + url && + (useAddressBarEnsResolution || + (!useAddressBarEnsResolution && url !== ensSiteUrl)) + ) { + browser.tabs.update(tabId, { url }); + } } } } diff --git a/test/e2e/tests/ipfs-ens-resolution.spec.js b/test/e2e/tests/ipfs-ens-resolution.spec.js index 73b2f70d66b8..ba7a1357d283 100644 --- a/test/e2e/tests/ipfs-ens-resolution.spec.js +++ b/test/e2e/tests/ipfs-ens-resolution.spec.js @@ -31,7 +31,7 @@ describe('Settings', function () { await driver.quit(); }); - it('Does not lookup IPFS data for ENS Domain when switched off', async function () { + it('Does not fetch ENS data for ENS Domain when ENS and IPFS switched off', async function () { let server; await withFixtures( @@ -54,7 +54,10 @@ describe('Settings', function () { await driver.clickElement({ text: 'Settings', tag: 'div' }); await driver.clickElement({ text: 'Security & privacy', tag: 'div' }); - // turns off IPFS domain resolution + // turns off IPFS setting + await driver.clickElement('[data-testid="ipfsToggle"] .toggle-button'); + + // turns off ENS domain resolution await driver.clickElement( '[data-testid="ipfs-gateway-resolution-container"] .toggle-button', );