From 4eb46f1e1666d952930295fa08c42b9c56e94d03 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Wed, 1 Nov 2023 06:28:14 -0700 Subject: [PATCH] Fix lint issues --- frontend/src/App.tsx | 2 +- frontend/src/basic/BookPage/index.tsx | 2 +- frontend/src/basic/Main.tsx | 2 +- frontend/src/basic/MainDialogs/index.tsx | 8 ++++++-- frontend/src/basic/NavBar/NavBar.tsx | 7 +++---- frontend/src/basic/OrderPage/index.tsx | 4 ++-- frontend/src/basic/RobotPage/Recovery.tsx | 1 - frontend/src/basic/RobotPage/RobotProfile.tsx | 4 ++-- frontend/src/basic/RobotPage/index.tsx | 3 +-- frontend/src/components/BookTable/index.tsx | 14 ++++++++------ .../components/Charts/DepthChart/index.tsx | 4 ++-- .../src/components/Charts/MapChart/index.tsx | 1 - .../Charts/helpers/OrderTooltip/index.tsx | 2 +- .../src/components/Dialogs/Coordinator.tsx | 2 +- frontend/src/components/Dialogs/F2fMap.tsx | 4 ++-- .../src/components/FederationTable/index.tsx | 2 +- .../src/components/MakerForm/MakerForm.tsx | 19 +++++++++---------- 17 files changed, 41 insertions(+), 40 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index d5690c03..2f61913d 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,4 +1,4 @@ -import React, { StrictMode, Suspense, useState } from 'react'; +import React, { StrictMode, Suspense } from 'react'; import ReactDOM from 'react-dom/client'; import Main from './basic/Main'; import { CssBaseline, ThemeProvider } from '@mui/material'; diff --git a/frontend/src/basic/BookPage/index.tsx b/frontend/src/basic/BookPage/index.tsx index f0cb9d19..a4664bfb 100644 --- a/frontend/src/basic/BookPage/index.tsx +++ b/frontend/src/basic/BookPage/index.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from 'react'; +import React, { useContext, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, Grid, ButtonGroup, Dialog, Box } from '@mui/material'; import { useNavigate } from 'react-router-dom'; diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index 4d3c9eea..283256fd 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -30,7 +30,7 @@ const MainBox = styled(Box)((props) => ({ const Main: React.FC = () => { const { t } = useTranslation(); - const { settings, page, slideDirection, setOpen, windowSize, navbarHeight, hostUrl, origin } = + const { settings, page, slideDirection, setOpen, windowSize, navbarHeight, hostUrl } = useContext(AppContext); const { federation, sortedCoordinators } = useContext(FederationContext); const { garage } = useContext(GarageContext); diff --git a/frontend/src/basic/MainDialogs/index.tsx b/frontend/src/basic/MainDialogs/index.tsx index 2ee9119a..7967ef8c 100644 --- a/frontend/src/basic/MainDialogs/index.tsx +++ b/frontend/src/basic/MainDialogs/index.tsx @@ -35,7 +35,7 @@ const MainDialogs = (): JSX.Element => { const [maxAmount, setMaxAmount] = useState('...loading...'); useEffect(() => { - if (focusedCoordinator) { + if (focusedCoordinator !== null && focusedCoordinator !== '') { const limits = federation.getCoordinator(focusedCoordinator).limits; if (limits[1000] !== undefined) { setMaxAmount(pn(limits[1000].max_amount * 100000000)); @@ -108,7 +108,11 @@ const MainDialogs = (): JSX.Element => { onClose={() => { setOpen(closeAll); }} - coordinator={focusedCoordinator ? federation.getCoordinator(focusedCoordinator) : null} + coordinator={ + focusedCoordinator !== null && focusedCoordinator !== '' + ? federation.getCoordinator(focusedCoordinator) + : null + } /> ); diff --git a/frontend/src/basic/NavBar/NavBar.tsx b/frontend/src/basic/NavBar/NavBar.tsx index 240afae3..3a01e0d2 100644 --- a/frontend/src/basic/NavBar/NavBar.tsx +++ b/frontend/src/basic/NavBar/NavBar.tsx @@ -60,7 +60,7 @@ const NavBar = (): JSX.Element => { useEffect(() => { // change tab (page) into the current route const pathPage: Page | string = location.pathname.split('/')[1]; - if (pathPage === 'index.html' || !pathPage) { + if (pathPage === 'index.html') { navigate('/robot'); setPage('robot'); } @@ -78,8 +78,7 @@ const NavBar = (): JSX.Element => { }; const changePage = function (mouseEvent: any, newPage: Page): void { - if (newPage === 'none') { - } else { + if (newPage !== 'none') { handleSlideDirection(page, newPage); setPage(newPage); const param = @@ -121,7 +120,7 @@ const NavBar = (): JSX.Element => { setOpen({ ...closeAll, profile: !open.profile }); }} icon={ - garage.getRobot().nickname && garage.getRobot().avatarLoaded ? ( + garage.getRobot().nickname != null && garage.getRobot().avatarLoaded ? ( { }, [params]); const onClickCoordinator = function (): void { - if (currentOrder.shortAlias) { + if (currentOrder.shortAlias != null) { setFocusedCoordinator(currentOrder.shortAlias); } setOpen((open) => { @@ -55,7 +55,7 @@ const OrderPage = (): JSX.Element => { const renewOrder = function (): void { const order = currentOrder.order; - if (order !== null && focusedCoordinator) { + if (order !== null && focusedCoordinator != null) { const body = { type: order.type, currency: order.currency, diff --git a/frontend/src/basic/RobotPage/Recovery.tsx b/frontend/src/basic/RobotPage/Recovery.tsx index cb7fb05d..4503ddf7 100644 --- a/frontend/src/basic/RobotPage/Recovery.tsx +++ b/frontend/src/basic/RobotPage/Recovery.tsx @@ -1,7 +1,6 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import { Button, Grid, Typography } from '@mui/material'; -import { type Robot } from '../../models'; import TokenInput from './TokenInput'; import Key from '@mui/icons-material/Key'; diff --git a/frontend/src/basic/RobotPage/RobotProfile.tsx b/frontend/src/basic/RobotPage/RobotProfile.tsx index 0593675d..68166169 100644 --- a/frontend/src/basic/RobotPage/RobotProfile.tsx +++ b/frontend/src/basic/RobotPage/RobotProfile.tsx @@ -55,7 +55,7 @@ const RobotProfile = ({ const [loading, setLoading] = useState(true); useEffect(() => { - if (garage.getRobot().nickname && garage.getRobot().avatarLoaded) { + if (garage.getRobot().nickname != null && garage.getRobot().avatarLoaded) { setLoading(false); } }, [robotUpdatedAt]); @@ -81,7 +81,7 @@ const RobotProfile = ({ sx={{ width: '100%' }} > - {garage.getRobot().avatarLoaded && garage.getRobot().nickname ? ( + {garage.getRobot().avatarLoaded && garage.getRobot().nickname != null ? (
{ pubKey: key.publicKeyArmored, encPrivKey: key.encryptedPrivateKeyArmored, }); - federation.fetchRobot(garage, slot); + void federation.fetchRobot(garage, slot); }) .catch((error) => { console.error('Error:', error); diff --git a/frontend/src/components/BookTable/index.tsx b/frontend/src/components/BookTable/index.tsx index 17285c54..677c6ed8 100644 --- a/frontend/src/components/BookTable/index.tsx +++ b/frontend/src/components/BookTable/index.tsx @@ -206,9 +206,10 @@ const BookTable = ({ headerName: t('Robot'), width: width * fontSize, renderCell: (params: any) => { - const { url, basePath } = federation - .getCoordinator(params.row.coordinatorShortAlias) - ?.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); + const { url, basePath } = + federation + .getCoordinator(params.row.coordinatorShortAlias) + ?.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl) ?? {}; return ( { - const { url, basePath } = federation - .getCoordinator(params.row.coordinatorShortAlias) - ?.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); + const { url, basePath } = + federation + .getCoordinator(params.row.coordinatorShortAlias) + ?.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl) ?? {}; return (
= ({ // We need to transform all currencies to the same base (ex. USD), we don't have the exchange rate // for EUR -> USD, but we know the rate of both to BTC, so we get advantage of it and apply a // simple rule of three - if (order.coordinatorShortAlias) { + if (order.coordinatorShortAlias != null) { const limits = federation.getCoordinator(order.coordinatorShortAlias).limits; order.base_amount = (order.price * limits[currencyCode].price) / limits[order.currency].price; diff --git a/frontend/src/components/Charts/MapChart/index.tsx b/frontend/src/components/Charts/MapChart/index.tsx index 3c7439a3..654dbbe4 100644 --- a/frontend/src/components/Charts/MapChart/index.tsx +++ b/frontend/src/components/Charts/MapChart/index.tsx @@ -12,7 +12,6 @@ import { Tooltip, } from '@mui/material'; import Map from '../../Map'; -import { AppContext, type UseAppStoreType } from '../../../contexts/AppContext'; import { PhotoSizeSelectActual } from '@mui/icons-material'; import { useTranslation } from 'react-i18next'; import { diff --git a/frontend/src/components/Charts/helpers/OrderTooltip/index.tsx b/frontend/src/components/Charts/helpers/OrderTooltip/index.tsx index 2cb8b558..c524eee8 100644 --- a/frontend/src/components/Charts/helpers/OrderTooltip/index.tsx +++ b/frontend/src/components/Charts/helpers/OrderTooltip/index.tsx @@ -26,7 +26,7 @@ const OrderTooltip: React.FC = ({ order }) => { const coordinator = federation.getCoordinator(coordinatorAlias); const baseUrl = coordinator?.[network]?.[origin] ?? ''; - return order?.id && baseUrl !== '' ? ( + return order?.id != null && baseUrl !== '' ? ( diff --git a/frontend/src/components/Dialogs/Coordinator.tsx b/frontend/src/components/Dialogs/Coordinator.tsx index ab15468a..46c3d82a 100644 --- a/frontend/src/components/Dialogs/Coordinator.tsx +++ b/frontend/src/components/Dialogs/Coordinator.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from 'react'; +import React, { useContext, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { diff --git a/frontend/src/components/Dialogs/F2fMap.tsx b/frontend/src/components/Dialogs/F2fMap.tsx index 20e5c2da..004af5a4 100644 --- a/frontend/src/components/Dialogs/F2fMap.tsx +++ b/frontend/src/components/Dialogs/F2fMap.tsx @@ -42,13 +42,13 @@ const F2fMapDialog = ({ const [openWarningDialog, setOpenWarningDialog] = useState(false); const onSave: () => void = () => { - if (position?.[0] && position?.[1]) { + if (position?.[0] != null && position?.[1] != null) { onClose([position[0] + Math.random() * 0.1 - 0.05, position[1] + Math.random() * 0.1 - 0.05]); } }; useEffect(() => { - if (open && latitude && longitude) { + if (open && latitude != null && longitude != null) { setPosition([latitude, longitude]); } else { setPosition(undefined); diff --git a/frontend/src/components/FederationTable/index.tsx b/frontend/src/components/FederationTable/index.tsx index ec9f10e0..18befdd9 100644 --- a/frontend/src/components/FederationTable/index.tsx +++ b/frontend/src/components/FederationTable/index.tsx @@ -213,7 +213,7 @@ const FederationTable = ({ const { columns, width } = filteredColumns(); const onEnableChange = function (shortAlias: string): void { - if (federation.getCoordinator(shortAlias).enabled) { + if (federation.getCoordinator(shortAlias).enabled === true) { federation.disableCoordinator(shortAlias); } else { federation.enableCoordinator(shortAlias); diff --git a/frontend/src/components/MakerForm/MakerForm.tsx b/frontend/src/components/MakerForm/MakerForm.tsx index 0061d91d..2df0957a 100644 --- a/frontend/src/components/MakerForm/MakerForm.tsx +++ b/frontend/src/components/MakerForm/MakerForm.tsx @@ -93,7 +93,7 @@ const MakerForm = ({ useEffect(() => { setCurrencyCode(currencyDict[fav.currency === 0 ? 1 : fav.currency]); - if (focusedCoordinator) { + if (focusedCoordinator != null) { const newLimits = federation.getCoordinator(focusedCoordinator).limits; if (Object.keys(newLimits).length !== 0) { updateAmountLimits(newLimits, fav.currency, maker.premium); @@ -280,9 +280,10 @@ const MakerForm = ({ }; const handleCreateOrder = function (): void { - const { url, basePath } = federation - .getCoordinator(maker.coordinator) - ?.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); + const { url, basePath } = + federation + .getCoordinator(maker.coordinator) + ?.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl) ?? {}; const auth = { tokenSHA256: garage.getRobot().tokenSHA256, @@ -292,7 +293,7 @@ const MakerForm = ({ }, }; - if (!disableRequest && focusedCoordinator) { + if (!disableRequest && focusedCoordinator != null) { setSubmittingRequest(true); const body = { type: fav.type === 0 ? 1 : 0, @@ -312,9 +313,7 @@ const MakerForm = ({ latitude: maker.latitude, longitude: maker.longitude, }; - const { url } = federation - .getCoordinator(focusedCoordinator) - .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); + apiClient .post(url, `${basePath}/api/make/`, body, auth) .then((data: any) => { @@ -447,7 +446,7 @@ const MakerForm = ({ }; const amountLabel = useMemo(() => { - if (!focusedCoordinator) return; + if (!(focusedCoordinator != null)) return; const info = federation.getCoordinator(focusedCoordinator)?.info; const defaultRoutingBudget = 0.001; @@ -587,7 +586,7 @@ const MakerForm = ({ if (pos != null) handleAddLocation(pos); setOpenWorldmap(false); }} - zoom={maker.latitude && maker.longitude ? 6 : undefined} + zoom={maker.latitude != null && maker.longitude != null ? 6 : undefined} />