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 (
{t('footer.warning_alert_text')}