Skip to content

Commit

Permalink
Fix #20910 - Turn off ENS resolution if IPFS is turned off (#20915)
Browse files Browse the repository at this point in the history
* Fix #20910 - Turn off ENS resolution if IPFS is turned off

* Updated WIP

* Implement conditions for ENS and IPFS settings

* Remove initial fix

* Fix e2es
  • Loading branch information
darkwing authored Sep 21, 2023
1 parent f7d99e4 commit a0349a6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
31 changes: 24 additions & 7 deletions app/scripts/lib/ens-ipfs/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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,
Expand Down Expand Up @@ -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 });
}
}
}
}
7 changes: 5 additions & 2 deletions test/e2e/tests/ipfs-ens-resolution.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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',
);
Expand Down

0 comments on commit a0349a6

Please sign in to comment.