Files
pezkuwi-apps/packages/apps/src/Root.tsx
T
Satoshi Qazi MuhammedandClaude Opus 5.5 f72ba84aac Drop the isElectron flag from the API context
Only the Electron renderer ever set isElectron to true; the web entry passed
false. With that package gone the flag is constant, so remove it from
ApiCtxRoot, the context types and its consumers, together with the
pezkuwi.js.org link base it selected. In-browser account storage and the
WebUSB ledger option now follow the settings alone, as they already did on
the web.

Runtime environment detection (getEnvironment, ExternalWarning) reads the
user agent and is left as is.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-04 04:33:58 +04:00

74 lines
2.4 KiB
TypeScript

// Copyright 2017-2026 @pezkuwi/apps authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ThemeDef } from '@pezkuwi/react-components/types';
import type { KeyringStore } from '@pezkuwi/ui-keyring/types';
import React, { Suspense, useEffect, useState } from 'react';
import { HashRouter } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';
import { ApiCtxRoot } from '@pezkuwi/react-api';
import { ApiStatsCtxRoot, BlockAuthorsCtxRoot, BlockEventsCtxRoot, KeyringCtxRoot, PayWithAssetCtxRoot, QueueCtxRoot, StakingAsyncApisCtxRoot, WindowSizeCtxRoot } from '@pezkuwi/react-hooks';
import { settings } from '@pezkuwi/ui-settings';
import BeforeApiInit from './overlays/BeforeInit.js';
import Apps from './Apps.js';
interface Props {
store?: KeyringStore;
}
function createTheme (settings: { uiTheme?: string }): ThemeDef {
const uiTheme = settings?.uiTheme || 'light';
const theme = uiTheme === 'dark' ? 'dark' : 'light';
document?.documentElement?.setAttribute('data-theme', theme);
return { theme };
}
function Root ({ store }: Props): React.ReactElement<Props> {
const [theme, setTheme] = useState(() => createTheme(settings));
useEffect((): void => {
settings.on('change', (newSettings) => setTheme(createTheme(newSettings)));
}, []);
// The ordering here is critical. It defines the hierarchy of dependencies,
// i.e. Block* depends on Api. Certainly no cross-deps allowed
return (
<Suspense fallback='...'>
<ThemeProvider theme={theme}>
<QueueCtxRoot>
<ApiCtxRoot
apiUrl={settings.apiUrl}
beforeApiInit={<BeforeApiInit />}
store={store}
>
<KeyringCtxRoot>
<ApiStatsCtxRoot>
<BlockAuthorsCtxRoot>
<BlockEventsCtxRoot>
<HashRouter>
<WindowSizeCtxRoot>
<PayWithAssetCtxRoot>
<StakingAsyncApisCtxRoot>
<Apps />
</StakingAsyncApisCtxRoot>
</PayWithAssetCtxRoot>
</WindowSizeCtxRoot>
</HashRouter>
</BlockEventsCtxRoot>
</BlockAuthorsCtxRoot>
</ApiStatsCtxRoot>
</KeyringCtxRoot>
</ApiCtxRoot>
</QueueCtxRoot>
</ThemeProvider>
</Suspense>
);
}
export default React.memo(Root);