From 2361b728fcd7c3e71a15c6de5116db222c5e4496 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Fri, 27 Oct 2023 04:00:53 -0700 Subject: [PATCH] Fix (some) lint issues --- frontend/src/basic/BookPage/index.tsx | 4 +-- frontend/src/basic/Main.tsx | 8 +++-- frontend/src/basic/MainDialogs/index.tsx | 2 +- frontend/src/basic/MakerPage/index.tsx | 4 +-- frontend/src/basic/NavBar/NavBar.tsx | 5 ++- frontend/src/basic/OrderPage/index.tsx | 4 +-- frontend/src/basic/RobotPage/Onboarding.tsx | 4 +-- frontend/src/basic/RobotPage/RobotProfile.tsx | 4 +-- frontend/src/basic/RobotPage/TokenInput.tsx | 2 +- frontend/src/basic/RobotPage/index.tsx | 4 +-- frontend/src/components/BookTable/index.tsx | 8 +++-- .../components/Charts/DepthChart/index.tsx | 5 ++- .../src/components/Charts/MapChart/index.tsx | 5 ++- .../Charts/helpers/OrderTooltip/index.tsx | 5 ++- frontend/src/components/Dialogs/Profile.tsx | 8 ++--- .../src/components/FederationTable/index.tsx | 6 ++-- .../src/components/MakerForm/MakerForm.tsx | 4 +-- .../MakerForm/SelectCoordinator.tsx | 2 +- frontend/src/components/Map/index.tsx | 2 +- .../src/components/Notifications/index.tsx | 2 +- .../components/OrderDetails/TakeButton.tsx | 6 ++-- .../src/components/OrderDetails/index.tsx | 6 ++-- frontend/src/components/RobotAvatar/index.tsx | 4 +-- frontend/src/components/TradeBox/index.tsx | 9 +++-- frontend/src/contexts/AppContext.ts | 15 ++++---- frontend/src/contexts/FederationContext.ts | 6 ++-- frontend/src/models/Coordinator.model.ts | 13 +++++-- frontend/src/models/Federation.model.ts | 36 ++++++++++--------- frontend/src/models/Garage.model.ts | 6 ++-- frontend/src/pro/Widgets/Book.tsx | 2 +- frontend/src/pro/Widgets/Depth.tsx | 2 +- frontend/src/pro/Widgets/Maker.tsx | 4 +-- frontend/src/utils/federationLottery.ts | 2 +- 33 files changed, 113 insertions(+), 86 deletions(-) diff --git a/frontend/src/basic/BookPage/index.tsx b/frontend/src/basic/BookPage/index.tsx index bd8d03e3..f0cb9d19 100644 --- a/frontend/src/basic/BookPage/index.tsx +++ b/frontend/src/basic/BookPage/index.tsx @@ -12,8 +12,8 @@ import BookTable from '../../components/BookTable'; import { BarChart, FormatListBulleted, Map } from '@mui/icons-material'; import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import MapChart from '../../components/Charts/MapChart'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; -import { GarageContext, UseGarageStoreType } from '../../contexts/GarageContext'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; +import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; const BookPage = (): JSX.Element => { const { windowSize } = useContext(AppContext); diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index e7c7678b..4d3c9eea 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -8,8 +8,8 @@ import RobotAvatar from '../components/RobotAvatar'; import Notifications from '../components/Notifications'; import { useTranslation } from 'react-i18next'; -import { FederationContext, UseFederationStoreType } from '../contexts/FederationContext'; -import { GarageContext, UseGarageStoreType } from '../contexts/GarageContext'; +import { FederationContext, type UseFederationStoreType } from '../contexts/FederationContext'; +import { GarageContext, type UseGarageStoreType } from '../contexts/GarageContext'; const Router = window.NativeRobosats === undefined ? BrowserRouter : MemoryRouter; @@ -46,7 +46,9 @@ const Main: React.FC = () => { style={{ display: 'none' }} nickname={garage.getRobot().nickname} baseUrl={federation.getCoordinator(sortedCoordinators[0]).getBaseUrl()} - onLoad={() => garage.updateRobot({ avatarLoaded: true })} + onLoad={() => { + garage.updateRobot({ avatarLoaded: true }); + }} /> { const { fav, windowSize, navbarHeight } = useContext(AppContext); diff --git a/frontend/src/basic/NavBar/NavBar.tsx b/frontend/src/basic/NavBar/NavBar.tsx index f88b0f01..869f8156 100644 --- a/frontend/src/basic/NavBar/NavBar.tsx +++ b/frontend/src/basic/NavBar/NavBar.tsx @@ -16,8 +16,8 @@ import { } from '@mui/icons-material'; import RobotAvatar from '../../components/RobotAvatar'; import { AppContext, type UseAppStoreType, closeAll } from '../../contexts/AppContext'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; -import { GarageContext, UseGarageStoreType } from '../../contexts/GarageContext'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; +import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; const NavBar = (): JSX.Element => { const theme = useTheme(); @@ -79,7 +79,6 @@ const NavBar = (): JSX.Element => { const changePage = function (mouseEvent: any, newPage: Page): void { if (newPage === 'none') { - return; } else { handleSlideDirection(page, newPage); setPage(newPage); diff --git a/frontend/src/basic/OrderPage/index.tsx b/frontend/src/basic/OrderPage/index.tsx index 55e4b22b..88e7c242 100644 --- a/frontend/src/basic/OrderPage/index.tsx +++ b/frontend/src/basic/OrderPage/index.tsx @@ -8,8 +8,8 @@ import OrderDetails from '../../components/OrderDetails'; import { apiClient } from '../../services/api'; import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; -import { GarageContext, UseGarageStoreType } from '../../contexts/GarageContext'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; +import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; const OrderPage = (): JSX.Element => { const { windowSize, setOpen, settings, navbarHeight, hostUrl, origin } = diff --git a/frontend/src/basic/RobotPage/Onboarding.tsx b/frontend/src/basic/RobotPage/Onboarding.tsx index 50bdd458..52a623c6 100644 --- a/frontend/src/basic/RobotPage/Onboarding.tsx +++ b/frontend/src/basic/RobotPage/Onboarding.tsx @@ -21,8 +21,8 @@ import RobotAvatar from '../../components/RobotAvatar'; import TokenInput from './TokenInput'; import { genBase62Token } from '../../utils'; import { NewTabIcon } from '../../components/Icons'; -import { AppContext, UseAppStoreType } from '../../contexts/AppContext'; -import { GarageContext, UseGarageStoreType } from '../../contexts/GarageContext'; +import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; +import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; interface OnboardingProps { setView: (state: 'welcome' | 'onboarding' | 'recovery' | 'profile') => void; diff --git a/frontend/src/basic/RobotPage/RobotProfile.tsx b/frontend/src/basic/RobotPage/RobotProfile.tsx index 91b6b611..0593675d 100644 --- a/frontend/src/basic/RobotPage/RobotProfile.tsx +++ b/frontend/src/basic/RobotPage/RobotProfile.tsx @@ -21,8 +21,8 @@ import { type Slot, type Robot } from '../../models'; import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import { genBase62Token } from '../../utils'; import { LoadingButton } from '@mui/lab'; -import { GarageContext, UseGarageStoreType } from '../../contexts/GarageContext'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; +import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; interface RobotProfileProps { robot: Robot; diff --git a/frontend/src/basic/RobotPage/TokenInput.tsx b/frontend/src/basic/RobotPage/TokenInput.tsx index 181e1eca..52d8f620 100644 --- a/frontend/src/basic/RobotPage/TokenInput.tsx +++ b/frontend/src/basic/RobotPage/TokenInput.tsx @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'; import { IconButton, LinearProgress, TextField, Tooltip } from '@mui/material'; import { ContentCopy } from '@mui/icons-material'; import { systemClient } from '../../services/System'; -import { UseGarageStoreType, GarageContext } from '../../contexts/GarageContext'; +import { type UseGarageStoreType, GarageContext } from '../../contexts/GarageContext'; interface TokenInputProps { editable?: boolean; diff --git a/frontend/src/basic/RobotPage/index.tsx b/frontend/src/basic/RobotPage/index.tsx index 5e0cdb38..8a85b894 100644 --- a/frontend/src/basic/RobotPage/index.tsx +++ b/frontend/src/basic/RobotPage/index.tsx @@ -21,8 +21,8 @@ import { TorIcon } from '../../components/Icons'; import { genKey } from '../../pgp'; import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import { validateTokenEntropy } from '../../utils'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; -import { GarageContext, UseGarageStoreType } from '../../contexts/GarageContext'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; +import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; interface RobotPageProps { avatarBaseUrl: string; diff --git a/frontend/src/components/BookTable/index.tsx b/frontend/src/components/BookTable/index.tsx index 91a868dd..17285c54 100644 --- a/frontend/src/components/BookTable/index.tsx +++ b/frontend/src/components/BookTable/index.tsx @@ -37,7 +37,7 @@ import RobotAvatar from '../RobotAvatar'; // Icons import { Fullscreen, FullscreenExit, Refresh } from '@mui/icons-material'; import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; const ClickThroughDataGrid = styled(DataGrid)({ '& .MuiDataGrid-overlayWrapperInner': { @@ -831,7 +831,11 @@ const BookTable = ({ - federation.update()}> + { + federation.update(); + }} + > diff --git a/frontend/src/components/Charts/DepthChart/index.tsx b/frontend/src/components/Charts/DepthChart/index.tsx index d245d1c6..e43d3356 100644 --- a/frontend/src/components/Charts/DepthChart/index.tsx +++ b/frontend/src/components/Charts/DepthChart/index.tsx @@ -26,7 +26,10 @@ import currencyDict from '../../../../static/assets/currencies.json'; import getNivoScheme from '../NivoScheme'; import OrderTooltip from '../helpers/OrderTooltip'; import { type UseAppStoreType, AppContext } from '../../../contexts/AppContext'; -import { FederationContext, UseFederationStoreType } from '../../../contexts/FederationContext'; +import { + FederationContext, + type UseFederationStoreType, +} from '../../../contexts/FederationContext'; interface DepthChartProps { maxWidth: number; diff --git a/frontend/src/components/Charts/MapChart/index.tsx b/frontend/src/components/Charts/MapChart/index.tsx index 7b5e5ad3..3c7439a3 100644 --- a/frontend/src/components/Charts/MapChart/index.tsx +++ b/frontend/src/components/Charts/MapChart/index.tsx @@ -15,7 +15,10 @@ import Map from '../../Map'; import { AppContext, type UseAppStoreType } from '../../../contexts/AppContext'; import { PhotoSizeSelectActual } from '@mui/icons-material'; import { useTranslation } from 'react-i18next'; -import { FederationContext, UseFederationStoreType } from '../../../contexts/FederationContext'; +import { + FederationContext, + type UseFederationStoreType, +} from '../../../contexts/FederationContext'; interface MapChartProps { maxWidth: number; diff --git a/frontend/src/components/Charts/helpers/OrderTooltip/index.tsx b/frontend/src/components/Charts/helpers/OrderTooltip/index.tsx index ef3f01cf..2cb8b558 100644 --- a/frontend/src/components/Charts/helpers/OrderTooltip/index.tsx +++ b/frontend/src/components/Charts/helpers/OrderTooltip/index.tsx @@ -7,7 +7,10 @@ import currencyDict from '../../../../../static/assets/currencies.json'; import { PaymentStringAsIcons } from '../../../PaymentMethods'; import { useTranslation } from 'react-i18next'; import { AppContext, type UseAppStoreType } from '../../../../contexts/AppContext'; -import { FederationContext, UseFederationStoreType } from '../../../../contexts/FederationContext'; +import { + FederationContext, + type UseFederationStoreType, +} from '../../../../contexts/FederationContext'; interface OrderTooltipProps { order: PublicOrder; diff --git a/frontend/src/components/Dialogs/Profile.tsx b/frontend/src/components/Dialogs/Profile.tsx index bf3b4e85..3a232457 100644 --- a/frontend/src/components/Dialogs/Profile.tsx +++ b/frontend/src/components/Dialogs/Profile.tsx @@ -16,9 +16,9 @@ import { import BoltIcon from '@mui/icons-material/Bolt'; import RobotAvatar from '../RobotAvatar'; import RobotInfo from '../RobotInfo'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; -import { GarageContext, UseGarageStoreType } from '../../contexts/GarageContext'; -import { Coordinator } from '../../models'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; +import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; +import { type Coordinator } from '../../models'; interface Props { open: boolean; @@ -97,7 +97,7 @@ const ProfileDialog = ({ open = false, baseUrl, onClose }: Props): JSX.Element = {Object.values(federation.coordinators).map((coordinator: Coordinator): JSX.Element => { - if (garage.getRobot()?.loading === false) { + if (!garage.getRobot()?.loading) { return (
diff --git a/frontend/src/contexts/AppContext.ts b/frontend/src/contexts/AppContext.ts index a8da5a99..c315da0b 100644 --- a/frontend/src/contexts/AppContext.ts +++ b/frontend/src/contexts/AppContext.ts @@ -2,7 +2,7 @@ import { createContext, type Dispatch, useEffect, useState, type SetStateAction import { type Page } from '../basic/NavBar'; import { type OpenDialogs } from '../basic/MainDialogs'; -import { Settings, type Version, type Origin, Favorites } from '../models'; +import { Settings, type Version, type Origin, type Favorites } from '../models'; import { getClientVersion, getHost } from '../utils'; @@ -25,10 +25,13 @@ export interface SlideDirection { export type TorStatus = 'NOTINIT' | 'STARTING' | '"Done"' | 'DONE'; -const entryPage: Page = - window.NativeRobosats === undefined - ? ((window.location.pathname.split('/')[1] ?? 'robot') as Page) - : 'robot'; +export const isNativeRoboSats = !(window.NativeRobosats === undefined); + +const pageFromPath = window.location.pathname.split('/')[1]; +const isPagePathEmpty = pageFromPath === ''; +const entryPage: Page = !isNativeRoboSats + ? ((isPagePathEmpty ? 'robot' : pageFromPath) as Page) + : 'robot'; export const closeAll = { more: false, @@ -73,7 +76,7 @@ const getHostUrl = (network = 'mainnet'): string => { }; const getOrigin = (network = 'mainnet'): Origin => { - let host = getHostUrl(network); + const host = getHostUrl(network); let origin: Origin = 'onion'; if (window.NativeRobosats !== undefined || host.includes('.onion')) { diff --git a/frontend/src/contexts/FederationContext.ts b/frontend/src/contexts/FederationContext.ts index 55d9980e..7627216a 100644 --- a/frontend/src/contexts/FederationContext.ts +++ b/frontend/src/contexts/FederationContext.ts @@ -8,12 +8,12 @@ import { useContext, } from 'react'; -import { Coordinator, type Order, Federation } from '../models'; +import { type Coordinator, type Order, Federation } from '../models'; import { federationLottery } from '../utils'; -import { AppContext, UseAppStoreType } from './AppContext'; -import { GarageContext, UseGarageStoreType } from './GarageContext'; +import { AppContext, type UseAppStoreType } from './AppContext'; +import { GarageContext, type UseGarageStoreType } from './GarageContext'; // Refresh delays (ms) according to Order status const statusToDelay = [ diff --git a/frontend/src/models/Coordinator.model.ts b/frontend/src/models/Coordinator.model.ts index f542ecf8..a222d061 100644 --- a/frontend/src/models/Coordinator.model.ts +++ b/frontend/src/models/Coordinator.model.ts @@ -1,5 +1,12 @@ import { sha256 } from 'js-sha256'; -import { type Robot, type LimitList, type PublicOrder, Settings, Order, Garage } from '.'; +import { + type Robot, + type LimitList, + type PublicOrder, + type Settings, + type Order, + type Garage, +} from '.'; import { apiClient } from '../services/api'; import { hexToBase91, validateTokenEntropy } from '../utils'; import { compareUpdateLimit } from './Limit.model'; @@ -182,7 +189,7 @@ export class Coordinator { apiClient .get(this.url, `${this.basePath}/api/limits/`) .then((data) => { - if (data) { + if (data != null) { const newLimits = data as LimitList; for (const currency in this.limits) { @@ -232,7 +239,7 @@ export class Coordinator { }; isUpdated = () => { - return ((this.loadingBook === this.loadingInfo) === this.loadingLimits) === false; + return !((this.loadingBook === this.loadingInfo) === this.loadingLimits); }; getBaseUrl = () => { diff --git a/frontend/src/models/Federation.model.ts b/frontend/src/models/Federation.model.ts index 9f653cfc..f3bc8326 100644 --- a/frontend/src/models/Federation.model.ts +++ b/frontend/src/models/Federation.model.ts @@ -1,15 +1,15 @@ import { Coordinator, - Exchange, - Garage, - Origin, - PublicOrder, - Robot, - Settings, + type Exchange, + type Garage, + type Origin, + type PublicOrder, + type Robot, + type Settings, defaultExchange, } from '.'; import defaultFederation from '../../static/federation.json'; -import { CurrentOrder } from '../contexts/FederationContext'; +import { type CurrentOrder } from '../contexts/FederationContext'; import { updateExchangeInfo } from './Exchange.model'; type FederationHooks = 'onCoordinatorUpdate' | 'onFederationReady'; @@ -40,7 +40,7 @@ export class Federation { public book: PublicOrder[]; public loading: boolean; - public hooks: Record void)[]>; + public hooks: Record void>>; // Hooks registerHook = (hookName: FederationHooks, fn: () => void): void => { @@ -48,7 +48,9 @@ export class Federation { }; triggerHook = (hookName: FederationHooks): void => { - this.hooks[hookName]?.forEach((fn) => fn()); + this.hooks[hookName]?.forEach((fn) => { + fn(); + }); }; onCoordinatorSaved = (shortAlias: string) => { @@ -68,18 +70,18 @@ export class Federation { this.onCoordinatorSaved(shortAlias); }; this.loading = true; - Object.values(this.coordinators).forEach((coor) => - coor.start(origin, settings, hostUrl, onCoordinatorStarted), - ); + Object.values(this.coordinators).forEach(async (coor) => { + await coor.start(origin, settings, hostUrl, onCoordinatorStarted); + }); }; update = (): void => { this.loading = false; - Object.values(this.coordinators).forEach((coor) => - coor.update(() => { + Object.values(this.coordinators).forEach(async (coor) => { + await coor.update(() => { this.onCoordinatorSaved(coor.shortAlias); - }), - ); + }); + }); }; updateExchange = () => { @@ -108,7 +110,7 @@ export class Federation { return currentOrder; }; - //Coordinators + // Coordinators getCoordinator = (shortAlias: string): Coordinator => { return this.coordinators[shortAlias]; }; diff --git a/frontend/src/models/Garage.model.ts b/frontend/src/models/Garage.model.ts index f2a9a19b..c7701dd6 100644 --- a/frontend/src/models/Garage.model.ts +++ b/frontend/src/models/Garage.model.ts @@ -39,7 +39,7 @@ class Garage { slots: Slot[]; currentSlot: number; - hooks: Record void)[]>; + hooks: Record void>>; // Hooks registerHook = (hookName: GarageHooks, fn: () => void): void => { @@ -47,7 +47,9 @@ class Garage { }; triggerHook = (hookName: GarageHooks): void => { - this.hooks[hookName]?.forEach((fn) => fn()); + this.hooks[hookName]?.forEach((fn) => { + fn(); + }); }; // Storage diff --git a/frontend/src/pro/Widgets/Book.tsx b/frontend/src/pro/Widgets/Book.tsx index 039a9f3f..0feb7381 100644 --- a/frontend/src/pro/Widgets/Book.tsx +++ b/frontend/src/pro/Widgets/Book.tsx @@ -3,7 +3,7 @@ import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import { Paper } from '@mui/material'; import BookTable from '../../components/BookTable'; import { type GridItem } from 'react-grid-layout'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; interface BookWidgetProps { layout: GridItem; diff --git a/frontend/src/pro/Widgets/Depth.tsx b/frontend/src/pro/Widgets/Depth.tsx index ed2ba4ce..df408563 100644 --- a/frontend/src/pro/Widgets/Depth.tsx +++ b/frontend/src/pro/Widgets/Depth.tsx @@ -2,7 +2,7 @@ import React, { useContext } from 'react'; import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import { Paper } from '@mui/material'; import DepthChart from '../../components/Charts/DepthChart'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; interface DepthChartWidgetProps { layout: any; diff --git a/frontend/src/pro/Widgets/Maker.tsx b/frontend/src/pro/Widgets/Maker.tsx index 6cd9b8f6..bdee616a 100644 --- a/frontend/src/pro/Widgets/Maker.tsx +++ b/frontend/src/pro/Widgets/Maker.tsx @@ -3,8 +3,8 @@ import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import MakerForm from '../../components/MakerForm'; import { Paper } from '@mui/material'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; -import { GarageContext, UseGarageStoreType } from '../../contexts/GarageContext'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; +import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; interface MakerWidgetProps { style?: React.StyleHTMLAttributes; diff --git a/frontend/src/utils/federationLottery.ts b/frontend/src/utils/federationLottery.ts index da90385c..4768e256 100644 --- a/frontend/src/utils/federationLottery.ts +++ b/frontend/src/utils/federationLottery.ts @@ -11,7 +11,7 @@ // donate to the development fund. This is the only way envisioned to incentivize // donations to the development fund. -import { Federation } from '../models'; +import { type Federation } from '../models'; export default function federationLottery(federation: Federation): string[] { // Create an array to store the coordinator short aliases and their corresponding weights (chance)