feat(p2p): enable pure browser p2p by default

This commit is contained in:
Tommaso Casaburi
2026-05-22 17:31:28 +07:00
parent 99eb49cdc5
commit ca13e97dd4
7 changed files with 55 additions and 65 deletions
+19 -8
View File
@@ -17,13 +17,23 @@ const browserWindow = {
},
} as unknown as Window;
const browserWindowWithDisabledPureP2P = {
electronApi: undefined,
isElectron: false,
location: { hostname: '5chan.app' },
localStorage: {
getItem: () => 'false',
setItem: () => undefined,
},
} as unknown as Window;
const electronWindow = {
electronApi: { isElectron: true },
isElectron: true,
location: { hostname: 'localhost' },
} as unknown as Window;
const p2pBrowserWindow = {
const p2pBrowserWindowWithDisabledPureP2P = {
electronApi: undefined,
isElectron: false,
location: { hostname: 'p2p.5chan.app' },
@@ -46,17 +56,18 @@ describe('p2p-runtime', () => {
expect(getP2PRuntimeMode(account, browserWindow)).toBeNull();
});
it('shows p2p settings in browsers only when pure p2p is enabled or active', () => {
expect(shouldShowP2PSettingsSection(undefined, browserWindow)).toBe(false);
expect(shouldShowP2PSettingsSection({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(false);
expect(isBrowserPureP2PEnabled({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(false);
it('shows p2p settings in browsers when pure p2p is enabled by default', () => {
expect(shouldShowP2PSettingsSection(undefined, browserWindow)).toBe(true);
expect(shouldShowP2PSettingsSection({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(true);
expect(isBrowserPureP2PEnabled({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(true);
});
it('forces browser p2p on p2p subdomains even with gateway account options', () => {
it('allows browser gateway mode when pure p2p is disabled', () => {
const gatewayAccount = { pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } };
expect(isBrowserPureP2PEnabled(gatewayAccount, p2pBrowserWindow)).toBe(true);
expect(shouldShowP2PSettingsSection(gatewayAccount, p2pBrowserWindow)).toBe(true);
expect(isBrowserPureP2PEnabled(gatewayAccount, browserWindowWithDisabledPureP2P)).toBe(false);
expect(shouldShowP2PSettingsSection(gatewayAccount, browserWindowWithDisabledPureP2P)).toBe(false);
expect(isBrowserPureP2PEnabled(gatewayAccount, p2pBrowserWindowWithDisabledPureP2P)).toBe(false);
});
it('builds browser p2p and gateway account options without a direct pkc-js import', () => {