2023-02-24 19:17:13 +00:00
|
|
|
import React, { useContext } from 'react';
|
2022-11-21 12:56:29 +00:00
|
|
|
import { HashRouter, BrowserRouter, Switch, Route } from 'react-router-dom';
|
2023-02-24 19:17:13 +00:00
|
|
|
import { Box, Slide, Typography } from '@mui/material';
|
2022-10-20 18:06:16 +00:00
|
|
|
|
2023-02-21 17:22:48 +00:00
|
|
|
import RobotPage from './RobotPage';
|
2022-10-20 18:06:16 +00:00
|
|
|
import MakerPage from './MakerPage';
|
|
|
|
import BookPage from './BookPage';
|
|
|
|
import OrderPage from './OrderPage';
|
2022-10-30 19:13:01 +00:00
|
|
|
import SettingsPage from './SettingsPage';
|
2023-02-24 19:17:13 +00:00
|
|
|
import NavBar from './NavBar';
|
|
|
|
import MainDialogs from './MainDialogs';
|
2022-10-20 18:06:16 +00:00
|
|
|
|
2022-10-30 19:13:01 +00:00
|
|
|
import RobotAvatar from '../components/RobotAvatar';
|
2022-10-20 18:06:16 +00:00
|
|
|
|
2022-11-07 16:45:05 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2022-11-21 12:56:29 +00:00
|
|
|
import Notifications from '../components/Notifications';
|
2023-02-24 19:17:13 +00:00
|
|
|
import { AppContextProps, AppContext } from '../contexts/AppContext';
|
2022-10-22 14:32:33 +00:00
|
|
|
|
2023-02-24 19:17:13 +00:00
|
|
|
const Main = (): JSX.Element => {
|
2022-11-07 16:45:05 +00:00
|
|
|
const { t } = useTranslation();
|
2023-02-24 19:17:13 +00:00
|
|
|
const {
|
|
|
|
book,
|
|
|
|
fetchBook,
|
|
|
|
maker,
|
|
|
|
setMaker,
|
|
|
|
clearOrder,
|
|
|
|
torStatus,
|
|
|
|
settings,
|
|
|
|
limits,
|
|
|
|
fetchLimits,
|
|
|
|
robot,
|
|
|
|
setRobot,
|
|
|
|
fetchRobot,
|
|
|
|
setOrder,
|
|
|
|
setDelay,
|
|
|
|
info,
|
|
|
|
fav,
|
|
|
|
setFav,
|
|
|
|
baseUrl,
|
|
|
|
order,
|
|
|
|
page,
|
|
|
|
setPage,
|
|
|
|
slideDirection,
|
|
|
|
setSlideDirection,
|
|
|
|
currentOrder,
|
|
|
|
setCurrentOrder,
|
|
|
|
closeAll,
|
|
|
|
open,
|
|
|
|
setOpen,
|
|
|
|
windowSize,
|
|
|
|
badOrder,
|
|
|
|
navbarHeight,
|
|
|
|
setBadOrder,
|
|
|
|
} = useContext<AppContextProps>(AppContext);
|
2022-10-30 19:13:01 +00:00
|
|
|
|
2022-10-31 16:20:20 +00:00
|
|
|
const Router = window.NativeRobosats === undefined ? BrowserRouter : HashRouter;
|
|
|
|
const basename = window.NativeRobosats === undefined ? '' : window.location.pathname;
|
2022-11-21 12:56:29 +00:00
|
|
|
|
2022-10-20 18:06:16 +00:00
|
|
|
return (
|
|
|
|
<Router basename={basename}>
|
2022-10-30 19:13:01 +00:00
|
|
|
<RobotAvatar
|
|
|
|
style={{ display: 'none' }}
|
|
|
|
nickname={robot.nickname}
|
2022-11-07 16:45:05 +00:00
|
|
|
baseUrl={baseUrl}
|
2022-10-30 19:13:01 +00:00
|
|
|
onLoad={() => setRobot({ ...robot, avatarLoaded: true })}
|
|
|
|
/>
|
2022-11-21 12:56:29 +00:00
|
|
|
<Notifications
|
|
|
|
order={order}
|
|
|
|
page={page}
|
|
|
|
openProfile={() => setOpen({ ...closeAll, profile: true })}
|
|
|
|
rewards={robot.earnedRewards}
|
|
|
|
setPage={setPage}
|
|
|
|
windowWidth={windowSize.width}
|
|
|
|
/>
|
2022-11-07 16:45:05 +00:00
|
|
|
{settings.network === 'testnet' ? (
|
|
|
|
<div style={{ height: 0 }}>
|
|
|
|
<Typography color='secondary' align='center'>
|
|
|
|
<i>{t('Using Testnet Bitcoin')}</i>
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)}
|
|
|
|
|
2022-10-30 19:13:01 +00:00
|
|
|
<Box
|
|
|
|
style={{
|
|
|
|
position: 'absolute',
|
|
|
|
top: '50%',
|
|
|
|
left: '50%',
|
|
|
|
transform: `translate(-50%, -50%) translate(0, -${navbarHeight / 2}em`,
|
|
|
|
}}
|
|
|
|
>
|
2022-10-20 18:06:16 +00:00
|
|
|
<Switch>
|
|
|
|
<Route
|
2022-10-31 18:03:34 +00:00
|
|
|
path={['/robot/:refCode?', '/']}
|
|
|
|
exact
|
2022-10-20 18:06:16 +00:00
|
|
|
render={(props: any) => (
|
2022-10-30 19:13:01 +00:00
|
|
|
<Slide
|
|
|
|
direction={page === 'robot' ? slideDirection.in : slideDirection.out}
|
|
|
|
in={page === 'robot'}
|
|
|
|
appear={slideDirection.in != undefined}
|
|
|
|
>
|
|
|
|
<div>
|
2023-02-21 17:22:48 +00:00
|
|
|
<RobotPage
|
2022-10-30 19:13:01 +00:00
|
|
|
setPage={setPage}
|
2023-02-21 17:22:48 +00:00
|
|
|
torStatus={torStatus}
|
2023-02-24 19:17:13 +00:00
|
|
|
fetchRobot={fetchRobot}
|
2022-11-07 10:13:02 +00:00
|
|
|
setCurrentOrder={setCurrentOrder}
|
2023-02-21 17:22:48 +00:00
|
|
|
windowSize={windowSize}
|
2022-10-30 19:13:01 +00:00
|
|
|
robot={robot}
|
|
|
|
setRobot={setRobot}
|
2022-11-07 16:45:05 +00:00
|
|
|
baseUrl={baseUrl}
|
2022-10-30 19:13:01 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Slide>
|
2022-10-20 18:06:16 +00:00
|
|
|
)}
|
|
|
|
/>
|
2022-10-30 19:13:01 +00:00
|
|
|
|
2022-10-31 18:03:34 +00:00
|
|
|
<Route path={'/offers'}>
|
2022-10-30 19:13:01 +00:00
|
|
|
<Slide
|
|
|
|
direction={page === 'offers' ? slideDirection.in : slideDirection.out}
|
|
|
|
in={page === 'offers'}
|
|
|
|
appear={slideDirection.in != undefined}
|
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<BookPage
|
|
|
|
book={book}
|
|
|
|
fetchBook={fetchBook}
|
2022-11-21 12:56:29 +00:00
|
|
|
onViewOrder={() => {
|
|
|
|
setOrder(undefined);
|
|
|
|
setDelay(10000);
|
|
|
|
}}
|
2022-10-30 19:13:01 +00:00
|
|
|
limits={limits}
|
|
|
|
fetchLimits={fetchLimits}
|
|
|
|
fav={fav}
|
|
|
|
setFav={setFav}
|
|
|
|
maker={maker}
|
|
|
|
setMaker={setMaker}
|
2022-11-21 12:56:29 +00:00
|
|
|
clearOrder={clearOrder}
|
2022-10-30 19:13:01 +00:00
|
|
|
lastDayPremium={info.last_day_nonkyc_btc_premium}
|
|
|
|
windowSize={windowSize}
|
|
|
|
hasRobot={robot.avatarLoaded}
|
|
|
|
setPage={setPage}
|
2022-11-07 10:13:02 +00:00
|
|
|
setCurrentOrder={setCurrentOrder}
|
2022-11-07 16:45:05 +00:00
|
|
|
baseUrl={baseUrl}
|
2022-10-30 19:13:01 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Slide>
|
|
|
|
</Route>
|
|
|
|
|
|
|
|
<Route path='/create'>
|
|
|
|
<Slide
|
|
|
|
direction={page === 'create' ? slideDirection.in : slideDirection.out}
|
|
|
|
in={page === 'create'}
|
|
|
|
appear={slideDirection.in != undefined}
|
|
|
|
>
|
|
|
|
<div>
|
2023-02-24 19:17:13 +00:00
|
|
|
<MakerPage hasRobot={robot.avatarLoaded} />
|
2022-10-30 19:13:01 +00:00
|
|
|
</div>
|
|
|
|
</Slide>
|
|
|
|
</Route>
|
|
|
|
|
2022-10-20 18:06:16 +00:00
|
|
|
<Route
|
2022-10-30 19:13:01 +00:00
|
|
|
path='/order/:orderId'
|
2022-10-20 18:06:16 +00:00
|
|
|
render={(props: any) => (
|
2022-10-30 19:13:01 +00:00
|
|
|
<Slide
|
|
|
|
direction={page === 'order' ? slideDirection.in : slideDirection.out}
|
|
|
|
in={page === 'order'}
|
|
|
|
appear={slideDirection.in != undefined}
|
|
|
|
>
|
|
|
|
<div>
|
2022-11-15 16:38:31 +00:00
|
|
|
<OrderPage
|
2022-11-21 12:56:29 +00:00
|
|
|
locationOrderId={props.match.params.orderId}
|
|
|
|
hasRobot={robot.avatarLoaded}
|
2022-11-15 16:38:31 +00:00
|
|
|
/>
|
2022-10-30 19:13:01 +00:00
|
|
|
</div>
|
|
|
|
</Slide>
|
2022-10-20 18:06:16 +00:00
|
|
|
)}
|
|
|
|
/>
|
2022-10-30 19:13:01 +00:00
|
|
|
|
|
|
|
<Route path='/settings'>
|
|
|
|
<Slide
|
|
|
|
direction={page === 'settings' ? slideDirection.in : slideDirection.out}
|
|
|
|
in={page === 'settings'}
|
|
|
|
appear={slideDirection.in != undefined}
|
|
|
|
>
|
|
|
|
<div>
|
2023-02-24 19:17:13 +00:00
|
|
|
<SettingsPage />
|
2022-10-30 19:13:01 +00:00
|
|
|
</div>
|
|
|
|
</Slide>
|
|
|
|
</Route>
|
2022-10-20 18:06:16 +00:00
|
|
|
</Switch>
|
2022-10-30 19:13:01 +00:00
|
|
|
</Box>
|
2022-11-21 12:56:29 +00:00
|
|
|
<div style={{ alignContent: 'center', display: 'flex' }}>
|
2023-02-24 19:17:13 +00:00
|
|
|
<NavBar width={windowSize.width} height={navbarHeight} hasRobot={robot.avatarLoaded} />
|
2022-11-21 12:56:29 +00:00
|
|
|
</div>
|
2022-10-30 19:13:01 +00:00
|
|
|
<MainDialogs
|
|
|
|
open={open}
|
|
|
|
setOpen={setOpen}
|
|
|
|
setRobot={setRobot}
|
2022-11-07 10:13:02 +00:00
|
|
|
setPage={setPage}
|
|
|
|
setCurrentOrder={setCurrentOrder}
|
2022-10-30 19:13:01 +00:00
|
|
|
info={info}
|
|
|
|
robot={robot}
|
|
|
|
closeAll={closeAll}
|
2022-11-07 16:45:05 +00:00
|
|
|
baseUrl={baseUrl}
|
2022-10-30 19:13:01 +00:00
|
|
|
/>
|
2022-10-20 18:06:16 +00:00
|
|
|
</Router>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Main;
|