bbgo_origin/apps/frontend/pages/connect/index.js

56 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-06-11 00:57:54 +00:00
import React, { useEffect, useState } from 'react';
2022-04-13 15:55:25 +00:00
2022-06-12 15:19:39 +00:00
import { makeStyles } from '@mui/styles';
2022-06-12 15:11:42 +00:00
import Typography from '@mui/material/Typography';
import Paper from '@mui/material/Paper';
2022-04-13 15:55:25 +00:00
import PlainLayout from '../../layouts/PlainLayout';
2022-06-11 00:57:54 +00:00
import { QRCodeSVG } from 'qrcode.react';
import { queryOutboundIP } from '../../api/bbgo';
2022-04-13 15:55:25 +00:00
const useStyles = makeStyles((theme) => ({
2022-06-11 00:57:54 +00:00
paper: {
margin: theme.spacing(2),
padding: theme.spacing(2),
},
dataGridContainer: {
display: 'flex',
textAlign: 'center',
alignItems: 'center',
alignContent: 'center',
height: 320,
},
2022-04-13 15:55:25 +00:00
}));
2022-04-13 16:53:01 +00:00
function fetchConnectUrl(cb) {
2022-06-11 00:57:54 +00:00
return queryOutboundIP((outboundIP) => {
cb(
window.location.protocol + '//' + outboundIP + ':' + window.location.port
);
});
2022-04-13 16:53:01 +00:00
}
export default function Connect() {
2022-06-11 00:57:54 +00:00
const classes = useStyles();
const [connectUrl, setConnectUrl] = useState([]);
useEffect(() => {
fetchConnectUrl(function (url) {
setConnectUrl(url);
});
}, []);
return (
<PlainLayout title={'Connect'}>
<Paper className={classes.paper}>
<Typography variant="h4" gutterBottom>
Sign In Using QR Codes
</Typography>
<div className={classes.dataGridContainer}>
<QRCodeSVG size={160} style={{ flexGrow: 1 }} value={connectUrl} />
</div>
</Paper>
</PlainLayout>
);
2022-04-13 15:55:25 +00:00
}