From fb004469e39ffba7d0a98679da710fc41c9355cd Mon Sep 17 00:00:00 2001 From: Tommaso Casaburi Date: Thu, 25 Jun 2026 18:36:37 +0700 Subject: [PATCH] feat(p2p): enable pure browser p2p by default --- .../__tests__/advanced-settings.test.tsx | 8 ++++---- .../use-browser-pure-p2p-account-upgrade.test.tsx | 6 +++--- src/lib/__tests__/p2p-browser-config.test.ts | 14 ++++++++------ src/lib/__tests__/p2p-runtime.test.ts | 10 +++++----- src/lib/p2p-browser-config.ts | 2 +- src/views/rules/__tests__/rules.test.tsx | 4 ++-- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/components/settings-modal/advanced-settings/__tests__/advanced-settings.test.tsx b/src/components/settings-modal/advanced-settings/__tests__/advanced-settings.test.tsx index 4dc00cd4..b6074f21 100644 --- a/src/components/settings-modal/advanced-settings/__tests__/advanced-settings.test.tsx +++ b/src/components/settings-modal/advanced-settings/__tests__/advanced-settings.test.tsx @@ -204,15 +204,15 @@ describe('AdvancedSettings', () => { expect(textInputs[2]?.value).toBe('/tmp/connected-node'); }); - it('shows pure p2p browser mode unchecked by default', async () => { + it('shows pure p2p browser mode checked by default', async () => { await renderSettings(false); - expect(container.textContent).toContain('advanced_ipfs_gateways'); - expect(container.textContent).toContain('advanced_pubsub_providers'); + expect(container.textContent).not.toContain('advanced_ipfs_gateways'); + expect(container.textContent).not.toContain('advanced_pubsub_providers'); expect(container.textContent).toContain('advanced_http_routers'); expect(container.textContent).toContain('advanced_full_node_websocket_rpc'); const checkbox = container.querySelector('input[type="checkbox"]'); - expect(checkbox?.checked).toBe(false); + expect(checkbox?.checked).toBe(true); const nodeRpcInput = Array.from(container.querySelectorAll('input[type="text"]')).find( (input) => input.placeholder === 'advanced_p2p_rpc_placeholder', diff --git a/src/hooks/__tests__/use-browser-pure-p2p-account-upgrade.test.tsx b/src/hooks/__tests__/use-browser-pure-p2p-account-upgrade.test.tsx index 4f977c44..cba89ece 100644 --- a/src/hooks/__tests__/use-browser-pure-p2p-account-upgrade.test.tsx +++ b/src/hooks/__tests__/use-browser-pure-p2p-account-upgrade.test.tsx @@ -86,7 +86,8 @@ describe('useBrowserPureP2PAccountUpgrade', () => { window.isElectron = false; }); - it('does not upgrade stale gateway browser accounts when pure p2p is disabled by default', async () => { + it('does not upgrade stale gateway browser accounts when pure p2p is explicitly disabled', async () => { + localStorage.setItem('5chan:pure-p2p-browser-enabled', 'false'); testState.account = { id: 'account-1', name: 'Account 1', @@ -104,8 +105,7 @@ describe('useBrowserPureP2PAccountUpgrade', () => { expect(reloadMock).not.toHaveBeenCalled(); }); - it('upgrades stale gateway browser accounts when pure p2p is enabled and reloads after saving', async () => { - localStorage.setItem('5chan:pure-p2p-browser-enabled', 'true'); + it('upgrades stale gateway browser accounts by default and reloads after saving', async () => { testState.account = { id: 'account-1', name: 'Account 1', diff --git a/src/lib/__tests__/p2p-browser-config.test.ts b/src/lib/__tests__/p2p-browser-config.test.ts index 4d67b858..65dbb7db 100644 --- a/src/lib/__tests__/p2p-browser-config.test.ts +++ b/src/lib/__tests__/p2p-browser-config.test.ts @@ -20,7 +20,7 @@ const createStorage = (values: Record = {}) => ({ describe('p2p-browser-config', () => { const defaultHttpRouters = DEFAULT_HTTP_ROUTER_URLS; - it('configures browser PKC options for gateway mode by default', () => { + it('configures browser PKC options for pure p2p mode by default', () => { const chainProviders = { eth: { urls: ['https://eth.example'], chainId: 1 }, }; @@ -33,12 +33,14 @@ describe('p2p-browser-config', () => { }, }; - expect(shouldUsePureP2PBrowser(targetWindow)).toBe(false); - expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(false); - expect(targetWindow.defaultPkcOptions).toEqual({ + expect(shouldUsePureP2PBrowser(targetWindow)).toBe(true); + expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(true); + expect(targetWindow.defaultPkcOptions).toMatchObject({ chainProviders, - ...getBrowserGatewayPkcOptions(), httpRoutersOptions: defaultHttpRouters, + ipfsGatewayUrls: undefined, + libp2pJsClientsOptions: [{ key: 'libp2pjs' }], + pubsubKuboRpcClientsOptions: undefined, }); }); @@ -105,7 +107,7 @@ describe('p2p-browser-config', () => { }; expect(getPureP2PBrowserPreference(targetWindow)).toBeUndefined(); - expect(shouldUsePureP2PBrowser(targetWindow)).toBe(false); + expect(shouldUsePureP2PBrowser(targetWindow)).toBe(true); setPureP2PBrowserPreference(false, targetWindow); expect(getPureP2PBrowserPreference(targetWindow)).toBe(false); diff --git a/src/lib/__tests__/p2p-runtime.test.ts b/src/lib/__tests__/p2p-runtime.test.ts index 88b30de1..0ed5c5d9 100644 --- a/src/lib/__tests__/p2p-runtime.test.ts +++ b/src/lib/__tests__/p2p-runtime.test.ts @@ -67,10 +67,10 @@ describe('p2p-runtime', () => { expect(getP2PRuntimeMode(account, browserWindow)).toBe('full-node-rpc'); }); - it('keeps browser pure p2p off by default while honoring explicit preference and active libp2p accounts', () => { - 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('keeps browser pure p2p on by default while honoring explicit preference and active libp2p accounts', () => { + 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); expect(shouldShowP2PSettingsSection({ pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }] } }, browserWindow)).toBe(true); expect(isBrowserPureP2PEnabled({ pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }] } }, browserWindow)).toBe(true); expect(shouldShowP2PSettingsSection({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindowWithEnabledPureP2P)).toBe(true); @@ -98,7 +98,7 @@ describe('p2p-runtime', () => { const mixedBrowserAccount = { pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }], pubsubKuboRpcClientsOptions: ['https://pubsub.example/api/v0'] } }; const fullNodeAccount = { pkcOptions: { pkcRpcClientsOptions: ['ws://node.example'] } }; - expect(shouldUpgradeBrowserPureP2PAccount(gatewayAccount, browserWindow)).toBe(false); + expect(shouldUpgradeBrowserPureP2PAccount(gatewayAccount, browserWindow)).toBe(true); expect(shouldUpgradeBrowserPureP2PAccount(gatewayAccount, browserWindowWithEnabledPureP2P)).toBe(true); expect(shouldUpgradeBrowserPureP2PAccount(browserAccount, browserWindow)).toBe(false); expect(shouldUpgradeBrowserPureP2PAccount(mixedBrowserAccount, browserWindow)).toBe(true); diff --git a/src/lib/p2p-browser-config.ts b/src/lib/p2p-browser-config.ts index 295760c4..2a7a1389 100644 --- a/src/lib/p2p-browser-config.ts +++ b/src/lib/p2p-browser-config.ts @@ -1,5 +1,5 @@ export const PURE_P2P_BROWSER_SETTING_KEY = '5chan:pure-p2p-browser-enabled'; -export const BROWSER_PURE_P2P_DEFAULT_ENABLED = false; +export const BROWSER_PURE_P2P_DEFAULT_ENABLED = true; const BROWSER_PUBSUB_KUBO_RPC_CLIENTS_OPTIONS = ['https://pubsubprovider.xyz/api/v0', 'https://plebpubsub.xyz/api/v0', 'https://rannithepleb.com/api/v0']; // Keep this aligned with bitsocial-react-hooks' DEFAULT_HTTP_ROUTER_URLS without relying on a package-internal runtime import before window.defaultPkcOptions is configured. diff --git a/src/views/rules/__tests__/rules.test.tsx b/src/views/rules/__tests__/rules.test.tsx index 84460a23..19bafddd 100644 --- a/src/views/rules/__tests__/rules.test.tsx +++ b/src/views/rules/__tests__/rules.test.tsx @@ -227,7 +227,7 @@ describe('Rules', () => { expect(scrollIntoViewMock).toHaveBeenCalled(); }); - it('shows a friendly loading state string while a board is downloading via IPFS', async () => { + it('shows a friendly loading state string while a board is downloading from peers', async () => { testState.communities = { 'custom-board.eth': { state: 'fetching-ipns', @@ -237,7 +237,7 @@ describe('Rules', () => { await renderRules(); await submitBoardAddress('custom-board.eth'); - expect(container.textContent).toContain('Downloading board via IPFS'); + expect(container.textContent).toContain('Downloading board from peers'); expect(container.textContent).not.toContain('loading...'); });