2023-12-02 20:19:23 +00:00
|
|
|
import React, { useContext } from 'react';
|
2024-05-25 17:33:07 +00:00
|
|
|
import { MemoryRouter,HashRouter ,BrowserRouter, Routes, Route } from 'react-router-dom';
|
2023-04-23 19:03:38 +00:00
|
|
|
import { Box, Slide, Typography, styled } from '@mui/material';
|
2023-10-27 10:01:59 +00:00
|
|
|
import { type UseAppStoreType, AppContext, closeAll } from '../contexts/AppContext';
|
2022-10-20 18:06:16 +00:00
|
|
|
|
2023-10-27 10:01:59 +00:00
|
|
|
import { RobotPage, MakerPage, BookPage, OrderPage, SettingsPage, NavBar, MainDialogs } from './';
|
2022-10-30 19:13:01 +00:00
|
|
|
import RobotAvatar from '../components/RobotAvatar';
|
2023-10-27 10:01:59 +00:00
|
|
|
import Notifications from '../components/Notifications';
|
2022-10-20 18:06:16 +00:00
|
|
|
|
2022-11-07 16:45:05 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-10-27 11:00:53 +00:00
|
|
|
import { GarageContext, type UseGarageStoreType } from '../contexts/GarageContext';
|
2022-10-22 14:32:33 +00:00
|
|
|
|
2024-05-25 17:33:07 +00:00
|
|
|
//const Router = window.NativeRobosats === undefined ? BrowserRouter : MemoryRouter;
|
|
|
|
|
|
|
|
const Router = (window.NativeRobosats === undefined && window.DesktopRobosats === undefined)? BrowserRouter : window.DesktopRobosats === 'Desktop-App' ? HashRouter : MemoryRouter;
|
2023-04-16 18:10:48 +00:00
|
|
|
|
2023-04-23 19:03:38 +00:00
|
|
|
const TestnetTypography = styled(Typography)({
|
|
|
|
height: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
interface MainBoxProps {
|
|
|
|
navbarHeight: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MainBox = styled(Box)<MainBoxProps>((props) => ({
|
|
|
|
position: 'absolute',
|
|
|
|
top: '50%',
|
|
|
|
left: '50%',
|
|
|
|
transform: `translate(-50%, -50%) translate(0, -${props.navbarHeight / 2}em)`,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const Main: React.FC = () => {
|
2022-11-07 16:45:05 +00:00
|
|
|
const { t } = useTranslation();
|
2023-12-02 20:19:23 +00:00
|
|
|
const { settings, page, slideDirection, setOpen, windowSize, navbarHeight } =
|
2023-10-27 10:01:59 +00:00
|
|
|
useContext<UseAppStoreType>(AppContext);
|
|
|
|
const { garage } = useContext<UseGarageStoreType>(GarageContext);
|
2022-10-30 19:13:01 +00:00
|
|
|
|
2022-10-20 18:06:16 +00:00
|
|
|
return (
|
2023-04-16 18:10:48 +00:00
|
|
|
<Router>
|
2023-12-15 15:17:46 +00:00
|
|
|
<RobotAvatar style={{ display: 'none' }} hashId={garage.getSlot()?.hashId} />
|
2022-11-21 12:56:29 +00:00
|
|
|
<Notifications
|
|
|
|
page={page}
|
2023-05-09 00:37:23 +00:00
|
|
|
openProfile={() => {
|
|
|
|
setOpen({ ...closeAll, profile: true });
|
|
|
|
}}
|
2023-11-21 17:36:59 +00:00
|
|
|
rewards={garage.getSlot()?.getRobot()?.earnedRewards}
|
2023-10-27 10:01:59 +00:00
|
|
|
windowWidth={windowSize?.width}
|
2022-11-21 12:56:29 +00:00
|
|
|
/>
|
2022-11-07 16:45:05 +00:00
|
|
|
{settings.network === 'testnet' ? (
|
2023-04-23 19:03:38 +00:00
|
|
|
<TestnetTypography color='secondary' align='center'>
|
|
|
|
<i>{t('Using Testnet Bitcoin')}</i>
|
|
|
|
</TestnetTypography>
|
2022-11-07 16:45:05 +00:00
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)}
|
|
|
|
|
2023-04-23 19:03:38 +00:00
|
|
|
<MainBox navbarHeight={navbarHeight}>
|
2023-04-16 18:10:48 +00:00
|
|
|
<Routes>
|
2023-05-05 10:12:38 +00:00
|
|
|
{['/robot/:token?', '/', ''].map((path, index) => {
|
2023-04-16 18:10:48 +00:00
|
|
|
return (
|
|
|
|
<Route
|
|
|
|
path={path}
|
|
|
|
element={
|
|
|
|
<Slide
|
|
|
|
direction={page === 'robot' ? slideDirection.in : slideDirection.out}
|
|
|
|
in={page === 'robot'}
|
2023-10-27 10:01:59 +00:00
|
|
|
appear={slideDirection.in !== undefined}
|
2023-04-16 18:10:48 +00:00
|
|
|
>
|
|
|
|
<div>
|
2023-12-02 12:12:52 +00:00
|
|
|
<RobotPage />
|
2023-04-16 18:10:48 +00:00
|
|
|
</div>
|
|
|
|
</Slide>
|
|
|
|
}
|
|
|
|
key={index}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
|
2022-10-20 18:06:16 +00:00
|
|
|
<Route
|
2023-04-16 18:10:48 +00:00
|
|
|
path={'/offers'}
|
|
|
|
element={
|
2022-10-30 19:13:01 +00:00
|
|
|
<Slide
|
2023-04-16 18:10:48 +00:00
|
|
|
direction={page === 'offers' ? slideDirection.in : slideDirection.out}
|
|
|
|
in={page === 'offers'}
|
2023-10-27 10:01:59 +00:00
|
|
|
appear={slideDirection.in !== undefined}
|
2022-10-30 19:13:01 +00:00
|
|
|
>
|
|
|
|
<div>
|
2023-04-16 18:10:48 +00:00
|
|
|
<BookPage />
|
2022-10-30 19:13:01 +00:00
|
|
|
</div>
|
|
|
|
</Slide>
|
2023-04-16 18:10:48 +00:00
|
|
|
}
|
2022-10-20 18:06:16 +00:00
|
|
|
/>
|
2022-10-30 19:13:01 +00:00
|
|
|
|
2023-04-16 18:10:48 +00:00
|
|
|
<Route
|
|
|
|
path='/create'
|
|
|
|
element={
|
|
|
|
<Slide
|
|
|
|
direction={page === 'create' ? slideDirection.in : slideDirection.out}
|
|
|
|
in={page === 'create'}
|
2023-10-27 10:01:59 +00:00
|
|
|
appear={slideDirection.in !== undefined}
|
2023-04-16 18:10:48 +00:00
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<MakerPage />
|
|
|
|
</div>
|
|
|
|
</Slide>
|
|
|
|
}
|
|
|
|
/>
|
2022-10-30 19:13:01 +00:00
|
|
|
|
2022-10-20 18:06:16 +00:00
|
|
|
<Route
|
2023-10-27 10:01:59 +00:00
|
|
|
path='/order/:shortAlias/:orderId'
|
2023-04-16 18:10:48 +00:00
|
|
|
element={
|
2022-10-30 19:13:01 +00:00
|
|
|
<Slide
|
|
|
|
direction={page === 'order' ? slideDirection.in : slideDirection.out}
|
|
|
|
in={page === 'order'}
|
2023-10-27 10:01:59 +00:00
|
|
|
appear={slideDirection.in !== undefined}
|
2022-10-30 19:13:01 +00:00
|
|
|
>
|
|
|
|
<div>
|
2023-04-16 18:10:48 +00:00
|
|
|
<OrderPage />
|
2022-10-30 19:13:01 +00:00
|
|
|
</div>
|
|
|
|
</Slide>
|
2023-04-16 18:10:48 +00:00
|
|
|
}
|
2022-10-20 18:06:16 +00:00
|
|
|
/>
|
2022-10-30 19:13:01 +00:00
|
|
|
|
2023-04-16 18:10:48 +00:00
|
|
|
<Route
|
|
|
|
path='/settings'
|
|
|
|
element={
|
|
|
|
<Slide
|
|
|
|
direction={page === 'settings' ? slideDirection.in : slideDirection.out}
|
|
|
|
in={page === 'settings'}
|
2023-10-27 10:01:59 +00:00
|
|
|
appear={slideDirection.in !== undefined}
|
2023-04-16 18:10:48 +00:00
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<SettingsPage />
|
|
|
|
</div>
|
|
|
|
</Slide>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Routes>
|
2023-04-23 19:03:38 +00:00
|
|
|
</MainBox>
|
2023-10-27 10:01:59 +00:00
|
|
|
<NavBar />
|
2023-03-02 11:01:06 +00:00
|
|
|
<MainDialogs />
|
2022-10-20 18:06:16 +00:00
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Main;
|