fix(p2p): force browser mode on p2p subdomains

This commit is contained in:
Tommaso Casaburi
2026-05-11 17:18:16 +07:00
parent e38d888b74
commit a97b891c5f
6 changed files with 90 additions and 5 deletions
+19
View File
@@ -10,6 +10,7 @@ import {
const browserWindow = {
electronApi: undefined,
isElectron: false,
location: { hostname: '5chan.app' },
localStorage: {
getItem: () => null,
setItem: () => undefined,
@@ -19,6 +20,17 @@ const browserWindow = {
const electronWindow = {
electronApi: { isElectron: true },
isElectron: true,
location: { hostname: 'localhost' },
} as unknown as Window;
const p2pBrowserWindow = {
electronApi: undefined,
isElectron: false,
location: { hostname: 'p2p.5chan.app' },
localStorage: {
getItem: () => 'false',
setItem: () => undefined,
},
} as unknown as Window;
describe('p2p-runtime', () => {
@@ -40,6 +52,13 @@ describe('p2p-runtime', () => {
expect(isBrowserPureP2PEnabled({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(false);
});
it('forces browser p2p on p2p subdomains even with gateway account options', () => {
const gatewayAccount = { pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } };
expect(isBrowserPureP2PEnabled(gatewayAccount, p2pBrowserWindow)).toBe(true);
expect(shouldShowP2PSettingsSection(gatewayAccount, p2pBrowserWindow)).toBe(true);
});
it('builds browser p2p and gateway account options without a direct pkc-js import', () => {
const account = {
pkcOptions: {