bbgo_origin/frontend/pages/index.tsx

114 lines
2.9 KiB
TypeScript
Raw Normal View History

2022-06-11 00:57:54 +00:00
import React, { useState } from 'react';
import { useRouter } from 'next/router';
2021-01-24 10:12:26 +00:00
2022-06-12 15:08:25 +00:00
import { makeStyles } from '@mui/core/styles';
import Typography from '@mui/core/Typography';
import Box from '@mui/core/Box';
import Grid from '@mui/core/Grid';
import Paper from '@mui/core/Paper';
2021-01-24 06:32:52 +00:00
2021-01-25 10:29:31 +00:00
import TotalAssetsPie from '../components/TotalAssetsPie';
import TotalAssetSummary from '../components/TotalAssetsSummary';
import TotalAssetDetails from '../components/TotalAssetsDetails';
2021-01-25 10:29:31 +00:00
2021-01-28 10:51:35 +00:00
import TradingVolumePanel from '../components/TradingVolumePanel';
2021-01-25 10:29:31 +00:00
import ExchangeSessionTabPanel from '../components/ExchangeSessionTabPanel';
2021-01-24 06:07:44 +00:00
2021-02-01 09:13:27 +00:00
import DashboardLayout from '../layouts/DashboardLayout';
2022-06-11 00:57:54 +00:00
import { queryAssets, querySessions } from '../api/bbgo';
2021-10-25 18:02:29 +00:00
import { ChainId, Config, DAppProvider } from '@usedapp/core';
2021-01-24 10:12:26 +00:00
const useStyles = makeStyles((theme) => ({
2022-06-11 00:57:54 +00:00
totalAssetsSummary: {
margin: theme.spacing(2),
padding: theme.spacing(2),
},
grid: {
flexGrow: 1,
},
control: {
padding: theme.spacing(2),
},
2021-01-24 10:12:26 +00:00
}));
2021-10-25 18:02:29 +00:00
const config: Config = {
2022-06-11 00:57:54 +00:00
readOnlyChainId: ChainId.Mainnet,
readOnlyUrls: {
[ChainId.Mainnet]:
'https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
},
};
2021-10-25 18:02:29 +00:00
2021-02-01 09:13:27 +00:00
// props are pageProps passed from _app.tsx
export default function Home() {
2022-06-11 00:57:54 +00:00
const classes = useStyles();
const router = useRouter();
const [assets, setAssets] = useState({});
const [sessions, setSessions] = React.useState([]);
React.useEffect(() => {
querySessions((sessions) => {
if (sessions && sessions.length > 0) {
setSessions(sessions);
queryAssets(setAssets);
} else {
router.push('/setup');
}
}).catch((err) => {
console.error(err);
});
}, [router]);
if (sessions.length == 0) {
2021-01-25 10:29:31 +00:00
return (
2022-06-11 00:57:54 +00:00
<DashboardLayout>
<Box m={4}>
<Typography variant="h4" gutterBottom>
Loading
</Typography>
</Box>
</DashboardLayout>
2021-01-25 08:56:02 +00:00
);
2022-06-11 00:57:54 +00:00
}
2021-01-24 06:32:52 +00:00
2022-06-11 00:57:54 +00:00
console.log('index: assets', assets);
return (
<DAppProvider config={config}>
<DashboardLayout>
<Paper className={classes.totalAssetsSummary}>
<Typography variant="h4" gutterBottom>
Total Assets
</Typography>
<div className={classes.grid}>
<Grid
container
direction="row"
justifyContent="space-around"
alignItems="flex-start"
spacing={1}
>
<Grid item xs={12} md={8}>
<TotalAssetSummary assets={assets} />
<TotalAssetsPie assets={assets} />
</Grid>
<Grid item xs={12} md={4}>
<TotalAssetDetails assets={assets} />
</Grid>
</Grid>
</div>
</Paper>
<TradingVolumePanel />
<ExchangeSessionTabPanel />
</DashboardLayout>
</DAppProvider>
);
}