diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index e26e30ed..a46c557f 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,7 +1,7 @@ import React, { StrictMode, Suspense } from 'react'; import ReactDOM from 'react-dom/client'; import Main from './basic/Main'; -import { CssBaseline, Grid } from '@mui/material'; +import { CssBaseline } from '@mui/material'; import HostAlert from './components/HostAlert'; import TorConnectionBadge from './components/TorConnection'; @@ -16,7 +16,7 @@ import { FederationContextProvider } from './contexts/FederationContext'; import NotificationSwitchBadge from './components/NotificationSwitch'; const App = (): JSX.Element => { - const [client, _view] = window.RobosatsSettings.split('-'); + const [client] = window.RobosatsSettings.split('-'); return ( diff --git a/frontend/src/basic/Main.tsx b/frontend/src/basic/Main.tsx index 04b4db28..7c555e96 100644 --- a/frontend/src/basic/Main.tsx +++ b/frontend/src/basic/Main.tsx @@ -12,7 +12,7 @@ import { GarageContext, type UseGarageStoreType } from '../contexts/GarageContex import Routes from './Routes'; const getRouter = (): any => { - const [client, _view] = window.RobosatsSettings.split('-'); + const [client] = window.RobosatsSettings.split('-'); if (client === 'web') { return BrowserRouter; } else if (client === 'desktop') { diff --git a/frontend/src/basic/MakerPage/index.tsx b/frontend/src/basic/MakerPage/index.tsx index 869daa74..0604e170 100644 --- a/frontend/src/basic/MakerPage/index.tsx +++ b/frontend/src/basic/MakerPage/index.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useMemo, useState } from 'react'; +import React, { useContext, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import { Grid, Paper, Collapse, Typography } from '@mui/material'; @@ -13,7 +13,7 @@ import { FederationContext, type UseFederationStoreType } from '../../contexts/F import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; const MakerPage = (): JSX.Element => { - const { fav, windowSize, navbarHeight, page } = useContext(AppContext); + const { fav, windowSize, navbarHeight } = useContext(AppContext); const { federation } = useContext(FederationContext); const { garage, maker } = useContext(GarageContext); const { t } = useTranslation(); diff --git a/frontend/src/basic/RobotPage/Onboarding.tsx b/frontend/src/basic/RobotPage/Onboarding.tsx index 59373aa0..452d3664 100644 --- a/frontend/src/basic/RobotPage/Onboarding.tsx +++ b/frontend/src/basic/RobotPage/Onboarding.tsx @@ -23,7 +23,7 @@ import { genBase62Token } from '../../utils'; import { NewTabIcon } from '../../components/Icons'; import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; -import { UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; +import { type UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; 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 8a5eec1d..9cba4f4f 100644 --- a/frontend/src/basic/RobotPage/RobotProfile.tsx +++ b/frontend/src/basic/RobotPage/RobotProfile.tsx @@ -13,8 +13,7 @@ import { useTheme, type SelectChangeEvent, } from '@mui/material'; -import { Key } from '@mui/icons-material'; -import { Bolt, Add, DeleteSweep, Download } from '@mui/icons-material'; +import { Key, Bolt, Add, DeleteSweep, Download } from '@mui/icons-material'; import RobotAvatar from '../../components/RobotAvatar'; import TokenInput from './TokenInput'; import { type Slot, type Robot } from '../../models'; @@ -22,7 +21,7 @@ import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import { genBase62Token } from '../../utils'; import { LoadingButton } from '@mui/lab'; import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; -import { UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; +import { type UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; interface RobotProfileProps { robot: Robot; diff --git a/frontend/src/basic/RobotPage/Welcome.tsx b/frontend/src/basic/RobotPage/Welcome.tsx index a812bea8..1a198643 100644 --- a/frontend/src/basic/RobotPage/Welcome.tsx +++ b/frontend/src/basic/RobotPage/Welcome.tsx @@ -4,10 +4,10 @@ import { Box, Button, Grid, Typography, useTheme } from '@mui/material'; import { RoboSatsTextIcon } from '../../components/Icons'; import { FastForward, RocketLaunch, Key } from '@mui/icons-material'; import { genBase62Token } from '../../utils'; -import { UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; -import { UseGarageStoreType, GarageContext } from '../../contexts/GarageContext'; +import { type UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; +import { type UseGarageStoreType, GarageContext } from '../../contexts/GarageContext'; import { useNavigate } from 'react-router-dom'; -import { UseAppStoreType, AppContext } from '../../contexts/AppContext'; +import { type UseAppStoreType, AppContext } from '../../contexts/AppContext'; interface WelcomeProps { setView: (state: 'welcome' | 'onboarding' | 'recovery' | 'profile') => void; diff --git a/frontend/src/basic/SettingsPage/index.tsx b/frontend/src/basic/SettingsPage/index.tsx index 2639fdab..177ccffe 100644 --- a/frontend/src/basic/SettingsPage/index.tsx +++ b/frontend/src/basic/SettingsPage/index.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from 'react'; +import React, { useContext, useState } from 'react'; import { Box, Button, Grid, List, ListItem, Paper, TextField, Typography } from '@mui/material'; import SettingsForm from '../../components/SettingsForm'; import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; @@ -8,7 +8,7 @@ import { FederationContext, type UseFederationStoreType } from '../../contexts/F import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; const SettingsPage = (): JSX.Element => { - const { windowSize, navbarHeight, page } = useContext(AppContext); + const { windowSize, navbarHeight } = useContext(AppContext); const { federation, addNewCoordinator } = useContext(FederationContext); const { garage } = useContext(GarageContext); const maxHeight = (windowSize.height - navbarHeight) * 0.85 - 3; diff --git a/frontend/src/components/BookTable/index.tsx b/frontend/src/components/BookTable/index.tsx index 1401530d..b29fcd43 100644 --- a/frontend/src/components/BookTable/index.tsx +++ b/frontend/src/components/BookTable/index.tsx @@ -581,9 +581,10 @@ const BookTable = ({ width: width * fontSize, renderCell: (params: any) => { const coordinator = federation.getCoordinator(params.row.coordinatorShortAlias); - const amount = Boolean(params.row.has_range) - ? parseFloat(params.row.max_amount) - : parseFloat(params.row.amount); + const amount = + params.row.has_range === true + ? parseFloat(params.row.max_amount) + : parseFloat(params.row.amount); const premium = parseFloat(params.row.premium); const price = (coordinator.limits[params.row.currency.toString()]?.price ?? 1) * (1 + premium / 100); diff --git a/frontend/src/components/Dialogs/Coordinator.tsx b/frontend/src/components/Dialogs/Coordinator.tsx index 05d49eb3..614e7a14 100644 --- a/frontend/src/components/Dialogs/Coordinator.tsx +++ b/frontend/src/components/Dialogs/Coordinator.tsx @@ -68,9 +68,9 @@ import { } from '../Icons'; import { AppContext } from '../../contexts/AppContext'; import { systemClient } from '../../services/System'; -import Coordinator, { type Badges } from '../../models/Coordinator.model'; +import type Coordinator from '../../models/Coordinator.model'; +import { type Badges } from '../../models/Coordinator.model'; import { type UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; -import { width } from '@mui/system'; interface Props { open: boolean; diff --git a/frontend/src/components/Dialogs/Exchange.tsx b/frontend/src/components/Dialogs/Exchange.tsx index cbf616b1..91f8ed5d 100644 --- a/frontend/src/components/Dialogs/Exchange.tsx +++ b/frontend/src/components/Dialogs/Exchange.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useState } from 'react'; +import React, { useContext } from 'react'; import { useTranslation } from 'react-i18next'; import { @@ -34,7 +34,7 @@ interface Props { const ExchangeDialog = ({ open = false, onClose }: Props): JSX.Element => { const { t } = useTranslation(); - const { federation, federationUpdatedAt } = useContext(FederationContext); + const { federation } = useContext(FederationContext); return ( diff --git a/frontend/src/components/Dialogs/Recovery.tsx b/frontend/src/components/Dialogs/Recovery.tsx index 9d3bdf12..4121a7ac 100644 --- a/frontend/src/components/Dialogs/Recovery.tsx +++ b/frontend/src/components/Dialogs/Recovery.tsx @@ -3,9 +3,9 @@ import { useTranslation } from 'react-i18next'; import { Dialog, DialogContent, Typography, Button, Grid } from '@mui/material'; import TokenInput from '../../basic/RobotPage/TokenInput'; import Key from '@mui/icons-material/Key'; -import { UseAppStoreType, AppContext } from '../../contexts/AppContext'; -import { UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; -import { UseGarageStoreType, GarageContext } from '../../contexts/GarageContext'; +import { type UseAppStoreType, AppContext } from '../../contexts/AppContext'; +import { type UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; +import { type UseGarageStoreType, GarageContext } from '../../contexts/GarageContext'; interface Props { setView: (state: 'welcome' | 'onboarding' | 'recovery' | 'profile') => void; @@ -24,7 +24,7 @@ const RecoveryDialog = ({ setInputToken, setView }: Props): JSX.Element => { setRecoveryToken(''); }, [open.recovery]); - const onClickRecover = () => { + const onClickRecover = (): void => { garage.createRobot(federation, recoveryToken); setInputToken(recoveryToken.trim()); setView('profile'); diff --git a/frontend/src/components/FederationTable/index.tsx b/frontend/src/components/FederationTable/index.tsx index 3f18b499..820c03b1 100644 --- a/frontend/src/components/FederationTable/index.tsx +++ b/frontend/src/components/FederationTable/index.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useState, useContext, useMemo } from 'react'; +import React, { useCallback, useEffect, useState, useContext } from 'react'; import { useTranslation } from 'react-i18next'; import { Box, useTheme, Checkbox, CircularProgress, Typography, Grid } from '@mui/material'; import { DataGrid, type GridColDef, type GridValidRowModel } from '@mui/x-data-grid'; @@ -22,7 +22,7 @@ const FederationTable = ({ }: FederationTableProps): JSX.Element => { const { t } = useTranslation(); const { federation, federationUpdatedAt } = useContext(FederationContext); - const { setOpen, settings } = useContext(AppContext); + const { setOpen } = useContext(AppContext); const theme = useTheme(); const [pageSize, setPageSize] = useState(0); diff --git a/frontend/src/components/NotificationSwitch/index.tsx b/frontend/src/components/NotificationSwitch/index.tsx index 2d35a348..4979fcf5 100644 --- a/frontend/src/components/NotificationSwitch/index.tsx +++ b/frontend/src/components/NotificationSwitch/index.tsx @@ -1,7 +1,7 @@ import React, { useContext, useEffect, useState } from 'react'; import { Box, CircularProgress, useTheme } from '@mui/material'; import { NotificationsActive, NotificationsOff } from '@mui/icons-material'; -import { AppContext, UseAppStoreType } from '../../contexts/AppContext'; +import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import { systemClient } from '../../services/System'; const NotificationSwitchBadge = (): JSX.Element => { @@ -14,7 +14,7 @@ const NotificationSwitchBadge = (): JSX.Element => { setStopNotifications(settings.stopNotifications); }, [settings.stopNotifications]); - const onClick = () => { + const onClick = (): void => { if (torStatus === 'ON' || !settings.useProxy) { setSettings({ ...settings, stopNotifications: !settings.stopNotifications }); systemClient.setItem('settings_stop_notifications', String(!settings.stopNotifications)); diff --git a/frontend/src/components/SettingsForm/index.tsx b/frontend/src/components/SettingsForm/index.tsx index 5a0f5057..0c72cfc1 100644 --- a/frontend/src/components/SettingsForm/index.tsx +++ b/frontend/src/components/SettingsForm/index.tsx @@ -23,16 +23,12 @@ import { DarkMode, SettingsOverscan, Link, - AttachMoney, QrCode, SettingsInputAntenna, - Dns, } from '@mui/icons-material'; import { systemClient } from '../../services/System'; import { TorIcon } from '../Icons'; -import SwapCalls from '@mui/icons-material/SwapCalls'; import { apiClient } from '../../services/api'; -import Nostr from '../Icons/Nostr'; interface SettingsFormProps { dense?: boolean; diff --git a/frontend/src/components/TorConnection/index.tsx b/frontend/src/components/TorConnection/index.tsx index 223113b1..4b20e1e6 100644 --- a/frontend/src/components/TorConnection/index.tsx +++ b/frontend/src/components/TorConnection/index.tsx @@ -2,7 +2,7 @@ import React, { useContext } from 'react'; import { Box, CircularProgress, Tooltip } from '@mui/material'; import { TorIcon } from '../Icons'; import { useTranslation } from 'react-i18next'; -import { AppContext, UseAppStoreType } from '../../contexts/AppContext'; +import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; interface TorIndicatorProps { color: 'inherit' | 'error' | 'warning' | 'success' | 'primary' | 'secondary' | 'info' | undefined; diff --git a/frontend/src/components/TradeBox/Forms/LightningPayout.tsx b/frontend/src/components/TradeBox/Forms/LightningPayout.tsx index 04488293..910850eb 100644 --- a/frontend/src/components/TradeBox/Forms/LightningPayout.tsx +++ b/frontend/src/components/TradeBox/Forms/LightningPayout.tsx @@ -33,7 +33,7 @@ import { apiClient } from '../../../services/api'; import { systemClient } from '../../../services/System'; import lnproxies from '../../../../static/lnproxies.json'; -import { UseAppStoreType, AppContext } from '../../../contexts/AppContext'; +import { type UseAppStoreType, AppContext } from '../../../contexts/AppContext'; let filteredProxies: Array> = []; export interface LightningForm { invoice: string; diff --git a/frontend/src/components/TradeBox/TradeSummary.tsx b/frontend/src/components/TradeBox/TradeSummary.tsx index 2f614f86..cc7e607b 100644 --- a/frontend/src/components/TradeBox/TradeSummary.tsx +++ b/frontend/src/components/TradeBox/TradeSummary.tsx @@ -37,7 +37,7 @@ import { } from '../Icons'; import { type TradeCoordinatorSummary, type TradeRobotSummary } from '../../models/Order.model'; import { systemClient } from '../../services/System'; -import { UseAppStoreType, AppContext } from '../../contexts/AppContext'; +import { type UseAppStoreType, AppContext } from '../../contexts/AppContext'; interface Props { isMaker: boolean; diff --git a/frontend/src/contexts/AppContext.tsx b/frontend/src/contexts/AppContext.tsx index 91299b11..19d4abc9 100644 --- a/frontend/src/contexts/AppContext.tsx +++ b/frontend/src/contexts/AppContext.tsx @@ -76,13 +76,13 @@ const makeTheme = function (settings: Settings): Theme { }; const getHostUrl = (network = 'mainnet'): string => { - const [client, _view] = window.RobosatsSettings.split('-'); + const [client] = window.RobosatsSettings.split('-'); const randomAlias = Object.keys(defaultFederation)[ Math.floor(Math.random() * Object.keys(defaultFederation).length) ]; - let host = defaultFederation[randomAlias][network].onion; - let protocol = 'http:'; + let host: string = defaultFederation[randomAlias][network].onion; + let protocol: string = 'http:'; if (client !== 'mobile') { host = getHost(); protocol = location.protocol; @@ -94,7 +94,7 @@ const getHostUrl = (network = 'mainnet'): string => { const getOrigin = (network = 'mainnet'): Origin => { const host = getHostUrl(network); let origin: Origin = 'onion'; - const [client, _view] = window.RobosatsSettings.split('-'); + const [client] = window.RobosatsSettings.split('-'); if (client === 'mobile' || client === 'desktop' || host.includes('.onion')) { origin = 'onion'; @@ -209,8 +209,9 @@ export const AppContextProvider = ({ children }: AppContextProviderProps): JSX.E initialAppContext.slideDirection, ); const [open, setOpen] = useState(initialAppContext.open); - const [windowSize, setWindowSize] = useState(() => - getWindowSize(theme.typography.fontSize), + const [windowSize, setWindowSize] = useState( + () => getWindowSize(theme.typography.fontSize), + O, ); const [fav, setFav] = useState(initialAppContext.fav); const [acknowledgedWarning, setAcknowledgedWarning] = useState( diff --git a/frontend/src/contexts/FederationContext.tsx b/frontend/src/contexts/FederationContext.tsx index 326e7659..2ab3adce 100644 --- a/frontend/src/contexts/FederationContext.tsx +++ b/frontend/src/contexts/FederationContext.tsx @@ -1,12 +1,4 @@ -import React, { - createContext, - type Dispatch, - useEffect, - useState, - type SetStateAction, - useContext, - type ReactNode, -} from 'react'; +import React, { createContext, useEffect, useState, useContext, type ReactNode } from 'react'; import { Federation, Settings } from '../models'; @@ -14,7 +6,8 @@ import { federationLottery } from '../utils'; import { AppContext, type UseAppStoreType } from './AppContext'; import { GarageContext, type UseGarageStoreType } from './GarageContext'; -import Coordinator, { type Origin, type Origins } from '../models/Coordinator.model'; +import type Coordinator from '../models/Coordinator.model'; +import { type Origin, type Origins } from '../models/Coordinator.model'; export interface CurrentOrderIdProps { id: number | null; diff --git a/frontend/src/contexts/GarageContext.tsx b/frontend/src/contexts/GarageContext.tsx index 02f599cb..a1c9fb0b 100644 --- a/frontend/src/contexts/GarageContext.tsx +++ b/frontend/src/contexts/GarageContext.tsx @@ -13,7 +13,6 @@ import { defaultMaker, type Maker, Garage } from '../models'; import { systemClient } from '../services/System'; import { type UseAppStoreType, AppContext } from './AppContext'; import { type UseFederationStoreType, FederationContext } from './FederationContext'; -import { genKey } from '../pgp'; export interface GarageContextProviderProps { children: ReactNode; @@ -90,7 +89,9 @@ export const GarageContextProvider = ({ children }: GarageContextProviderProps): clearInterval(timer); fetchSlotActiveOrder(); - return () => clearTimeout(timer); + return () => { + clearTimeout(timer); + }; }, []); useEffect(() => { @@ -143,7 +144,11 @@ export const GarageContextProvider = ({ children }: GarageContextProviderProps): const resetInterval = (): void => { clearInterval(timer); setDelay(defaultDelay); - setTimer(setTimeout(() => fetchSlotActiveOrder(), defaultDelay)); + setTimer( + setTimeout(() => { + fetchSlotActiveOrder(); + }, defaultDelay), + ); }; return ( diff --git a/frontend/src/models/Coordinator.model.ts b/frontend/src/models/Coordinator.model.ts index b9896f34..84c7ca20 100644 --- a/frontend/src/models/Coordinator.model.ts +++ b/frontend/src/models/Coordinator.model.ts @@ -202,7 +202,7 @@ export class Coordinator { if (!data?.not_found) { this.book = (data as PublicOrder[]).reduce>((book, order) => { order.coordinatorShortAlias = this.shortAlias; - return { ...book, [this.shortAlias + order.id]: order }; + return { ...book, [`${this.shortAlias}${order.id}`]: order }; }, {}); void this.generateAllMakerAvatars(); onDataLoad(); @@ -272,7 +272,7 @@ export class Coordinator { enable = (onEnabled: () => void = () => {}): void => { this.enabled = true; - void this.loadLimits(() => { + this.loadLimits(() => { onEnabled(); }); }; diff --git a/frontend/src/models/Federation.model.ts b/frontend/src/models/Federation.model.ts index 51c4558a..be2cf9bf 100644 --- a/frontend/src/models/Federation.model.ts +++ b/frontend/src/models/Federation.model.ts @@ -12,7 +12,6 @@ import { federationLottery, getHost } from '../utils'; import { coordinatorDefaultValues } from './Coordinator.model'; import { updateExchangeInfo } from './Exchange.model'; import eventToPublicOrder from '../utils/nostr'; -import { SubCloser } from 'nostr-tools/lib/types/pool'; import RoboPool from '../services/RoboPool'; type FederationHooks = 'onFederationUpdate'; @@ -71,7 +70,7 @@ export class Federation { public coordinators: Record; public exchange: Exchange; - public book: Record; + public book: Record; public loading: boolean; public connection: 'api' | 'nostr' | null; @@ -87,7 +86,7 @@ export class Federation { this.loadBookNostr(); } else { this.roboPool.close(); - this.loadBook(); + void this.loadBook(); } }; @@ -103,7 +102,7 @@ export class Federation { if (publicOrder) { this.book[dTag] = publicOrder; } else { - delete this.book[dTag]; + this.book[dTag] = undefined; } }, oneose: () => { @@ -181,7 +180,7 @@ export class Federation { this.updateEnabledCoordinators(); for (const coor of Object.values(this.coordinators)) { - void coor.loadInfo(() => { + coor.loadInfo(() => { this.onCoordinatorSaved(); }); } @@ -194,7 +193,7 @@ export class Federation { this.updateEnabledCoordinators(); for (const coor of Object.values(this.coordinators)) { - void coor.loadLimits(() => { + coor.loadLimits(() => { this.exchange.onlineCoordinators = this.exchange.onlineCoordinators + 1; this.onCoordinatorSaved(); }); @@ -209,7 +208,7 @@ export class Federation { this.triggerHook('onFederationUpdate'); this.exchange.loadingCoordinators = Object.keys(this.coordinators).length; for (const coor of Object.values(this.coordinators)) { - void coor.loadBook(() => { + coor.loadBook(() => { this.onCoordinatorSaved(); this.triggerHook('onFederationUpdate'); }); diff --git a/frontend/src/models/Order.model.ts b/frontend/src/models/Order.model.ts index 5eae7383..ede9e4bd 100644 --- a/frontend/src/models/Order.model.ts +++ b/frontend/src/models/Order.model.ts @@ -219,7 +219,7 @@ class Order { slot, takeAmount, ) => { - return this.submitAction(federation, slot, { + return await this.submitAction(federation, slot, { action: 'take', amount: this?.currency === 1000 ? Number(takeAmount) / 100000000 : Number(takeAmount), }); diff --git a/frontend/src/models/Settings.model.ts b/frontend/src/models/Settings.model.ts index c6c23943..a271b180 100644 --- a/frontend/src/models/Settings.model.ts +++ b/frontend/src/models/Settings.model.ts @@ -49,7 +49,7 @@ class BaseSettings { this.network = networkCookie && networkCookie !== '' ? networkCookie : 'mainnet'; this.host = getHost(); - const [client, _view] = window.RobosatsSettings.split('-'); + const [client] = window.RobosatsSettings.split('-'); const stopNotifications = systemClient.getItem('settings_stop_notifications'); this.stopNotifications = client === 'mobile' && stopNotifications === 'true'; diff --git a/frontend/src/services/RoboPool/index.ts b/frontend/src/services/RoboPool/index.ts index 761c571b..34173304 100644 --- a/frontend/src/services/RoboPool/index.ts +++ b/frontend/src/services/RoboPool/index.ts @@ -1,7 +1,6 @@ -import { Event } from 'nostr-tools'; -import { Settings } from '../../models'; +import { type Event } from 'nostr-tools'; +import { type Settings } from '../../models'; import defaultFederation from '../../../static/federation.json'; -import { Origins } from '../../models/Coordinator.model'; interface RoboPoolEvents { onevent: (event: Event) => void; @@ -13,9 +12,9 @@ class RoboPool { this.network = settings.network ?? 'mainnet'; this.relays = Object.values(defaultFederation) .map((coord) => { - const url = coord[this.network][settings.selfhostedClient ? 'onion' : origin]; + const url: string = coord[this.network][settings.selfhostedClient ? 'onion' : origin]; - if (!url) return; + if (!url) return undefined; return `ws://${url.replace(/^https?:\/\//, '')}/nostr`; }) @@ -26,15 +25,15 @@ class RoboPool { public network: string; public webSockets: WebSocket[] = []; - private messageHandlers: Array<(url: string, event: MessageEvent) => void> = []; + private readonly messageHandlers: Array<(url: string, event: MessageEvent) => void> = []; - connect = () => { + connect = (): void => { this.relays.forEach((url) => { if (this.webSockets.find((w: WebSocket) => w.url === url)) return; let ws: WebSocket; - const connect = () => { + const connect = (): void => { ws = new WebSocket(url); // Add event listeners for the WebSocket @@ -43,7 +42,9 @@ class RoboPool { }; ws.onmessage = (event) => { - this.messageHandlers.forEach((handler) => handler(url, event)); + this.messageHandlers.forEach((handler) => { + handler(url, event); + }); }; ws.onerror = (error) => { @@ -61,12 +62,14 @@ class RoboPool { }); }; - close = () => { - this.webSockets.forEach((ws) => ws.close()); + close = (): void => { + this.webSockets.forEach((ws) => { + ws.close(); + }); }; - sendMessage = (message: string) => { - const send = (index: number, message: string) => { + sendMessage = (message: string): void => { + const send = (index: number, message: string): void => { const ws = this.webSockets[index]; if (ws.readyState === WebSocket.OPEN) { @@ -76,10 +79,12 @@ class RoboPool { } }; - this.webSockets.forEach((_ws, index) => send(index, message)); + this.webSockets.forEach((_ws, index) => { + send(index, message); + }); }; - subscribeBook = (events: RoboPoolEvents) => { + subscribeBook = (events: RoboPoolEvents): void => { const authors = Object.values(defaultFederation) .map((f) => f.nostrHexPubkey) .filter((item) => item !== undefined); diff --git a/frontend/src/services/Roboidentities/RoboidentitiesWebClient/RobohashGenerator.ts b/frontend/src/services/Roboidentities/RoboidentitiesWebClient/RobohashGenerator.ts index 5929ee79..7314f96e 100644 --- a/frontend/src/services/Roboidentities/RoboidentitiesWebClient/RobohashGenerator.ts +++ b/frontend/src/services/Roboidentities/RoboidentitiesWebClient/RobohashGenerator.ts @@ -19,11 +19,11 @@ class RoboGenerator { private readonly workers: RoboWorker[] = []; private readonly taskQueue: Task[] = []; - private numberOfWorkers: number = 8; + private readonly numberOfWorkers: number = 8; private waitingForLibrary: boolean = true; - private resolves: Record void)[]> = {}; - private rejects: Record void)[]> = {}; + private resolves: Record void>> = {}; + private rejects: Record void>> = {}; constructor() { for (let i = 0; i < this.numberOfWorkers; i++) { @@ -86,7 +86,7 @@ class RoboGenerator { return { id, worker, busy: false }; }; - addTask = (task: any) => { + addTask = (task: any): void => { const availableWorker = this.workers.find((w) => !w.busy); if (availableWorker && !this.waitingForLibrary) { availableWorker.worker.postMessage(task); diff --git a/frontend/src/utils/filterOrders.ts b/frontend/src/utils/filterOrders.ts index 1c5c057a..f98d83b1 100644 --- a/frontend/src/utils/filterOrders.ts +++ b/frontend/src/utils/filterOrders.ts @@ -1,4 +1,4 @@ -import { type PublicOrder, type Favorites, Federation } from '../models'; +import { type PublicOrder, type Favorites, type Federation } from '../models'; interface AmountFilter { amount: string; diff --git a/frontend/src/utils/nostr.ts b/frontend/src/utils/nostr.ts index 00e7a09f..a25483c7 100644 --- a/frontend/src/utils/nostr.ts +++ b/frontend/src/utils/nostr.ts @@ -1,5 +1,5 @@ -import { Event } from 'nostr-tools'; -import { Federation, PublicOrder } from '../models'; +import { type Event } from 'nostr-tools'; +import { type PublicOrder } from '../models'; import { fromUnixTime } from 'date-fns'; import Geohash from 'latlon-geohash'; import currencyDict from '../../static/assets/currencies.json'; @@ -69,18 +69,20 @@ const eventToPublicOrder = (event: Event): { dTag: string; publicOrder: PublicOr tag.shift(); publicOrder.payment_method = tag.join(' '); break; - case 'g': + case 'g': { const { lat, lon } = Geohash.decode(tag[1]); publicOrder.latitude = lat; publicOrder.longitude = lon; break; - case 'f': + } + case 'f': { const currencyNumber = Object.entries(currencyDict).find( ([_key, value]) => value === tag[1], ); publicOrder.currency = currencyNumber?.[0] ? parseInt(currencyNumber[0], 10) : null; break; - case 'source': + } + case 'source': { const orderUrl = tag[1].split('/'); publicOrder.id = parseInt(orderUrl[orderUrl.length - 1] ?? '0'); const coordinatorIdentifier = orderUrl[orderUrl.length - 2] ?? ''; @@ -88,6 +90,7 @@ const eventToPublicOrder = (event: Event): { dTag: string; publicOrder: PublicOr ([key, value]) => value.identifier === coordinatorIdentifier, )?.[0]; break; + } default: break; }