Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #20910 - Turn off ENS resolution if IPFS is turned off #20915

Merged
merged 5 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading