mirror of
https://github.com/RoboSats/robosats.git
synced 2025-02-21 12:49:02 +00:00
Add Main component WIP
This commit is contained in:
parent
e43b274c33
commit
037d46ceef
@ -1,6 +1,6 @@
|
|||||||
import React, { Suspense, useState } from 'react';
|
import React, { Suspense, useState } from 'react';
|
||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from 'react-dom/client';
|
||||||
import HomePage from './HomePage';
|
import Main from './Main';
|
||||||
import { CssBaseline, IconButton } from '@mui/material';
|
import { CssBaseline, IconButton } from '@mui/material';
|
||||||
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
||||||
import UnsafeAlert from './UnsafeAlert';
|
import UnsafeAlert from './UnsafeAlert';
|
||||||
@ -83,7 +83,7 @@ const App = (): JSX.Element => {
|
|||||||
{theme.palette.mode === 'dark' ? <LightModeIcon /> : <DarkModeIcon />}
|
{theme.palette.mode === 'dark' ? <LightModeIcon /> : <DarkModeIcon />}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<UnsafeAlert className='unsafeAlert' />
|
<UnsafeAlert className='unsafeAlert' />
|
||||||
<HomePage theme={theme} />
|
<Main />
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</I18nextProvider>
|
</I18nextProvider>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
|
@ -5,7 +5,7 @@ import { useHistory } from 'react-router-dom';
|
|||||||
import currencyDict from '../../../static/assets/currencies.json';
|
import currencyDict from '../../../static/assets/currencies.json';
|
||||||
import DepthChart from '../Charts/DepthChart';
|
import DepthChart from '../Charts/DepthChart';
|
||||||
|
|
||||||
import { Order, LimitList, Maker } from '../../models';
|
import { Book, Order, LimitList, Maker } from '../../models';
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
import { BarChart, FormatListBulleted } from '@mui/icons-material';
|
import { BarChart, FormatListBulleted } from '@mui/icons-material';
|
||||||
@ -13,27 +13,24 @@ import BookTable from './BookTable';
|
|||||||
import { MakerForm } from '../MakerPage';
|
import { MakerForm } from '../MakerPage';
|
||||||
|
|
||||||
interface BookPageProps {
|
interface BookPageProps {
|
||||||
bookLoading?: boolean;
|
|
||||||
bookRefreshing?: boolean;
|
bookRefreshing?: boolean;
|
||||||
loadingLimits: boolean;
|
loadingLimits: boolean;
|
||||||
lastDayPremium: number;
|
lastDayPremium: number;
|
||||||
orders: Order[];
|
book: Book;
|
||||||
limits: LimitList;
|
limits: LimitList;
|
||||||
fetchLimits: () => void;
|
fetchLimits: () => void;
|
||||||
type: number;
|
type: number;
|
||||||
currency: number;
|
currency: number;
|
||||||
windowWidth: number;
|
windowWidth: number;
|
||||||
windowHeight: number;
|
windowHeight: number;
|
||||||
fetchBook: (loading: boolean, refreshing: boolean) => void;
|
fetchBook: () => void;
|
||||||
setAppState: (state: object) => void;
|
setAppState: (state: object) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BookPage = ({
|
const BookPage = ({
|
||||||
bookLoading = false,
|
|
||||||
bookRefreshing = false,
|
|
||||||
lastDayPremium = 0,
|
lastDayPremium = 0,
|
||||||
loadingLimits,
|
loadingLimits,
|
||||||
orders = [],
|
book = { orders: [], loading: true },
|
||||||
limits,
|
limits,
|
||||||
fetchLimits,
|
fetchLimits,
|
||||||
type,
|
type,
|
||||||
@ -75,7 +72,7 @@ const BookPage = ({
|
|||||||
const [maker, setMaker] = useState<Maker>(defaultMaker);
|
const [maker, setMaker] = useState<Maker>(defaultMaker);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (orders.length < 1) {
|
if (book.orders.length < 1) {
|
||||||
fetchBook(true, false);
|
fetchBook(true, false);
|
||||||
} else {
|
} else {
|
||||||
fetchBook(false, true);
|
fetchBook(false, true);
|
||||||
@ -184,10 +181,8 @@ const BookPage = ({
|
|||||||
>
|
>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<BookTable
|
<BookTable
|
||||||
loading={bookLoading}
|
clickRefresh={() => fetchBook()}
|
||||||
refreshing={bookRefreshing}
|
book={book}
|
||||||
clickRefresh={() => fetchBook(false, true)}
|
|
||||||
orders={orders}
|
|
||||||
type={type}
|
type={type}
|
||||||
currency={currency}
|
currency={currency}
|
||||||
maxWidth={maxBookTableWidth} // EM units
|
maxWidth={maxBookTableWidth} // EM units
|
||||||
@ -215,8 +210,7 @@ const BookPage = ({
|
|||||||
</Grid>
|
</Grid>
|
||||||
) : view === 'depth' ? (
|
) : view === 'depth' ? (
|
||||||
<DepthChart
|
<DepthChart
|
||||||
bookLoading={bookLoading}
|
book={book}
|
||||||
orders={orders}
|
|
||||||
lastDayPremium={lastDayPremium}
|
lastDayPremium={lastDayPremium}
|
||||||
currency={currency}
|
currency={currency}
|
||||||
compact={true}
|
compact={true}
|
||||||
@ -227,10 +221,8 @@ const BookPage = ({
|
|||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<BookTable
|
<BookTable
|
||||||
loading={bookLoading}
|
book={book}
|
||||||
refreshing={bookRefreshing}
|
clickRefresh={() => fetchBook()}
|
||||||
clickRefresh={() => fetchBook(false, true)}
|
|
||||||
orders={orders}
|
|
||||||
type={type}
|
type={type}
|
||||||
currency={currency}
|
currency={currency}
|
||||||
maxWidth={windowWidth * 0.97} // EM units
|
maxWidth={windowWidth * 0.97} // EM units
|
||||||
|
@ -18,7 +18,7 @@ import {
|
|||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import { DataGrid, GridPagination } from '@mui/x-data-grid';
|
import { DataGrid, GridPagination } from '@mui/x-data-grid';
|
||||||
import currencyDict from '../../../static/assets/currencies.json';
|
import currencyDict from '../../../static/assets/currencies.json';
|
||||||
import { Order } from '../../models';
|
import { Book, Order } from '../../models';
|
||||||
import filterOrders from '../../utils/filterOrders';
|
import filterOrders from '../../utils/filterOrders';
|
||||||
import BookControl from './BookControl';
|
import BookControl from './BookControl';
|
||||||
|
|
||||||
@ -30,13 +30,11 @@ import hexToRgb from '../../utils/hexToRgb';
|
|||||||
import statusBadgeColor from '../../utils/statusBadgeColor';
|
import statusBadgeColor from '../../utils/statusBadgeColor';
|
||||||
|
|
||||||
// Icons
|
// Icons
|
||||||
import { Fullscreen, FullscreenExit, Refresh, WidthFull } from '@mui/icons-material';
|
import { Fullscreen, FullscreenExit, Refresh } from '@mui/icons-material';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
loading?: boolean;
|
|
||||||
refreshing?: boolean;
|
|
||||||
clickRefresh?: () => void;
|
clickRefresh?: () => void;
|
||||||
orders: Order[];
|
book: Book;
|
||||||
type: number;
|
type: number;
|
||||||
currency: number;
|
currency: number;
|
||||||
maxWidth: number;
|
maxWidth: number;
|
||||||
@ -52,10 +50,8 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const BookTable = ({
|
const BookTable = ({
|
||||||
loading = false,
|
|
||||||
refreshing = false,
|
|
||||||
clickRefresh,
|
clickRefresh,
|
||||||
orders,
|
book,
|
||||||
type,
|
type,
|
||||||
currency,
|
currency,
|
||||||
maxWidth,
|
maxWidth,
|
||||||
@ -702,17 +698,17 @@ const BookTable = ({
|
|||||||
rows={
|
rows={
|
||||||
showControls
|
showControls
|
||||||
? filterOrders({
|
? filterOrders({
|
||||||
orders,
|
orders: book.orders,
|
||||||
baseFilter: { currency, type },
|
baseFilter: { currency, type },
|
||||||
paymentMethods,
|
paymentMethods,
|
||||||
})
|
})
|
||||||
: orders
|
: book.orders
|
||||||
}
|
}
|
||||||
loading={loading || refreshing}
|
loading={book.loading}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
hideFooter={!showFooter}
|
hideFooter={!showFooter}
|
||||||
components={gridComponents()}
|
components={gridComponents()}
|
||||||
pageSize={loading ? 0 : pageSize}
|
pageSize={book.loading && book.orders.length == 0 ? 0 : pageSize}
|
||||||
rowsPerPageOptions={width < 22 ? [] : [0, pageSize, defaultPageSize * 2, 50, 100]}
|
rowsPerPageOptions={width < 22 ? [] : [0, pageSize, defaultPageSize * 2, 50, 100]}
|
||||||
onPageSizeChange={(newPageSize) => {
|
onPageSizeChange={(newPageSize) => {
|
||||||
setPageSize(newPageSize);
|
setPageSize(newPageSize);
|
||||||
@ -728,16 +724,20 @@ const BookTable = ({
|
|||||||
<Paper style={{ width: '100%', height: '100%', overflow: 'auto' }}>
|
<Paper style={{ width: '100%', height: '100%', overflow: 'auto' }}>
|
||||||
<DataGrid
|
<DataGrid
|
||||||
localeText={localeText}
|
localeText={localeText}
|
||||||
rows={orders.filter(
|
rows={
|
||||||
(order) =>
|
showControls
|
||||||
(order.type == type || type == null) &&
|
? filterOrders({
|
||||||
(order.currency == currency || currency == 0),
|
orders: book.orders,
|
||||||
)}
|
baseFilter: { currency, type },
|
||||||
loading={loading || refreshing}
|
paymentMethods,
|
||||||
|
})
|
||||||
|
: book.orders
|
||||||
|
}
|
||||||
|
loading={book.loading}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
hideFooter={!showFooter}
|
hideFooter={!showFooter}
|
||||||
components={gridComponents()}
|
components={gridComponents()}
|
||||||
pageSize={loading ? 0 : pageSize}
|
pageSize={book.loading && book.orders.length == 0 ? 0 : pageSize}
|
||||||
rowsPerPageOptions={[0, pageSize, defaultPageSize * 2, 50, 100]}
|
rowsPerPageOptions={[0, pageSize, defaultPageSize * 2, 50, 100]}
|
||||||
onPageSizeChange={(newPageSize) => {
|
onPageSizeChange={(newPageSize) => {
|
||||||
setPageSize(newPageSize);
|
setPageSize(newPageSize);
|
||||||
|
@ -1,187 +0,0 @@
|
|||||||
import React, { Component } from 'react';
|
|
||||||
import { HashRouter, BrowserRouter, Switch, Route } from 'react-router-dom';
|
|
||||||
|
|
||||||
import UserGenPage from './UserGenPage';
|
|
||||||
import MakerPage from './MakerPage';
|
|
||||||
import BookPage from './BookPage';
|
|
||||||
import OrderPage from './OrderPage';
|
|
||||||
import BottomBar from './BottomBar';
|
|
||||||
|
|
||||||
import { apiClient } from '../services/api';
|
|
||||||
|
|
||||||
export default class HomePage extends Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
nickname: null,
|
|
||||||
token: null,
|
|
||||||
copiedToken: false,
|
|
||||||
avatarLoaded: false,
|
|
||||||
buyChecked: false,
|
|
||||||
sellChecked: false,
|
|
||||||
type: null,
|
|
||||||
currency: 0,
|
|
||||||
bookCurrencyCode: 'ANY',
|
|
||||||
orders: new Array(),
|
|
||||||
bookLoading: true,
|
|
||||||
bookRefreshing: false,
|
|
||||||
activeOrderId: null,
|
|
||||||
lastOrderId: null,
|
|
||||||
earnedRewards: 0,
|
|
||||||
referralCode: '',
|
|
||||||
lastDayPremium: 0,
|
|
||||||
limits: {},
|
|
||||||
loadingLimits: true,
|
|
||||||
maker: {},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount = () => {
|
|
||||||
if (typeof window !== undefined) {
|
|
||||||
this.setState({
|
|
||||||
windowWidth: window.innerWidth / this.props.theme.typography.fontSize,
|
|
||||||
windowHeight: window.innerHeight / this.props.theme.typography.fontSize,
|
|
||||||
});
|
|
||||||
window.addEventListener('resize', this.onResize);
|
|
||||||
}
|
|
||||||
this.fetchBook(true, false);
|
|
||||||
this.fetchLimits(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
componentWillUnmount = () => {
|
|
||||||
if (typeof window !== undefined) {
|
|
||||||
window.removeEventListener('resize', this.onResize);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
onResize = () => {
|
|
||||||
this.setState({
|
|
||||||
windowWidth: window.innerWidth / this.props.theme.typography.fontSize,
|
|
||||||
windowHeight: window.innerHeight / this.props.theme.typography.fontSize,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
setAppState = (newState) => {
|
|
||||||
this.setState(newState);
|
|
||||||
};
|
|
||||||
|
|
||||||
redirectTo(location) {
|
|
||||||
this.props.history.push(location);
|
|
||||||
}
|
|
||||||
|
|
||||||
getBasename() {
|
|
||||||
if (window.NativeRobosats) {
|
|
||||||
// Only for Android
|
|
||||||
return window.location.pathname;
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
fetchBook = (loading, refreshing) => {
|
|
||||||
this.setState({ bookLoading: loading, bookRefreshing: refreshing });
|
|
||||||
apiClient.get('/api/book/').then((data) =>
|
|
||||||
this.setState({
|
|
||||||
bookLoading: false,
|
|
||||||
bookRefreshing: false,
|
|
||||||
orders: data.not_found ? [] : data,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
fetchLimits = (loading) => {
|
|
||||||
this.setState({ loadingLimits: loading });
|
|
||||||
const limits = apiClient.get('/api/limits/').then((data) => {
|
|
||||||
this.setState({ limits: data, loadingLimits: false });
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
return limits;
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const fontSize = this.props.theme.typography.fontSize;
|
|
||||||
const fontSizeFactor = fontSize / 14; // default fontSize is 14
|
|
||||||
const Router = window.NativeRobosats ? HashRouter : BrowserRouter;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Router basename={this.getBasename()}>
|
|
||||||
<div className='appCenter'>
|
|
||||||
<Switch>
|
|
||||||
<Route
|
|
||||||
exact
|
|
||||||
path='/'
|
|
||||||
render={(props) => (
|
|
||||||
<UserGenPage
|
|
||||||
{...props}
|
|
||||||
{...this.state}
|
|
||||||
{...this.props}
|
|
||||||
setAppState={this.setAppState}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/ref/:refCode'
|
|
||||||
render={(props) => (
|
|
||||||
<UserGenPage
|
|
||||||
{...props}
|
|
||||||
{...this.state}
|
|
||||||
{...this.props}
|
|
||||||
setAppState={this.setAppState}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/make'
|
|
||||||
render={(props) => (
|
|
||||||
<MakerPage
|
|
||||||
{...props}
|
|
||||||
{...this.state}
|
|
||||||
{...this.props}
|
|
||||||
fetchLimits={this.fetchLimits}
|
|
||||||
setAppState={this.setAppState}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/book'
|
|
||||||
render={(props) => (
|
|
||||||
<BookPage
|
|
||||||
{...props}
|
|
||||||
{...this.state}
|
|
||||||
{...this.props}
|
|
||||||
fetchBook={this.fetchBook}
|
|
||||||
fetchLimits={this.fetchLimits}
|
|
||||||
setAppState={this.setAppState}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path='/order/:orderId'
|
|
||||||
render={(props) => (
|
|
||||||
<OrderPage
|
|
||||||
{...props}
|
|
||||||
{...this.state}
|
|
||||||
{...this.props}
|
|
||||||
setAppState={this.setAppState}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</Switch>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className='bottomBar'
|
|
||||||
style={{
|
|
||||||
height: `${40 * fontSizeFactor}px`,
|
|
||||||
width: `${(this.state.windowWidth / 16) * 14}em`,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<BottomBar
|
|
||||||
redirectTo={this.redirectTo}
|
|
||||||
{...this.state}
|
|
||||||
{...this.props}
|
|
||||||
setAppState={this.setAppState}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Router>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
168
frontend/src/components/Main.tsx
Normal file
168
frontend/src/components/Main.tsx
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { HashRouter, BrowserRouter, Switch, Route, useHistory } from 'react-router-dom';
|
||||||
|
import { useTheme } from '@mui/material';
|
||||||
|
|
||||||
|
import UserGenPage from './UserGenPage';
|
||||||
|
import MakerPage from './MakerPage';
|
||||||
|
import BookPage from './BookPage';
|
||||||
|
import OrderPage from './OrderPage';
|
||||||
|
import BottomBar from './BottomBar';
|
||||||
|
|
||||||
|
import { apiClient } from '../services/api';
|
||||||
|
|
||||||
|
import { Book, LimitList } from '../models';
|
||||||
|
|
||||||
|
interface Limits {
|
||||||
|
list: LimitList;
|
||||||
|
loading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Main = (): JSX.Element => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const history = useHistory();
|
||||||
|
const Router = window.NativeRobosats ? HashRouter : BrowserRouter;
|
||||||
|
const basename = window.NativeRobosats ? window.location.pathname : '';
|
||||||
|
const [windowSize, setWindowSize] = useState<number[]>(); // EM values
|
||||||
|
|
||||||
|
// All app data structured
|
||||||
|
const [book, setBook] = useState<Book>({ orders: [], loading: true });
|
||||||
|
const [limits, setLimits] = useState<Limits>({ list: [], loading: true });
|
||||||
|
const [robot, setRobot] = useState();
|
||||||
|
const [maker, setMaker] = useState();
|
||||||
|
const [info, setInfo] = useState();
|
||||||
|
const [favorites, setFavorites] = useState();
|
||||||
|
const [settings, setSettings] = useState();
|
||||||
|
|
||||||
|
// constructor(props) {
|
||||||
|
// super(props);
|
||||||
|
// this.state = {
|
||||||
|
// type: null,
|
||||||
|
// currency: 0,
|
||||||
|
// lastDayPremium: 0,
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof window !== undefined) {
|
||||||
|
onResize();
|
||||||
|
window.addEventListener('resize', onResize);
|
||||||
|
}
|
||||||
|
fetchBook();
|
||||||
|
fetchLimits();
|
||||||
|
return () => {
|
||||||
|
if (typeof window !== undefined) {
|
||||||
|
window.removeEventListener('resize', onResize);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onResize = function () {
|
||||||
|
setWindowSize([
|
||||||
|
window.innerWidth / theme.typography.fontSize,
|
||||||
|
window.innerHeight / theme.typography.fontSize,
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchBook = function () {
|
||||||
|
setBook({ ...book, loading: true });
|
||||||
|
apiClient.get('/api/book/').then((data) =>
|
||||||
|
setBook({
|
||||||
|
loading: false,
|
||||||
|
orders: data.not_found ? [] : data,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchLimits = () => {
|
||||||
|
setLimits({ ...limits, loading: true });
|
||||||
|
const data = apiClient.get('/api/limits/').then((data) => {
|
||||||
|
setLimits({ limits: data, loading: false });
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Router basename={basename}>
|
||||||
|
<div className='appCenter'>
|
||||||
|
<Switch>
|
||||||
|
<Route
|
||||||
|
exact
|
||||||
|
path='/'
|
||||||
|
render={(props) => (
|
||||||
|
<UserGenPage
|
||||||
|
{...props}
|
||||||
|
{...this.state}
|
||||||
|
{...this.props}
|
||||||
|
setAppState={this.setAppState}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/ref/:refCode'
|
||||||
|
render={(props) => (
|
||||||
|
<UserGenPage
|
||||||
|
{...props}
|
||||||
|
{...this.state}
|
||||||
|
{...this.props}
|
||||||
|
setAppState={this.setAppState}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/make'
|
||||||
|
render={() => (
|
||||||
|
<MakerPage
|
||||||
|
orders={book.orders}
|
||||||
|
fetchLimits={fetchLimits}
|
||||||
|
maker={maker}
|
||||||
|
setMaker={setMaker}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/book'
|
||||||
|
render={(props) => (
|
||||||
|
<BookPage
|
||||||
|
{...props}
|
||||||
|
{...this.state}
|
||||||
|
{...this.props}
|
||||||
|
book={book}
|
||||||
|
fetchBook={this.fetchBook}
|
||||||
|
fetchLimits={this.fetchLimits}
|
||||||
|
setAppState={this.setAppState}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path='/order/:orderId'
|
||||||
|
render={(props) => (
|
||||||
|
<OrderPage
|
||||||
|
{...props}
|
||||||
|
{...this.state}
|
||||||
|
{...this.props}
|
||||||
|
setAppState={this.setAppState}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Switch>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className='bottomBar'
|
||||||
|
style={{
|
||||||
|
height: '2.857em',
|
||||||
|
width: `${(windowSize[0] / 16) * 14}em`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<BottomBar
|
||||||
|
redirectTo={(location) => history.push(location)}
|
||||||
|
{...this.state}
|
||||||
|
{...this.props}
|
||||||
|
setAppState={this.setAppState}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Router>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Main;
|
@ -43,9 +43,8 @@ import { SelfImprovement, Lock, HourglassTop, DeleteSweep, Edit } from '@mui/ico
|
|||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
|
|
||||||
interface MakerFormProps {
|
interface MakerFormProps {
|
||||||
limits: LimitList;
|
limits: { list: LimitList; loading: boolean };
|
||||||
fetchLimits: (loading) => void;
|
fetchLimits: () => LimitList;
|
||||||
loadingLimits: boolean;
|
|
||||||
pricingMethods: boolean;
|
pricingMethods: boolean;
|
||||||
maker: Maker;
|
maker: Maker;
|
||||||
type: number;
|
type: number;
|
||||||
@ -62,7 +61,6 @@ interface MakerFormProps {
|
|||||||
const MakerForm = ({
|
const MakerForm = ({
|
||||||
limits,
|
limits,
|
||||||
fetchLimits,
|
fetchLimits,
|
||||||
loadingLimits,
|
|
||||||
pricingMethods,
|
pricingMethods,
|
||||||
currency,
|
currency,
|
||||||
type,
|
type,
|
||||||
@ -94,19 +92,18 @@ const MakerForm = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCurrencyCode(currencyDict[currency == 0 ? 1 : currency]);
|
setCurrencyCode(currencyDict[currency == 0 ? 1 : currency]);
|
||||||
if (Object.keys(limits).length === 0) {
|
if (Object.keys(limits.list).length === 0) {
|
||||||
setAppState({ loadingLimits: true });
|
fetchLimits().then((data) => {
|
||||||
fetchLimits(true).then((data) => {
|
|
||||||
updateAmountLimits(data, currency, maker.premium);
|
updateAmountLimits(data, currency, maker.premium);
|
||||||
updateCurrentPrice(data, currency, maker.premium);
|
updateCurrentPrice(data, currency, maker.premium);
|
||||||
updateSatoshisLimits(data);
|
updateSatoshisLimits(data);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
updateAmountLimits(limits, currency, maker.premium);
|
updateAmountLimits(limits.list, currency, maker.premium);
|
||||||
updateCurrentPrice(limits, currency, maker.premium);
|
updateCurrentPrice(limits.list, currency, maker.premium);
|
||||||
updateSatoshisLimits(limits);
|
updateSatoshisLimits(limits.list);
|
||||||
|
|
||||||
fetchLimits(false);
|
fetchLimits();
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -130,10 +127,10 @@ const MakerForm = ({
|
|||||||
const updateCurrentPrice = function (limits: LimitList, currency: number, premium: number) {
|
const updateCurrentPrice = function (limits: LimitList, currency: number, premium: number) {
|
||||||
const index = currency === 0 ? 1 : currency;
|
const index = currency === 0 ? 1 : currency;
|
||||||
let price = '...';
|
let price = '...';
|
||||||
if (maker.is_explicit && maker.amount > 0 && maker.satoshis > 0) {
|
if (maker.isExplicit && maker.amount > 0 && maker.satoshis > 0) {
|
||||||
price = maker.amount / (maker.satoshis / 100000000);
|
price = maker.amount / (maker.satoshis / 100000000);
|
||||||
} else if (!maker.is_explicit) {
|
} else if (!maker.is_explicit) {
|
||||||
price = limits[index].price * (1 + premium / 100);
|
price = limits.list[index].price * (1 + premium / 100);
|
||||||
}
|
}
|
||||||
setCurrentPrice(parseFloat(Number(price).toPrecision(5)));
|
setCurrentPrice(parseFloat(Number(price).toPrecision(5)));
|
||||||
};
|
};
|
||||||
@ -145,13 +142,13 @@ const MakerForm = ({
|
|||||||
currency: newCurrency,
|
currency: newCurrency,
|
||||||
bookCurrencyCode: currencyCode,
|
bookCurrencyCode: currencyCode,
|
||||||
});
|
});
|
||||||
updateAmountLimits(limits, newCurrency, maker.premium);
|
updateAmountLimits(limits.list, newCurrency, maker.premium);
|
||||||
updateCurrentPrice(limits, newCurrency, maker.premium);
|
updateCurrentPrice(limits.list, newCurrency, maker.premium);
|
||||||
if (advancedOptions) {
|
if (advancedOptions) {
|
||||||
setMaker({
|
setMaker({
|
||||||
...maker,
|
...maker,
|
||||||
minAmount: parseFloat(Number(limits[newCurrency].max_amount * 0.25).toPrecision(2)),
|
minAmount: parseFloat(Number(limits.list[newCurrency].max_amount * 0.25).toPrecision(2)),
|
||||||
maxAmount: parseFloat(Number(limits[newCurrency].max_amount * 0.75).toPrecision(2)),
|
maxAmount: parseFloat(Number(limits.list[newCurrency].max_amount * 0.75).toPrecision(2)),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -198,8 +195,8 @@ const MakerForm = ({
|
|||||||
badPremiumText = t('Must be more than {{min}}%', { min });
|
badPremiumText = t('Must be more than {{min}}%', { min });
|
||||||
premium = -99.99;
|
premium = -99.99;
|
||||||
}
|
}
|
||||||
updateCurrentPrice(limits, currency, premium);
|
updateCurrentPrice(limits.list, currency, premium);
|
||||||
updateAmountLimits(limits, currency, premium);
|
updateAmountLimits(limits.list, currency, premium);
|
||||||
setMaker({
|
setMaker({
|
||||||
...maker,
|
...maker,
|
||||||
premium,
|
premium,
|
||||||
@ -331,10 +328,10 @@ const MakerForm = ({
|
|||||||
const index = currency === 0 ? 1 : currency;
|
const index = currency === 0 ? 1 : currency;
|
||||||
const minAmount = maker.amount
|
const minAmount = maker.amount
|
||||||
? parseFloat((maker.amount / 2).toPrecision(2))
|
? parseFloat((maker.amount / 2).toPrecision(2))
|
||||||
: parseFloat(Number(limits[index].max_amount * 0.25).toPrecision(2));
|
: parseFloat(Number(limits.list[index].max_amount * 0.25).toPrecision(2));
|
||||||
const maxAmount = maker.amount
|
const maxAmount = maker.amount
|
||||||
? parseFloat(maker.amount)
|
? parseFloat(maker.amount)
|
||||||
: parseFloat(Number(limits[index].max_amount * 0.75).toPrecision(2));
|
: parseFloat(Number(limits.list[index].max_amount * 0.75).toPrecision(2));
|
||||||
|
|
||||||
setMaker({
|
setMaker({
|
||||||
...maker,
|
...maker,
|
||||||
@ -437,12 +434,12 @@ const MakerForm = ({
|
|||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<ConfirmationDialogs />
|
<ConfirmationDialogs />
|
||||||
<Collapse in={loadingLimits}>
|
<Collapse in={limits.loading}>
|
||||||
<div style={{ display: loadingLimits ? '' : 'none' }}>
|
<div style={{ display: limits.loading ? '' : 'none' }}>
|
||||||
<LinearProgress />
|
<LinearProgress />
|
||||||
</div>
|
</div>
|
||||||
</Collapse>
|
</Collapse>
|
||||||
<Collapse in={!(loadingLimits || collapseAll)}>
|
<Collapse in={!(limits.loading || collapseAll)}>
|
||||||
<Grid container justifyContent='space-between' spacing={0} sx={{ maxHeight: '1em' }}>
|
<Grid container justifyContent='space-between' spacing={0} sx={{ maxHeight: '1em' }}>
|
||||||
<Grid item>
|
<Grid item>
|
||||||
<IconButton
|
<IconButton
|
||||||
@ -478,7 +475,7 @@ const MakerForm = ({
|
|||||||
>
|
>
|
||||||
<Switch
|
<Switch
|
||||||
size='small'
|
size='small'
|
||||||
disabled={loadingLimits}
|
disabled={limits.loading}
|
||||||
checked={advancedOptions}
|
checked={advancedOptions}
|
||||||
onChange={handleClickAdvanced}
|
onChange={handleClickAdvanced}
|
||||||
/>
|
/>
|
||||||
@ -944,7 +941,7 @@ const MakerForm = ({
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Collapse in={!loadingLimits}>
|
<Collapse in={!limits.loading}>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
placement='top'
|
placement='top'
|
||||||
enterTouchDelay={0}
|
enterTouchDelay={0}
|
||||||
|
@ -10,10 +10,9 @@ import { useHistory } from 'react-router-dom';
|
|||||||
import filterOrders from '../../utils/filterOrders';
|
import filterOrders from '../../utils/filterOrders';
|
||||||
|
|
||||||
interface MakerPageProps {
|
interface MakerPageProps {
|
||||||
limits: LimitList;
|
limits: { list: LimitList; loading: boolean };
|
||||||
fetchLimits: () => void;
|
fetchLimits: () => void;
|
||||||
orders: Order[];
|
orders: Order[];
|
||||||
loadingLimits: boolean;
|
|
||||||
type: number;
|
type: number;
|
||||||
windowHeight: number;
|
windowHeight: number;
|
||||||
windowWidth: number;
|
windowWidth: number;
|
||||||
@ -25,7 +24,6 @@ const MakerPage = ({
|
|||||||
limits,
|
limits,
|
||||||
fetchLimits,
|
fetchLimits,
|
||||||
orders,
|
orders,
|
||||||
loadingLimits,
|
|
||||||
currency,
|
currency,
|
||||||
type,
|
type,
|
||||||
setAppState,
|
setAppState,
|
||||||
@ -82,7 +80,6 @@ const MakerPage = ({
|
|||||||
<MakerForm
|
<MakerForm
|
||||||
limits={limits}
|
limits={limits}
|
||||||
fetchLimits={fetchLimits}
|
fetchLimits={fetchLimits}
|
||||||
loadingLimits={loadingLimits}
|
|
||||||
pricingMethods={false}
|
pricingMethods={false}
|
||||||
setAppState={setAppState}
|
setAppState={setAppState}
|
||||||
maker={maker}
|
maker={maker}
|
||||||
|
@ -23,4 +23,9 @@ export interface Order {
|
|||||||
maker_status: 'Active' | 'Seen recently' | 'Inactive';
|
maker_status: 'Active' | 'Seen recently' | 'Inactive';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Book {
|
||||||
|
orders: Order[];
|
||||||
|
loading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export default Order;
|
export default Order;
|
29
frontend/src/models/Robot.model.ts
Normal file
29
frontend/src/models/Robot.model.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
export interface Robot {
|
||||||
|
nickname: string | null;
|
||||||
|
token: string | null;
|
||||||
|
bitsEntropy: number | null;
|
||||||
|
shannonEntropy: number | null;
|
||||||
|
stealthInvoices: boolean;
|
||||||
|
activeOrderId: number | null;
|
||||||
|
lastOrderId: number | null;
|
||||||
|
earnedRewards: number;
|
||||||
|
referralCode: string;
|
||||||
|
loading: boolean;
|
||||||
|
copiedToken: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const defaultRobot: Robot = {
|
||||||
|
nickname: null,
|
||||||
|
token: null,
|
||||||
|
bitsEntropy: null,
|
||||||
|
shannonEntropy: null,
|
||||||
|
stealthInvoices: true,
|
||||||
|
activeOrderId: null,
|
||||||
|
lastOrderId: null,
|
||||||
|
earnedRewards: 0,
|
||||||
|
referralCode: '',
|
||||||
|
loading: true,
|
||||||
|
copiedToken: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Robot;
|
@ -3,3 +3,6 @@ export type { Limit } from './Limit.model';
|
|||||||
export type { Maker } from './Maker.model';
|
export type { Maker } from './Maker.model';
|
||||||
export { defaultMaker } from './Maker.model';
|
export { defaultMaker } from './Maker.model';
|
||||||
export type { Order } from './Order.model';
|
export type { Order } from './Order.model';
|
||||||
|
export type { Book } from './Order.model';
|
||||||
|
export type { Robot } from './Robot.model';
|
||||||
|
export { defaultRobot } from './Robot.model';
|
||||||
|
Loading…
Reference in New Issue
Block a user