Skip to content

Commit 69b0db8

Browse files
committed
chore: drop psl direct dep and stale getDomain helper
The banner-rule logic that needed eTLD+1 grouping now lives in the NetworkConnectionBannerController package; nothing in the extension imports `getDomain` anymore.
1 parent b5a85bc commit 69b0db8

6 files changed

Lines changed: 1 addition & 91 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@
507507
"nanoid": "^3.3.8",
508508
"pify": "^5.0.0",
509509
"prop-types": "^15.6.1",
510-
"psl": "^1.15.0",
511510
"punycode": "^2.1.1",
512511
"qrcode-generator": "^2.0.4",
513512
"qrcode.react": "^4.2.0",

shared/lib/url-utils.test.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getDomain, isLocalhostOrIPAddress } from './url-utils';
1+
import { isLocalhostOrIPAddress } from './url-utils';
22

33
describe('isLocalhostOrIPAddress', () => {
44
it('returns true for "localhost" (any case)', () => {
@@ -23,43 +23,3 @@ describe('isLocalhostOrIPAddress', () => {
2323
expect(isLocalhostOrIPAddress('my-custom-rpc')).toBe(false);
2424
});
2525
});
26-
27-
describe('getDomain', () => {
28-
it('returns the last two labels for a multi-label hostname', () => {
29-
expect(getDomain('https://mainnet.infura.io/v3/abc')).toBe('infura.io');
30-
});
31-
32-
it('groups subdomain-heavy hostnames under the same registrable domain', () => {
33-
expect(getDomain('https://linea-mainnet.infura.io/v3/abc')).toBe(
34-
'infura.io',
35-
);
36-
expect(getDomain('https://polygon-mainnet.g.alchemy.com/v2/abc')).toBe(
37-
'alchemy.com',
38-
);
39-
});
40-
41-
it('returns the hostname as-is when it has exactly two labels', () => {
42-
expect(getDomain('https://alchemy.com/')).toBe('alchemy.com');
43-
});
44-
45-
it('handles multi-part public suffixes like .co.uk', () => {
46-
expect(getDomain('https://api.example.co.uk/v1')).toBe('example.co.uk');
47-
expect(getDomain('https://example.co.uk/')).toBe('example.co.uk');
48-
});
49-
50-
it('returns single-label hosts (e.g., localhost) verbatim', () => {
51-
expect(getDomain('http://localhost:8545')).toBe('localhost');
52-
});
53-
54-
it('returns IPv4 addresses verbatim', () => {
55-
expect(getDomain('http://127.0.0.1:8545')).toBe('127.0.0.1');
56-
});
57-
58-
it('returns IPv6 addresses verbatim, including brackets', () => {
59-
expect(getDomain('http://[::1]:8545')).toBe('[::1]');
60-
});
61-
62-
it('returns null for an invalid URL', () => {
63-
expect(getDomain('not a url')).toBeNull();
64-
});
65-
});

shared/lib/url-utils.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import urlLib from 'url';
22
import ipRegex from 'ip-regex';
3-
import psl from 'psl';
43

54
export function addUrlProtocolPrefix(urlString: string) {
65
let trimmed = urlString.trim();
@@ -80,31 +79,3 @@ export function isLocalhostOrIPAddress(hostname: string): boolean {
8079

8180
return ipRegex({ exact: true }).test(hostnameWithoutBrackets);
8281
}
83-
84-
/**
85-
* Registrable domain (eTLD+1) for a URL, computed via the Public Suffix List
86-
* so multi-part suffixes like ".co.uk" resolve correctly. Used to group RPC
87-
* endpoints by provider so a single provider's wide outage (e.g. *.infura.io)
88-
* is treated as one failure rather than many.
89-
*
90-
* Localhost, IP literals, and single-label hosts are returned verbatim rather
91-
* than reduced to a domain (psl returns null or garbage for those, and callers
92-
* grouping by domain still need to distinguish them).
93-
*
94-
* @param urlString - The URL to extract a domain from.
95-
* @returns The domain, or null if the URL is invalid.
96-
*/
97-
export function getDomain(urlString: string): string | null {
98-
const url = getValidUrl(urlString);
99-
if (url === null) {
100-
return null;
101-
}
102-
103-
const { hostname } = url;
104-
105-
if (!hostname.includes('.') || isLocalhostOrIPAddress(hostname)) {
106-
return hostname;
107-
}
108-
109-
return psl.get(hostname) ?? hostname;
110-
}

types/psl.d.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

ui/selectors/multichain/networks.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ import {
4444
} from '../../../shared/lib/selectors/networks';
4545
import { createDeepEqualSelector } from '../../../shared/lib/selectors/selector-creators';
4646
import { getEnabledNetworks } from '../../../shared/lib/selectors/multichain';
47-
import { getIsMetaMaskInfuraEndpointUrl } from '../../../shared/lib/network-utils';
48-
import { getDomain } from '../../../shared/lib/url-utils';
4947
import type { RemoteFeatureFlagsState } from '../../../shared/lib/selectors/remote-feature-flags';
5048
import {
5149
type AccountsState,

yarn.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33575,7 +33575,6 @@ __metadata:
3357533575
prettier-plugin-sort-json: "npm:^4.1.1"
3357633576
process: "npm:^0.11.10"
3357733577
prop-types: "npm:^15.6.1"
33578-
psl: "npm:^1.15.0"
3357933578
pumpify: "npm:^2.0.1"
3358033579
punycode: "npm:^2.1.1"
3358133580
qrcode-generator: "npm:^2.0.4"

0 commit comments

Comments
 (0)