diff --git a/frontend/src/components/BookTable/BookControl.tsx b/frontend/src/components/BookTable/BookControl.tsx index 44b1ffb4..73b85098 100644 --- a/frontend/src/components/BookTable/BookControl.tsx +++ b/frontend/src/components/BookTable/BookControl.tsx @@ -20,7 +20,7 @@ import { AppContext, type UseAppStoreType } from '../../contexts/AppContext'; import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank'; import SwapCalls from '@mui/icons-material/SwapCalls'; -import { FederationContext, UseFederationStoreType } from '../../contexts/FederationContext'; +import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; import RobotAvatar from '../RobotAvatar'; interface BookControlProps { diff --git a/frontend/src/components/Dialogs/Coordinator.tsx b/frontend/src/components/Dialogs/Coordinator.tsx index 46c548b2..fc4f63ca 100644 --- a/frontend/src/components/Dialogs/Coordinator.tsx +++ b/frontend/src/components/Dialogs/Coordinator.tsx @@ -545,7 +545,7 @@ const CoordinatorDialog = ({ open = false, onClose, network, shortAlias }: Props - {coordinator?.info?.swap_enabled === false ? ( + {!coordinator?.info?.swap_enabled ? ( diff --git a/frontend/src/components/MakerForm/MakerForm.tsx b/frontend/src/components/MakerForm/MakerForm.tsx index 087979aa..a55d4ec2 100644 --- a/frontend/src/components/MakerForm/MakerForm.tsx +++ b/frontend/src/components/MakerForm/MakerForm.tsx @@ -2,7 +2,6 @@ import React, { useContext, useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { InputAdornment, - LinearProgress, ButtonGroup, Slider, Switch, @@ -103,7 +102,7 @@ const MakerForm = ({ useEffect(() => { updateCoordinatorInfo(); - }, [maker.coordinator]); + }, [maker.coordinator, coordinatorUpdatedAt]); const updateCoordinatorInfo = (): void => { if (maker.coordinator != null) { @@ -516,7 +515,9 @@ const MakerForm = ({ (makerHasAmountRange && (minAmountError || maxAmountError)) || (!makerHasAmountRange && maker.amount <= 0) || (maker.isExplicit && (maker.badSatoshisText !== '' || maker.satoshis === '')) || - (!maker.isExplicit && maker.badPremiumText !== '') + (!maker.isExplicit && maker.badPremiumText !== '') || + federation.getCoordinator(maker.coordinator)?.info === undefined || + federation.getCoordinator(maker.coordinator)?.limits === undefined ); }, [maker, amountLimits, coordinatorUpdatedAt, fav.type, makerHasAmountRange]); @@ -613,11 +614,6 @@ const MakerForm = ({ }} zoom={maker.latitude != null && maker.longitude != null ? 6 : undefined} /> - -
- -
-
@@ -1165,10 +1161,10 @@ const MakerForm = ({ { + coordinatorAlias={maker.coordinator} + setCoordinator={(coordinatorAlias) => { setMaker((maker) => { - return { ...maker, coordinator }; + return { ...maker, coordinator: coordinatorAlias }; }); }} /> diff --git a/frontend/src/components/MakerForm/SelectCoordinator.tsx b/frontend/src/components/MakerForm/SelectCoordinator.tsx index 1a100cb9..36a37ccc 100644 --- a/frontend/src/components/MakerForm/SelectCoordinator.tsx +++ b/frontend/src/components/MakerForm/SelectCoordinator.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from 'react'; +import React, { useContext, useMemo } from 'react'; import { Grid, Select, @@ -7,6 +7,7 @@ import { Tooltip, Typography, type SelectChangeEvent, + CircularProgress, } from '@mui/material'; import RobotAvatar from '../RobotAvatar'; @@ -16,13 +17,17 @@ import { useTranslation } from 'react-i18next'; import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext'; interface SelectCoordinatorProps { - coordinator: string; - setCoordinator: (coordinator: string) => void; + coordinatorAlias: string; + setCoordinator: (coordinatorAlias: string) => void; } -const SelectCoordinator: React.FC = ({ coordinator, setCoordinator }) => { +const SelectCoordinator: React.FC = ({ + coordinatorAlias, + setCoordinator, +}) => { const { setOpen } = useContext(AppContext); - const { federation, sortedCoordinators } = useContext(FederationContext); + const { federation, sortedCoordinators, coordinatorUpdatedAt } = + useContext(FederationContext); const theme = useTheme(); const { t } = useTranslation(); @@ -36,6 +41,11 @@ const SelectCoordinator: React.FC = ({ coordinator, setC setCoordinator(e.target.value); }; + const coordinator = useMemo( + () => federation.getCoordinator(coordinatorAlias), + [coordinatorUpdatedAt], + ); + return ( = ({ coordinator, setC xs={3} sx={{ cursor: 'pointer', position: 'relative', left: '0.3em', bottom: '0.1em' }} onClick={() => { - onClickCurrentCoordinator(coordinator); + onClickCurrentCoordinator(coordinatorAlias); }} > + {(coordinator?.info === undefined || + Object.keys(coordinator?.limits).length === 0) && ( + + )} @@ -90,20 +108,17 @@ const SelectCoordinator: React.FC = ({ coordinator, setC inputProps={{ style: { textAlign: 'center' }, }} - value={coordinator} + value={coordinatorAlias} onChange={handleCoordinatorChange} disableUnderline > {sortedCoordinators.map((shortAlias: string): JSX.Element | null => { let row: JSX.Element | null = null; - if ( - shortAlias === coordinator || - (federation.getCoordinator(shortAlias).enabled === true && - federation.getCoordinator(shortAlias).info !== undefined) - ) { + const item = federation.getCoordinator(shortAlias); + if (item.enabled === true) { row = ( - {federation.getCoordinator(shortAlias).longAlias} + {item.longAlias} ); } diff --git a/frontend/src/components/OrderDetails/index.tsx b/frontend/src/components/OrderDetails/index.tsx index 92ffea6f..53c97055 100644 --- a/frontend/src/components/OrderDetails/index.tsx +++ b/frontend/src/components/OrderDetails/index.tsx @@ -40,7 +40,6 @@ import type Coordinator from '../../models'; import { statusBadgeColor, pn, amountToString, computeSats } from '../../utils'; import TakeButton from './TakeButton'; import { F2fMapDialog } from '../Dialogs'; -import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext'; import { type UseFederationStoreType, FederationContext } from '../../contexts/FederationContext'; import { type Order } from '../../models'; diff --git a/frontend/src/contexts/FederationContext.tsx b/frontend/src/contexts/FederationContext.tsx index b38ad71a..b73c6e2c 100644 --- a/frontend/src/contexts/FederationContext.tsx +++ b/frontend/src/contexts/FederationContext.tsx @@ -106,11 +106,11 @@ export const FederationContextProvider = ({ useEffect(() => { // On bitcoin network change we reset book, limits and federation info and fetch everything again const newFed = initialFederationContext.federation; - newFed.registerHook('onFederationReady', () => { - setCoordinatorUpdatedAt(new Date().toISOString()); + newFed.registerHook('onFederationUpdate', () => { + setFederationUpdatedAt(new Date().toISOString()); }); newFed.registerHook('onCoordinatorUpdate', () => { - setFederationUpdatedAt(new Date().toISOString()); + setCoordinatorUpdatedAt(new Date().toISOString()); }); void newFed.start(origin, settings, hostUrl); setFederation(newFed); diff --git a/frontend/src/models/Exchange.model.ts b/frontend/src/models/Exchange.model.ts index 9e783ac6..74b5a294 100644 --- a/frontend/src/models/Exchange.model.ts +++ b/frontend/src/models/Exchange.model.ts @@ -43,7 +43,7 @@ export const updateExchangeInfo = (federation: Federation): ExchangeInfo => { premiums[index] = coordinator.info.last_day_nonkyc_btc_premium; volumes[index] = coordinator.info.last_day_volume; highestVersion = getHigherVer(highestVersion, coordinator.info.version); - active_robots_today = Math.max(active_robots_today, coordinator.info['active_robots_today']); + active_robots_today = Math.max(active_robots_today, coordinator.info.active_robots_today); aggregations.forEach((key: any) => { info[key] = Number(info[key]) + Number(coordinator.info[key]); diff --git a/frontend/src/models/Federation.model.ts b/frontend/src/models/Federation.model.ts index 570fadf5..ed9a0aa8 100644 --- a/frontend/src/models/Federation.model.ts +++ b/frontend/src/models/Federation.model.ts @@ -11,7 +11,7 @@ import defaultFederation from '../../static/federation.json'; import { getHost } from '../utils'; import { updateExchangeInfo } from './Exchange.model'; -type FederationHooks = 'onCoordinatorUpdate' | 'onFederationReady'; +type FederationHooks = 'onCoordinatorUpdate' | 'onFederationUpdate'; export class Federation { constructor() { @@ -34,7 +34,7 @@ export class Federation { this.book = []; this.hooks = { onCoordinatorUpdate: [], - onFederationReady: [], + onFederationUpdate: [], }; this.loading = true; } @@ -67,7 +67,7 @@ export class Federation { this.loading = this.exchange.loadingCoordinators > 0; if (Object.values(this.coordinators).every((coor) => coor.isUpdated())) { this.updateExchange(); - this.triggerHook('onFederationReady'); + this.triggerHook('onFederationUpdate'); } }; @@ -119,6 +119,7 @@ export class Federation { updateExchange = (): void => { this.exchange.info = updateExchangeInfo(this); + this.triggerHook('onFederationUpdate'); }; // Fetchs diff --git a/frontend/src/models/Garage.model.ts b/frontend/src/models/Garage.model.ts index 3ff38879..a6258cd1 100644 --- a/frontend/src/models/Garage.model.ts +++ b/frontend/src/models/Garage.model.ts @@ -126,7 +126,7 @@ class Garage { ) => { if (!token || !shortAlias) return; - let slot = this.getSlot(token); + const slot = this.getSlot(token); if (slot != null) { slot.updateRobot(shortAlias, { token, ...attributes }); diff --git a/frontend/src/utils/filterOrders.ts b/frontend/src/utils/filterOrders.ts index cefb2717..c97ff1d8 100644 --- a/frontend/src/utils/filterOrders.ts +++ b/frontend/src/utils/filterOrders.ts @@ -69,13 +69,13 @@ const filterOrders = function ({ const filteredOrders = orders.filter((order) => { const typeChecks = order.type === baseFilter.type || baseFilter.type == null; const modeChecks = baseFilter.mode === 'fiat' ? !(order.currency === 1000) : true; - const premiumChecks = premium != null ? filterByPremium(order, premium) : true; + const premiumChecks = premium !== null ? filterByPremium(order, premium) : true; const currencyChecks = order.currency === baseFilter.currency || baseFilter.currency === 0; const paymentMethodChecks = paymentMethods.length > 0 ? filterByPayment(order, paymentMethods) : true; - const amountChecks = amountFilter != null ? filterByAmount(order, amountFilter) : true; + const amountChecks = amountFilter !== null ? filterByAmount(order, amountFilter) : true; const hostChecks = - baseFilter.coordinator != 'any' ? filterByHost(order, baseFilter.coordinator) : true; + baseFilter.coordinator !== 'any' ? filterByHost(order, baseFilter.coordinator) : true; return ( typeChecks && modeChecks &&