import React, { useContext, useEffect, useState } from 'react'; import { MemoryRouter, BrowserRouter, Routes, Route } from 'react-router-dom'; import { Box, Slide, Typography, styled } from '@mui/material'; import { type UseAppStoreType, AppContext, closeAll } from '../contexts/AppContext'; import { RobotPage, MakerPage, BookPage, OrderPage, SettingsPage, NavBar, MainDialogs } from './'; import RobotAvatar from '../components/RobotAvatar'; import Notifications from '../components/Notifications'; import { useTranslation } from 'react-i18next'; import { FederationContext, type UseFederationStoreType } from '../contexts/FederationContext'; import { GarageContext, type UseGarageStoreType } from '../contexts/GarageContext'; const Router = window.NativeRobosats === undefined ? BrowserRouter : MemoryRouter; const TestnetTypography = styled(Typography)({ height: 0, }); interface MainBoxProps { navbarHeight: number; } const MainBox = styled(Box)((props) => ({ position: 'absolute', top: '50%', left: '50%', transform: `translate(-50%, -50%) translate(0, -${props.navbarHeight / 2}em)`, })); const Main: React.FC = () => { const { t } = useTranslation(); const { settings, page, slideDirection, setOpen, windowSize, navbarHeight, hostUrl, origin } = useContext(AppContext); const { federation, sortedCoordinators } = useContext(FederationContext); const { garage } = useContext(GarageContext); const [avatarBaseUrl, setAvatarBaseUrl] = useState(hostUrl); useEffect(() => { setAvatarBaseUrl(federation.getCoordinator(sortedCoordinators[0]).getBaseUrl()); }, [settings.network, settings.selfhostedClient, federation, sortedCoordinators]); return ( { garage.updateRobot({ avatarLoaded: true }); }} /> { setOpen({ ...closeAll, profile: true }); }} rewards={garage.getRobot().earnedRewards} windowWidth={windowSize?.width} /> {settings.network === 'testnet' ? ( {t('Using Testnet Bitcoin')} ) : ( <> )} {['/robot/:token?', '/', ''].map((path, index) => { return (
} key={index} /> ); })}
} />
} />
} />
} />
); }; export default Main;