Merge branch 'codex/feature/p2p-stats-settings'

# Conflicts:
#	package.json
#	public/translations/ar/default.json
#	public/translations/bn/default.json
#	public/translations/cs/default.json
#	public/translations/da/default.json
#	public/translations/de/default.json
#	public/translations/el/default.json
#	public/translations/en/default.json
#	public/translations/es/default.json
#	public/translations/fa/default.json
#	public/translations/fi/default.json
#	public/translations/fil/default.json
#	public/translations/fr/default.json
#	public/translations/he/default.json
#	public/translations/hi/default.json
#	public/translations/hu/default.json
#	public/translations/id/default.json
#	public/translations/it/default.json
#	public/translations/ja/default.json
#	public/translations/ko/default.json
#	public/translations/mr/default.json
#	public/translations/nl/default.json
#	public/translations/no/default.json
#	public/translations/pl/default.json
#	public/translations/pt/default.json
#	public/translations/ro/default.json
#	public/translations/ru/default.json
#	public/translations/sq/default.json
#	public/translations/sv/default.json
#	public/translations/te/default.json
#	public/translations/th/default.json
#	public/translations/tr/default.json
#	public/translations/uk/default.json
#	public/translations/ur/default.json
#	public/translations/vi/default.json
#	public/translations/zh/default.json
#	src/components/settings-modal/__tests__/settings-modal.test.tsx
#	src/components/settings-modal/settings-modal.tsx
#	yarn.lock
This commit is contained in:
Tommaso Casaburi
2026-05-07 16:59:44 +07:00
51 changed files with 1452 additions and 227 deletions
+70 -8
View File
@@ -1,6 +1,21 @@
import { describe, expect, it } from 'vitest';
import { configureP2PBrowserPkcOptions, isP2PBrowserHostname, P2P_BROWSER_PKC_OPTIONS } from '../p2p-browser-config';
import {
configureP2PBrowserPkcOptions,
getPureP2PBrowserPreference,
isP2PBrowserHostname,
P2P_BROWSER_PKC_OPTIONS,
PURE_P2P_BROWSER_SETTING_KEY,
setPureP2PBrowserPreference,
shouldUsePureP2PBrowser,
} from '../p2p-browser-config';
const createStorage = (values: Record<string, string | undefined> = {}) => ({
getItem: (key: string) => values[key] ?? null,
setItem: (key: string, value: string) => {
values[key] = value;
},
});
describe('p2p-browser-config', () => {
it('detects p2p subdomains', () => {
@@ -10,31 +25,78 @@ describe('p2p-browser-config', () => {
expect(isP2PBrowserHostname('www.p2p.5chan.app')).toBe(false);
});
it('configures browser PKC options for p2p hostnames', () => {
it('leaves browser PKC options untouched by default', () => {
const targetWindow = {
location: { hostname: 'p2p.5chan.app' },
location: { hostname: '5chan.app' },
localStorage: createStorage(),
defaultPkcOptions: {
ipfsGatewayUrls: ['https://gateway.example'],
},
};
expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(false);
expect(targetWindow.defaultPkcOptions).toEqual({
ipfsGatewayUrls: ['https://gateway.example'],
});
});
it('configures browser PKC options when pure p2p is enabled', () => {
const targetWindow = {
location: { hostname: '5chan.app' },
localStorage: createStorage({ [PURE_P2P_BROWSER_SETTING_KEY]: 'true' }),
defaultPkcOptions: {
ipfsGatewayUrls: ['https://gateway.example'],
},
};
expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(true);
expect(targetWindow.defaultPkcOptions).toEqual({
ipfsGatewayUrls: ['https://gateway.example'],
...P2P_BROWSER_PKC_OPTIONS,
});
expect(targetWindow.defaultPkcOptions).toEqual(P2P_BROWSER_PKC_OPTIONS);
});
it('leaves normal hostnames untouched', () => {
it('leaves browser PKC options untouched when pure p2p is disabled', () => {
const defaultPkcOptions = {
ipfsGatewayUrls: ['https://gateway.example'],
};
const targetWindow = {
location: { hostname: '5chan.app' },
localStorage: createStorage({ [PURE_P2P_BROWSER_SETTING_KEY]: 'false' }),
defaultPkcOptions,
};
expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(false);
expect(targetWindow.defaultPkcOptions).toBe(defaultPkcOptions);
});
it('leaves electron defaults untouched', () => {
const defaultPkcOptions = {
pkcRpcClientsOptions: ['ws://localhost:9138'],
};
const targetWindow = {
electronApi: { isElectron: true },
location: { hostname: 'localhost' },
localStorage: createStorage(),
defaultPkcOptions,
};
expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(false);
expect(targetWindow.defaultPkcOptions).toBe(defaultPkcOptions);
});
it('persists and reads the browser pure p2p preference', () => {
const targetWindow = {
location: { hostname: '5chan.app' },
localStorage: createStorage(),
};
expect(getPureP2PBrowserPreference(targetWindow)).toBeUndefined();
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(false);
setPureP2PBrowserPreference(false, targetWindow);
expect(getPureP2PBrowserPreference(targetWindow)).toBe(false);
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(false);
setPureP2PBrowserPreference(true, targetWindow);
expect(getPureP2PBrowserPreference(targetWindow)).toBe(true);
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(true);
});
});
+63
View File
@@ -0,0 +1,63 @@
import { describe, expect, it } from 'vitest';
import {
getBrowserGatewayAccountOptions,
getBrowserPureP2PAccountOptions,
getP2PRuntimeMode,
isBrowserPureP2PEnabled,
shouldShowP2PSettingsSection,
} from '../p2p-runtime';
const browserWindow = {
electronApi: undefined,
isElectron: false,
localStorage: {
getItem: () => null,
setItem: () => undefined,
},
} as unknown as Window;
const electronWindow = {
electronApi: { isElectron: true },
isElectron: true,
} as unknown as Window;
describe('p2p-runtime', () => {
it('detects browser libp2p accounts from options and live clients', () => {
expect(getP2PRuntimeMode({ pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }] } }, browserWindow)).toBe('browser-libp2p');
expect(getP2PRuntimeMode({ pkc: { clients: { libp2pJsClients: { libp2pjs: {} } } } }, browserWindow)).toBe('browser-libp2p');
});
it('detects electron Kubo RPC accounts only in electron runtime', () => {
const account = { pkcOptions: { pkcRpcClientsOptions: ['ws://localhost:9138'] } };
expect(getP2PRuntimeMode(account, electronWindow)).toBe('electron-kubo-rpc');
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('builds browser p2p and gateway account options without a direct pkc-js import', () => {
const account = {
pkcOptions: {
httpRoutersOptions: ['https://custom-router.example'],
ipfsGatewayUrls: ['https://gateway.example'],
pkcRpcClientsOptions: ['ws://remote.example'],
},
};
expect(getBrowserPureP2PAccountOptions(account)).toMatchObject({
libp2pJsClientsOptions: [{ key: 'libp2pjs' }],
ipfsGatewayUrls: undefined,
pkcRpcClientsOptions: undefined,
});
expect(getBrowserGatewayAccountOptions(account)).toMatchObject({
ipfsGatewayUrls: ['https://ipfsgateway.xyz', 'https://gateway.plebpubsub.xyz', 'https://gateway.forumindex.com'],
libp2pJsClientsOptions: undefined,
pkcRpcClientsOptions: undefined,
});
});
});