Skip to content

Commit 9a15384

Browse files
authored
Strip leading www. from hostname when reading explorer name (#60)
1 parent 1ff9224 commit 9a15384

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

packages/entrypoint/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ log("Starting on", { hostname, pathname, search });
1717
// prefix of the hostname is passed to `explorer` search param
1818
// @see vscode-host/src/deth/commands/ethViewerCommands.ts
1919
if (hostname.endsWith(".deth.net") && !url.searchParams.get("explorer")) {
20-
url.searchParams.set("explorer", hostname.slice(0, -9));
20+
url.searchParams.set(
21+
"explorer",
22+
hostname.slice(0, -9 /* length of '.deth.net' */)
23+
);
2124
}
2225

2326
log("setting iframe src:", url.href);

packages/vscode-host/src/deth/commands/ethViewerCommands.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ describe("ethViewerCommands", () => {
2222

2323
expect(getApiName()).toEqual("etherscan");
2424
});
25+
26+
it('strips leading "www." from hostname', () => {
27+
givenUrl(
28+
"https://www.bscscan.deth.net/token/0x2170ed0880ac9a755fd29b2688956bd959f933f8"
29+
);
30+
31+
expect(getApiName()).toEqual("bscscan");
32+
});
2533
});
2634

2735
describe(getContractAddress.name, () => {

packages/vscode-host/src/deth/commands/ethViewerCommands.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,16 @@ export const ethViewerCommands = {
1717
return path.startsWith("0x") ? path : undefined;
1818
},
1919
getApiName: (): string | undefined => {
20-
const { hostname } = window.location;
20+
const { hostname, search } = window.location;
21+
let res: string | undefined = undefined;
2122

22-
const searchParam = new URLSearchParams(window.location.search).get(
23-
"explorer"
24-
);
25-
26-
if (searchParam) return searchParam;
23+
const searchParam = new URLSearchParams(search).get("explorer");
24+
if (searchParam) res = searchParam;
2725

2826
// @todo this can be deprecated after we deploy and configure iframe entrypoints
29-
if (hostname.endsWith(".deth.net")) return hostname.slice(0, -9);
27+
if (hostname.endsWith(".deth.net")) res = hostname.slice(0, -9);
3028

31-
return undefined;
29+
return res && res.replace(/^www\./, "");
3230
},
3331
openRepoOnGithub: () => {
3432
window.open("https://github.com/dethcrypto/ethereum-code-viewer", "_blank");

0 commit comments

Comments
 (0)