From 1e39f32eb5e80996bad87866c4d3becd4818a5a1 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi <90936742+Reckless-Satoshi@users.noreply.github.com> Date: Fri, 12 May 2023 12:51:52 +0000 Subject: [PATCH] Fix usenavigate PRO (#571) * Simplify and optimize nodeapp * Add pro frontend * Fix PRO errors --- frontend/src/basic/BookPage/index.tsx | 2 + frontend/src/basic/MakerPage/index.tsx | 2 + frontend/src/basic/OrderPage/index.tsx | 3 + frontend/src/components/BookTable/index.tsx | 97 ++++++++++--------- .../src/components/Dialogs/Confirmation.tsx | 5 +- frontend/src/components/Dialogs/NoRobot.tsx | 25 +++-- .../src/components/MakerForm/MakerForm.tsx | 4 + .../components/OrderDetails/TakeButton.tsx | 10 +- .../src/components/OrderDetails/index.tsx | 3 + nodeapp/nginx.conf | 3 +- 10 files changed, 93 insertions(+), 61 deletions(-) diff --git a/frontend/src/basic/BookPage/index.tsx b/frontend/src/basic/BookPage/index.tsx index d1607385..b11c13b7 100644 --- a/frontend/src/basic/BookPage/index.tsx +++ b/frontend/src/basic/BookPage/index.tsx @@ -85,6 +85,7 @@ const BookPage = (): JSX.Element => { onClose={() => { setOpenNoRobot(false); }} + onClickGenerateRobot={() => navigate('/robot')} /> {openMaker ? ( { onOrderCreated={(id) => { navigate('/order/' + id); }} + onClickGenerateRobot={() => navigate('/robot')} /> diff --git a/frontend/src/basic/MakerPage/index.tsx b/frontend/src/basic/MakerPage/index.tsx index 1115db76..5f72fc3c 100644 --- a/frontend/src/basic/MakerPage/index.tsx +++ b/frontend/src/basic/MakerPage/index.tsx @@ -69,6 +69,7 @@ const MakerPage = (): JSX.Element => { onClose={() => { setOpenNoRobot(false); }} + onClickGenerateRobot={() => navigate('/robot')} /> 0 && showMatches}> @@ -114,6 +115,7 @@ const MakerPage = (): JSX.Element => { setShowMatches(false); }} submitButtonLabel={matches.length > 0 && !showMatches ? 'Submit' : 'Create order'} + onClickGenerateRobot={() => navigate('/robot')} /> diff --git a/frontend/src/basic/OrderPage/index.tsx b/frontend/src/basic/OrderPage/index.tsx index 84cac457..ae5f5b25 100644 --- a/frontend/src/basic/OrderPage/index.tsx +++ b/frontend/src/basic/OrderPage/index.tsx @@ -109,6 +109,7 @@ const OrderPage = (): JSX.Element => { baseUrl={baseUrl} info={info} hasRobot={robot.avatarLoaded} + onClickGenerateRobot={() => navigate('/robot')} /> @@ -164,6 +165,7 @@ const OrderPage = (): JSX.Element => { baseUrl={baseUrl} info={info} hasRobot={robot.avatarLoaded} + onClickGenerateRobot={() => navigate('/robot')} />
@@ -196,6 +198,7 @@ const OrderPage = (): JSX.Element => { baseUrl={baseUrl} info={info} hasRobot={robot.avatarLoaded} + onClickGenerateRobot={() => navigate('/robot')} /> ) diff --git a/frontend/src/components/BookTable/index.tsx b/frontend/src/components/BookTable/index.tsx index 2407589a..5ab9b74c 100644 --- a/frontend/src/components/BookTable/index.tsx +++ b/frontend/src/components/BookTable/index.tsx @@ -344,54 +344,57 @@ const BookTable = ({ }; }, []); - const premiumObj = useCallback((width: number) => { - // coloring premium texts based on 4 params: - // Hardcoded: a sell order at 0% is an outstanding premium - // Hardcoded: a buy order at 10% is an outstanding premium - const sellStandardPremium = 10; - const buyOutstandingPremium = 10; - return { - field: 'premium', - headerName: t('Premium'), - type: 'number', - width: width * fontSize, - renderCell: (params: any) => { - const currencyCode = currencyDict[params.row.currency.toString()]; - let fontColor = `rgb(0,0,0)`; - if (params.row.type === 0) { - var premiumPoint = params.row.premium / buyOutstandingPremium; - premiumPoint = premiumPoint < 0 ? 0 : premiumPoint > 1 ? 1 : premiumPoint; - fontColor = premiumColor( - theme.palette.text.primary, - theme.palette.secondary.dark, - premiumPoint, + const premiumObj = useCallback( + (width: number) => { + // coloring premium texts based on 4 params: + // Hardcoded: a sell order at 0% is an outstanding premium + // Hardcoded: a buy order at 10% is an outstanding premium + const sellStandardPremium = 10; + const buyOutstandingPremium = 10; + return { + field: 'premium', + headerName: t('Premium'), + type: 'number', + width: width * fontSize, + renderCell: (params: any) => { + const currencyCode = currencyDict[params.row.currency.toString()]; + let fontColor = `rgb(0,0,0)`; + if (params.row.type === 0) { + var premiumPoint = params.row.premium / buyOutstandingPremium; + premiumPoint = premiumPoint < 0 ? 0 : premiumPoint > 1 ? 1 : premiumPoint; + fontColor = premiumColor( + theme.palette.text.primary, + theme.palette.secondary.dark, + premiumPoint, + ); + } else { + var premiumPoint = (sellStandardPremium - params.row.premium) / sellStandardPremium; + premiumPoint = premiumPoint < 0 ? 0 : premiumPoint > 1 ? 1 : premiumPoint; + fontColor = premiumColor( + theme.palette.text.primary, + theme.palette.primary.dark, + premiumPoint, + ); + } + const fontWeight = 400 + Math.round(premiumPoint * 5) * 100; + return ( + +
+ + {parseFloat(parseFloat(params.row.premium).toFixed(4)) + '%'} + +
+
); - } else { - var premiumPoint = (sellStandardPremium - params.row.premium) / sellStandardPremium; - premiumPoint = premiumPoint < 0 ? 0 : premiumPoint > 1 ? 1 : premiumPoint; - fontColor = premiumColor( - theme.palette.text.primary, - theme.palette.primary.dark, - premiumPoint, - ); - } - const fontWeight = 400 + Math.round(premiumPoint * 5) * 100; - return ( - -
- - {parseFloat(parseFloat(params.row.premium).toFixed(4)) + '%'} - -
-
- ); - }, - }; - }, []); + }, + }; + }, + [theme], + ); const timerObj = useCallback((width: number) => { return { diff --git a/frontend/src/components/Dialogs/Confirmation.tsx b/frontend/src/components/Dialogs/Confirmation.tsx index ee72dd13..69d02f25 100644 --- a/frontend/src/components/Dialogs/Confirmation.tsx +++ b/frontend/src/components/Dialogs/Confirmation.tsx @@ -1,12 +1,12 @@ import React from 'react'; import { NoRobotDialog, StoreTokenDialog } from '.'; -import { Page } from '../../basic/NavBar'; interface ConfirmationDialogProps { open: boolean; onClose: () => void; onClickDone: () => void; hasRobot: boolean; + onClickGenerateRobot?: () => void; } const ConfirmationDialog = ({ @@ -14,6 +14,7 @@ const ConfirmationDialog = ({ onClose, hasRobot, onClickDone, + onClickGenerateRobot = () => null, }: ConfirmationDialogProps): JSX.Element => { return hasRobot ? ( ) : ( - + ); }; diff --git a/frontend/src/components/Dialogs/NoRobot.tsx b/frontend/src/components/Dialogs/NoRobot.tsx index 9c39a8a4..7fc0a6c4 100644 --- a/frontend/src/components/Dialogs/NoRobot.tsx +++ b/frontend/src/components/Dialogs/NoRobot.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from 'react'; +import React from 'react'; import { useTranslation } from 'react-i18next'; import { Dialog, @@ -8,21 +8,19 @@ import { DialogContentText, Button, } from '@mui/material'; -import { useNavigate } from 'react-router-dom'; interface Props { open: boolean; onClose: () => void; + onClickGenerateRobot?: () => void; } -const NoRobotDialog = ({ open, onClose }: Props): JSX.Element => { +const NoRobotDialog = ({ + open, + onClose, + onClickGenerateRobot = () => null, +}: Props): JSX.Element => { const { t } = useTranslation(); - const navigate = useNavigate(); - - const handleClickGenerate = function () { - onClose(); - navigate('/robot'); - }; return ( @@ -35,7 +33,14 @@ const NoRobotDialog = ({ open, onClose }: Props): JSX.Element => { - + ); diff --git a/frontend/src/components/MakerForm/MakerForm.tsx b/frontend/src/components/MakerForm/MakerForm.tsx index 5a7e9a29..0e2579ab 100644 --- a/frontend/src/components/MakerForm/MakerForm.tsx +++ b/frontend/src/components/MakerForm/MakerForm.tsx @@ -50,6 +50,7 @@ interface MakerFormProps { onReset?: () => void; submitButtonLabel?: string; onOrderCreated?: (id: number) => void; + onClickGenerateRobot?: () => void; } const MakerForm = ({ @@ -60,12 +61,14 @@ const MakerForm = ({ onReset = () => {}, submitButtonLabel = 'Create Order', onOrderCreated = () => null, + onClickGenerateRobot = () => null, }: MakerFormProps): JSX.Element => { const { fav, setFav, limits, fetchLimits, info, maker, setMaker, baseUrl, robot } = useContext(AppContext); const { t } = useTranslation(); const theme = useTheme(); + const [badRequest, setBadRequest] = useState(null); const [amountLimits, setAmountLimits] = useState([1, 1000]); const [satoshisLimits, setSatoshisLimits] = useState([20000, 4000000]); @@ -469,6 +472,7 @@ const MakerForm = ({ }} onClickDone={handleCreateOrder} hasRobot={robot.avatarLoaded} + onClickGenerateRobot={onClickGenerateRobot} />
diff --git a/frontend/src/components/OrderDetails/TakeButton.tsx b/frontend/src/components/OrderDetails/TakeButton.tsx index bc271aa1..f006d463 100644 --- a/frontend/src/components/OrderDetails/TakeButton.tsx +++ b/frontend/src/components/OrderDetails/TakeButton.tsx @@ -32,6 +32,7 @@ interface TakeButtonProps { setOrder: (state: Order) => void; baseUrl: string; info: Info; + onClickGenerateRobot?: () => void; } interface OpenDialogsProps { @@ -40,7 +41,13 @@ interface OpenDialogsProps { } const closeAll = { inactiveMaker: false, confirmation: false }; -const TakeButton = ({ order, setOrder, baseUrl, info }: TakeButtonProps): JSX.Element => { +const TakeButton = ({ + order, + setOrder, + baseUrl, + info, + onClickGenerateRobot = () => null, +}: TakeButtonProps): JSX.Element => { const { t } = useTranslation(); const theme = useTheme(); const { robot } = useContext(AppContext); @@ -336,6 +343,7 @@ const TakeButton = ({ order, setOrder, baseUrl, info }: TakeButtonProps): JSX.El setOpen(closeAll); }} hasRobot={robot.avatarLoaded} + onClickGenerateRobot={onClickGenerateRobot} /> diff --git a/frontend/src/components/OrderDetails/index.tsx b/frontend/src/components/OrderDetails/index.tsx index 3f4411c3..cf396d82 100644 --- a/frontend/src/components/OrderDetails/index.tsx +++ b/frontend/src/components/OrderDetails/index.tsx @@ -44,6 +44,7 @@ interface OrderDetailsProps { info: Info; baseUrl: string; hasRobot: boolean; + onClickGenerateRobot?: () => void; } const OrderDetails = ({ @@ -52,6 +53,7 @@ const OrderDetails = ({ setOrder, baseUrl, hasRobot, + onClickGenerateRobot = () => null, }: OrderDetailsProps): JSX.Element => { const { t } = useTranslation(); const theme = useTheme(); @@ -444,6 +446,7 @@ const OrderDetails = ({ baseUrl={baseUrl} hasRobot={hasRobot} info={info} + onClickGenerateRobot={onClickGenerateRobot} /> ) : ( diff --git a/nodeapp/nginx.conf b/nodeapp/nginx.conf index 89b4e494..5ba520d8 100644 --- a/nodeapp/nginx.conf +++ b/nodeapp/nginx.conf @@ -42,9 +42,10 @@ http { index basic.html; } - location /pro/ { + location /pro { root /usr/src/robosats; try_files $uri $uri/ /pro.html; + index pro.html; } location /static/ {