import React, { useState, useEffect, useCallback, useMemo } from 'react' import { Route, Routes, Navigate } from 'react-router-dom' import * as rb from 'react-bootstrap' import { Trans, useTranslation } from 'react-i18next' import Wallets from './Wallets' import CreateWallet from './CreateWallet' import Jam from './Jam' import Send from './Send' import Earn from './Earn' import Receive from './Receive' import CurrentWalletMagic from './CurrentWalletMagic' import CurrentWalletAdvanced from './CurrentWalletAdvanced' import FidelityBond from './FidelityBond' import Settings from './Settings' import Navbar from './Navbar' import Layout from './Layout' import Sprite from './Sprite' import { useSettings, useSettingsDispatch } from '../context/SettingsContext' import { useWebsocketState } from '../context/WebsocketContext' import { useCurrentWallet, useSetCurrentWallet } from '../context/WalletContext' import { useSessionConnectionError } from '../context/ServiceInfoContext' import { setSession, clearSession } from '../session' import Onboarding from './Onboarding' import Cheatsheet from './Cheatsheet' import { routes } from '../constants/routes' import packageInfo from '../../package.json' export default function App() { const { t } = useTranslation() const settings = useSettings() const settingsDispatch = useSettingsDispatch() const websocketState = useWebsocketState() const currentWallet = useCurrentWallet() const setCurrentWallet = useSetCurrentWallet() const sessionConnectionError = useSessionConnectionError() const [websocketConnected, setWebsocketConnected] = useState() const [showBetaWarning, setShowBetaWarning] = useState(false) const [showCheatsheet, setShowCheatsheet] = useState(false) const cheatsheetEnabled = useMemo(() => !!currentWallet, [currentWallet]) const startWallet = useCallback( (name, token) => { setSession({ name, token }) setCurrentWallet({ name, token }) }, [setCurrentWallet] ) const stopWallet = useCallback(() => { clearSession() setCurrentWallet(null) }, [setCurrentWallet]) // update the connection indicator based on the websocket connection state useEffect(() => { setWebsocketConnected(websocketState === WebSocket.OPEN) }, [websocketState]) useEffect(() => { let timer // show the cheatsheet once after the first wallet has been created if (cheatsheetEnabled && settings.showCheatsheet) { timer = setTimeout(() => { setShowCheatsheet(true) settingsDispatch({ showCheatsheet: false }) }, 1_000) } return () => clearTimeout(timer) }, [cheatsheetEnabled, settings, settingsDispatch]) if (settings.showOnboarding === true) { return ( ) } return ( <> {showBetaWarning && (
{t('footer.warning_alert_title')}

{t('footer.warning_alert_text')}

setShowBetaWarning(false)}> {t('footer.warning_alert_button_ok')}
)} {sessionConnectionError && ( {t('app.alert_no_connection', { connectionError: sessionConnectionError.message })}. )} {/** * This sections defines all routes that can be displayed, even if the connection * to the backend is down, e.g. "create-wallet" shows the seed quiz and it is important * that it stays visible in case the backend becomes unavailable. */} }> } /> {/** * This section defines all routes that are displayed only if the backend is reachable. */} {!sessionConnectionError && ( <> }> } /> {currentWallet && ( <> } /> } /> } /> } /> } /> } /> )} {currentWallet && !settings.useAdvancedWalletMode && ( }> } /> )} {currentWallet && settings.useAdvancedWalletMode && ( }> } /> )} } /> )}
This is pre-alpha software. setShowBetaWarning(true)} > Read this before using.
{cheatsheetEnabled && (
setShowCheatsheet(false)} /> setShowCheatsheet(true)} >
{t('footer.cheatsheet')}
)}
{' '} v{packageInfo.version}
|
( {websocketConnected ? t('footer.connected') : t('footer.disconnected')} )} >
) }