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
@@ -211,6 +211,8 @@ describe('AdvancedSettings', () => {
});
it('saves the browser pure p2p toggle through advanced settings', async () => {
localStorage.setItem('5chan:pure-p2p-browser-enabled', 'false');
await renderSettings(false);
const checkbox = container.querySelector<HTMLInputElement>('input[type="checkbox"]');
@@ -239,29 +241,29 @@ describe('AdvancedSettings', () => {
expect(reloadMock).toHaveBeenCalledOnce();
});
it('forces the browser pure p2p toggle on p2p subdomains', async () => {
it('allows browser pure p2p to be disabled on p2p subdomains', async () => {
localStorage.setItem('5chan:pure-p2p-browser-enabled', 'false');
setTestHostname('p2p.5chan.app');
await renderSettings(false);
const checkbox = container.querySelector<HTMLInputElement>('input[type="checkbox"]');
expect(checkbox?.checked).toBe(true);
expect(checkbox?.disabled).toBe(true);
expect(checkbox?.checked).toBe(false);
expect(checkbox?.disabled).toBe(false);
await clickButton('save_advanced_settings');
expect(testState.setAccountMock).toHaveBeenCalledWith(
expect.objectContaining({
pkcOptions: expect.objectContaining({
ipfsGatewayUrls: undefined,
libp2pJsClientsOptions: [{ key: 'libp2pjs' }],
pkcRpcClientsOptions: undefined,
pubsubKuboRpcClientsOptions: undefined,
ipfsGatewayUrls: ['https://ipfs.old.example'],
libp2pJsClientsOptions: undefined,
pkcRpcClientsOptions: ['ws://old.example/key'],
pubsubKuboRpcClientsOptions: ['https://pubsub.old.example'],
}),
}),
);
expect(localStorage.getItem('5chan:pure-p2p-browser-enabled')).toBe('true');
expect(localStorage.getItem('5chan:pure-p2p-browser-enabled')).toBe('false');
});
it('saves gateway mode defaults when browser pure p2p is disabled', async () => {
@@ -1,7 +1,7 @@
import { memo, RefObject, useRef, useState } from 'react';
import { setAccount, useAccount, usePkcRpcSettings } from '@bitsocial/bitsocial-react-hooks';
import { useTranslation } from 'react-i18next';
import { getBrowserGatewayPkcOptions, getBrowserPureP2PPkcOptions, isPureP2PBrowserForced, setPureP2PBrowserPreference } from '../../../lib/p2p-browser-config';
import { getBrowserGatewayPkcOptions, getBrowserPureP2PPkcOptions, setPureP2PBrowserPreference } from '../../../lib/p2p-browser-config';
import { canConfigureBrowserPureP2P, isBrowserPureP2PEnabled } from '../../../lib/p2p-runtime';
import styles from './advanced-settings.module.css';
@@ -205,18 +205,11 @@ const P2pDataPathSettings = ({ p2pDataPathRef }: SettingsProps) => {
const PureP2PBrowserSettings = ({ pureP2PBrowserRef }: SettingsProps) => {
const { t } = useTranslation();
const account = useAccount() as AccountShape | undefined;
const isForced = isPureP2PBrowserForced();
return (
<div className={styles.pureP2PSettings}>
<label>
<input
className={styles.pureP2PCheckbox}
type='checkbox'
defaultChecked={isForced || isBrowserPureP2PEnabled(account)}
disabled={isForced}
ref={pureP2PBrowserRef}
/>
<input className={styles.pureP2PCheckbox} type='checkbox' defaultChecked={isBrowserPureP2PEnabled(account)} ref={pureP2PBrowserRef} />
{t('enable_pure_p2p')}
</label>
<div className={styles.settingTip}>{t('enable_pure_p2p_tip')}</div>
@@ -261,7 +254,7 @@ const AdvancedSettings = () => {
const pkcRpcClientsOptions = p2pRpcRef.current?.value.trim() ? [p2pRpcRef.current.value.trim()] : undefined;
const dataPath = p2pDataPathRef.current?.value.trim() || undefined;
const pureP2PBrowserPreference = canConfigureBrowserPureP2P() ? isPureP2PBrowserForced() || pureP2PBrowserRef.current?.checked : undefined;
const pureP2PBrowserPreference = canConfigureBrowserPureP2P() ? pureP2PBrowserRef.current?.checked : undefined;
const chainProviders: Record<string, { urls: string[] | undefined; chainId: number }> = {};
if (ethRpcUrls && ethRpcUrls.length > 0) {