Improve book refresh behavior other minor fixes

This commit is contained in:
Reckless_Satoshi 2022-09-29 15:14:54 -07:00
parent a6cbff8ff6
commit 3b0e740ea2
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
8 changed files with 50 additions and 34 deletions

View File

@ -33,15 +33,20 @@ class BookPage extends Component {
} }
componentDidMount = () => { componentDidMount = () => {
this.getOrderDetails(); if (this.props.bookOrders.length < 1) {
this.getOrderDetails(true, false);
} else {
this.getOrderDetails(false, true);
}
}; };
getOrderDetails() { getOrderDetails(loading, refreshing) {
this.props.setAppState({ bookLoading: true }); this.props.setAppState({ bookLoading: loading, bookRefreshing: refreshing });
apiClient.get('/api/book/').then((data) => apiClient.get('/api/book/').then((data) =>
this.props.setAppState({ this.props.setAppState({
bookNotFound: data.not_found, bookNotFound: data.not_found,
bookLoading: false, bookLoading: false,
bookRefreshing: false,
bookOrders: data, bookOrders: data,
}), }),
); );
@ -131,6 +136,8 @@ class BookPage extends Component {
<Grid item xs={tableWidthXS} style={{ width: `${bookTableWidth}em` }}> <Grid item xs={tableWidthXS} style={{ width: `${bookTableWidth}em` }}>
<BookTable <BookTable
loading={this.props.bookLoading} loading={this.props.bookLoading}
refreshing={this.props.bookRefreshing}
clickRefresh={() => this.getOrderDetails(false, true)}
orders={this.props.bookOrders} orders={this.props.bookOrders}
type={this.props.type} type={this.props.type}
currency={this.props.currency} currency={this.props.currency}
@ -179,6 +186,8 @@ class BookPage extends Component {
return ( return (
<BookTable <BookTable
loading={this.props.bookLoading} loading={this.props.bookLoading}
refreshing={this.props.bookRefreshing}
clickRefresh={() => this.getOrderDetails(false, true)}
orders={this.props.bookOrders} orders={this.props.bookOrders}
type={this.props.type} type={this.props.type}
currency={this.props.currency} currency={this.props.currency}
@ -217,13 +226,6 @@ class BookPage extends Component {
const { t } = this.props; const { t } = this.props;
return ( return (
<> <>
<IconButton
sx={{ position: 'fixed', right: '0px', top: '30px' }}
onClick={() => this.setState({ loading: true }) & this.getOrderDetails()}
>
<Refresh />
</IconButton>
<Grid item xs={6} align='right'> <Grid item xs={6} align='right'>
<FormControl align='center'> <FormControl align='center'>
<FormHelperText align='center' sx={{ textAlign: 'center' }}> <FormHelperText align='center' sx={{ textAlign: 'center' }}>

View File

@ -13,6 +13,7 @@ import {
ListItemAvatar, ListItemAvatar,
useTheme, useTheme,
CircularProgress, CircularProgress,
LinearProgress,
IconButton, IconButton,
} from '@mui/material'; } from '@mui/material';
import { DataGrid, GridFooterPlaceholder, GridPagination } from '@mui/x-data-grid'; import { DataGrid, GridFooterPlaceholder, GridPagination } from '@mui/x-data-grid';
@ -27,11 +28,11 @@ import hexToRgb from '../utils/hexToRgb';
import statusBadgeColor from '../utils/statusBadgeColor'; import statusBadgeColor from '../utils/statusBadgeColor';
// Icons // Icons
import FullscreenIcon from '@mui/icons-material/Fullscreen'; import { Fullscreen, FullscreenExit, Refresh } from '@mui/icons-material';
import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
interface Props { interface Props {
loading: boolean; loading: boolean;
clickRefresh: () => void;
orders: Order[]; orders: Order[];
type: number; type: number;
currency: number; currency: number;
@ -44,6 +45,8 @@ interface Props {
const BookTable = ({ const BookTable = ({
loading, loading,
refreshing,
clickRefresh,
orders, orders,
type, type,
currency, currency,
@ -426,7 +429,9 @@ const BookTable = ({
renderCell: (params) => { renderCell: (params) => {
return ( return (
<div style={{ cursor: 'pointer' }}> <div style={{ cursor: 'pointer' }}>
{`${pn(Math.round(params.row.satoshis_now / 1000))}K`} {params.row.satoshis_now > 1000000
? `${pn(Math.round(params.row.satoshis_now / 10000) / 100)} M`
: `${pn(Math.round(params.row.satoshis_now / 1000))} K`}
</div> </div>
); );
}, },
@ -512,7 +517,7 @@ const BookTable = ({
priority: 7, priority: 7,
order: 7, order: 7,
normal: { normal: {
width: 5.8, width: 5,
object: expiryObj, object: expiryObj,
}, },
}, },
@ -582,6 +587,7 @@ const BookTable = ({
const [columns, width] = filteredColumns(fullscreen ? fullWidth : maxWidth); const [columns, width] = filteredColumns(fullscreen ? fullWidth : maxWidth);
const gridComponents = { const gridComponents = {
LoadingOverlay: LinearProgress,
NoResultsOverlay: () => ( NoResultsOverlay: () => (
<Stack height='100%' alignItems='center' justifyContent='center'> <Stack height='100%' alignItems='center' justifyContent='center'>
{t('Filter has no results')} {t('Filter has no results')}
@ -590,10 +596,20 @@ const BookTable = ({
Footer: () => ( Footer: () => (
<Grid container alignItems='center' direction='row' justifyContent='space-between'> <Grid container alignItems='center' direction='row' justifyContent='space-between'>
<Grid item> <Grid item>
<IconButton onClick={() => setFullscreen(!fullscreen)}> <Grid container alignItems='center' direction='row'>
{fullscreen ? <FullscreenExitIcon /> : <FullscreenIcon />} <Grid item xs={6}>
</IconButton> <IconButton onClick={() => setFullscreen(!fullscreen)}>
{fullscreen ? <FullscreenExit /> : <Fullscreen />}
</IconButton>
</Grid>
<Grid item xs={6}>
<IconButton onClick={clickRefresh}>
<Refresh />
</IconButton>
</Grid>
</Grid>
</Grid> </Grid>
<Grid item> <Grid item>
<GridPagination /> <GridPagination />
</Grid> </Grid>
@ -610,7 +626,7 @@ const BookTable = ({
(order) => (order) =>
(order.type == type || type == null) && (order.currency == currency || currency == 0), (order.type == type || type == null) && (order.currency == currency || currency == 0),
)} )}
loading={loading} loading={loading || refreshing}
columns={columns} columns={columns}
components={gridComponents} components={gridComponents}
pageSize={loading ? 0 : pageSize} pageSize={loading ? 0 : pageSize}
@ -634,7 +650,7 @@ const BookTable = ({
(order.type == type || type == null) && (order.type == type || type == null) &&
(order.currency == currency || currency == 0), (order.currency == currency || currency == 0),
)} )}
loading={loading} loading={loading || refreshing}
columns={columns} columns={columns}
components={gridComponents} components={gridComponents}
pageSize={loading ? 0 : pageSize} pageSize={loading ? 0 : pageSize}

View File

@ -33,7 +33,6 @@ import { apiClient } from '../../../services/api/index';
import statusBadgeColor from '../../../utils/statusBadgeColor'; import statusBadgeColor from '../../../utils/statusBadgeColor';
interface DepthChartProps { interface DepthChartProps {
bookLoading: boolean;
orders: Order[]; orders: Order[];
lastDayPremium: number | undefined; lastDayPremium: number | undefined;
currency: number; currency: number;
@ -44,7 +43,6 @@ interface DepthChartProps {
} }
const DepthChart: React.FC<DepthChartProps> = ({ const DepthChart: React.FC<DepthChartProps> = ({
bookLoading,
orders, orders,
lastDayPremium, lastDayPremium,
currency, currency,
@ -291,7 +289,7 @@ const DepthChart: React.FC<DepthChartProps> = ({
return ( return (
<Paper style={{ width: `${width}em`, maxHeight: `${height}em` }}> <Paper style={{ width: `${width}em`, maxHeight: `${height}em` }}>
<Paper variant='outlined'> <Paper variant='outlined'>
{bookLoading || center == undefined || enrichedOrders.length < 1 ? ( {center == undefined || enrichedOrders.length < 1 ? (
<div <div
style={{ style={{
display: 'flex', display: 'flex',

View File

@ -22,6 +22,7 @@ export default class HomePage extends Component {
bookCurrencyCode: 'ANY', bookCurrencyCode: 'ANY',
bookOrders: new Array(), bookOrders: new Array(),
bookLoading: true, bookLoading: true,
bookRefreshing: false,
activeOrderId: null, activeOrderId: null,
lastOrderId: null, lastOrderId: null,
earnedRewards: 0, earnedRewards: 0,

View File

@ -8,7 +8,7 @@ declare global {
} }
export interface ReactNativeWebView { export interface ReactNativeWebView {
postMessage(message: string): void; postMessage: (message: string) => void;
} }
export interface NativeWebViewMessageHttp { export interface NativeWebViewMessageHttp {

View File

@ -29,7 +29,7 @@ class NativeRobosats {
} }
}; };
public postMessage: (message: NativeWebViewMessage) => Promise<{ [key: string]: any }> = ( public postMessage: (message: NativeWebViewMessage) => Promise<{ [key: string]: any }> = async (
message, message,
) => { ) => {
this.messageCounter += 1; this.messageCounter += 1;
@ -37,11 +37,11 @@ class NativeRobosats {
const json = JSON.stringify(message); const json = JSON.stringify(message);
window.ReactNativeWebView?.postMessage(json); window.ReactNativeWebView?.postMessage(json);
return new Promise<object>(async (resolve, reject) => { return await new Promise<object>(async (resolve, reject) => {
if (message.id) { if (message.id) {
this.pendingMessages[message.id] = { this.pendingMessages[message.id] = {
resolve: resolve, resolve,
reject: reject, reject,
}; };
} }
}); });

View File

@ -14,11 +14,11 @@ class ApiNativeClient implements ApiClient {
}; };
public put: (path: string, body: object) => Promise<object | undefined> = async (path, body) => { public put: (path: string, body: object) => Promise<object | undefined> = async (path, body) => {
return new Promise((res, _rej) => res({})); return await new Promise((res, _rej) => res({}));
}; };
public delete: (path: string) => Promise<object | undefined> = async (path) => { public delete: (path: string) => Promise<object | undefined> = async (path) => {
return window.NativeRobosats?.postMessage({ return await window.NativeRobosats?.postMessage({
category: 'http', category: 'http',
type: 'delete', type: 'delete',
path, path,
@ -27,7 +27,7 @@ class ApiNativeClient implements ApiClient {
}; };
public post: (path: string, body: object) => Promise<object | undefined> = async (path, body) => { public post: (path: string, body: object) => Promise<object | undefined> = async (path, body) => {
return window.NativeRobosats?.postMessage({ return await window.NativeRobosats?.postMessage({
category: 'http', category: 'http',
type: 'post', type: 'post',
path, path,
@ -37,7 +37,7 @@ class ApiNativeClient implements ApiClient {
}; };
public get: (path: string) => Promise<object | undefined> = async (path) => { public get: (path: string) => Promise<object | undefined> = async (path) => {
return window.NativeRobosats?.postMessage({ return await window.NativeRobosats?.postMessage({
category: 'http', category: 'http',
type: 'get', type: 'get',
path, path,

View File

@ -9,6 +9,5 @@ export interface ApiClient {
fileImageUrl: (path: string) => Promise<string | undefined>; fileImageUrl: (path: string) => Promise<string | undefined>;
} }
export const apiClient: ApiClient = window.ReactNativeWebView export const apiClient: ApiClient =
? new ApiNativeClient() window.ReactNativeWebView != null ? new ApiNativeClient() : new ApiWebClient();
: new ApiWebClient();