diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 90cee64b..9644bf7c 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -21,8 +21,8 @@ const App = (): JSX.Element => {
-
-
+
+
{window.NativeRobosats === undefined && window.RobosatsClient === undefined ? (
@@ -30,8 +30,8 @@ const App = (): JSX.Element => {
)}
-
-
+
+
diff --git a/frontend/src/basic/BookPage/index.tsx b/frontend/src/basic/BookPage/index.tsx
index ed74cc24..3b9ebf45 100644
--- a/frontend/src/basic/BookPage/index.tsx
+++ b/frontend/src/basic/BookPage/index.tsx
@@ -12,12 +12,10 @@ 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, type UseFederationStoreType } from '../../contexts/FederationContext';
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
const BookPage = (): JSX.Element => {
const { windowSize } = useContext(AppContext);
- const { setDelay, setCurrentOrderId } = useContext(FederationContext);
const { garage } = useContext(GarageContext);
const { t } = useTranslation();
const navigate = useNavigate();
@@ -32,8 +30,6 @@ const BookPage = (): JSX.Element => {
const onOrderClicked = function (id: number, shortAlias: string): void {
if (garage.getSlot()?.hashId) {
- setDelay(10000);
- setCurrentOrderId({ id, shortAlias });
navigate(`/order/${shortAlias}/${id}`);
} else {
setOpenNoRobot(true);
@@ -102,9 +98,6 @@ const BookPage = (): JSX.Element => {
>
{
- navigate(`/order/${id}`);
- }}
onClickGenerateRobot={() => {
navigate('/robot');
}}
diff --git a/frontend/src/basic/MakerPage/index.tsx b/frontend/src/basic/MakerPage/index.tsx
index 142cf451..67e6d6d7 100644
--- a/frontend/src/basic/MakerPage/index.tsx
+++ b/frontend/src/basic/MakerPage/index.tsx
@@ -14,8 +14,7 @@ import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageCon
const MakerPage = (): JSX.Element => {
const { fav, windowSize, navbarHeight } = useContext(AppContext);
- const { federation, setDelay, setCurrentOrderId } =
- useContext(FederationContext);
+ const { federation } = useContext(FederationContext);
const { garage, maker } = useContext(GarageContext);
const { t } = useTranslation();
const navigate = useNavigate();
@@ -54,8 +53,6 @@ const MakerPage = (): JSX.Element => {
const onOrderClicked = function (id: number, shortAlias: string): void {
if (garage.getSlot()?.hashId) {
- setDelay(10000);
- setCurrentOrderId({ id, shortAlias });
navigate(`/order/${shortAlias}/${id}`);
} else {
setOpenNoRobot(true);
@@ -105,10 +102,6 @@ const MakerPage = (): JSX.Element => {
}}
>
{
- setCurrentOrderId({ id, shortAlias });
- navigate(`/order/${shortAlias}/${id}`);
- }}
disableRequest={matches.length > 0 && !showMatches}
collapseAll={showMatches}
onSubmit={() => {
diff --git a/frontend/src/basic/NavBar/NavBar.tsx b/frontend/src/basic/NavBar/NavBar.tsx
index 9cabcfd0..ecd8f85c 100644
--- a/frontend/src/basic/NavBar/NavBar.tsx
+++ b/frontend/src/basic/NavBar/NavBar.tsx
@@ -17,15 +17,13 @@ import {
import RobotAvatar from '../../components/RobotAvatar';
import { AppContext, type UseAppStoreType, closeAll } from '../../contexts/AppContext';
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
-import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
const NavBar = (): JSX.Element => {
const theme = useTheme();
const { t } = useTranslation();
const { page, setPage, settings, setSlideDirection, open, setOpen, windowSize, navbarHeight } =
useContext(AppContext);
- const { garage, robotUpdatedAt } = useContext(GarageContext);
- const { setCurrentOrderId } = useContext(FederationContext);
+ const { garage, slotUpdatedAt } = useContext(GarageContext);
const navigate = useNavigate();
const location = useLocation();
@@ -50,7 +48,7 @@ const NavBar = (): JSX.Element => {
useEffect(() => {
// re-render on orde rand robot updated at for latest orderId in tab
- }, [robotUpdatedAt]);
+ }, [slotUpdatedAt]);
useEffect(() => {
// change tab (page) into the current route
@@ -77,14 +75,10 @@ const NavBar = (): JSX.Element => {
const slot = garage.getSlot();
handleSlideDirection(page, newPage);
setPage(newPage);
- const shortAlias = String(slot?.activeShortAlias);
- const activeOrderId = slot?.getRobot(slot?.activeShortAlias ?? '')?.activeOrderId;
- const lastOrderId = slot?.getRobot(slot?.lastShortAlias ?? '')?.lastOrderId;
- const param =
- newPage === 'order' ? `${shortAlias}/${String(activeOrderId ?? lastOrderId)}` : '';
- if (newPage === 'order') {
- setCurrentOrderId({ id: activeOrderId ?? lastOrderId, shortAlias });
- }
+
+ const shortAlias = slot?.activeOrder?.shortAlias;
+ const orderId = slot?.activeOrder?.id;
+ const param = newPage === 'order' ? `${String(shortAlias)}/${String(orderId)}` : '';
setTimeout(() => {
navigate(`/${newPage}/${param}`);
}, theme.transitions.duration.leavingScreen * 3);
@@ -162,7 +156,7 @@ const NavBar = (): JSX.Element => {
sx={tabSx}
label={smallBar ? undefined : t('Order')}
value='order'
- disabled={!slot?.getRobot()?.activeOrderId}
+ disabled={!slot?.activeOrder}
icon={}
iconPosition='start'
/>
diff --git a/frontend/src/basic/OrderPage/index.tsx b/frontend/src/basic/OrderPage/index.tsx
index aa2f3e74..af582549 100644
--- a/frontend/src/basic/OrderPage/index.tsx
+++ b/frontend/src/basic/OrderPage/index.tsx
@@ -1,4 +1,4 @@
-import React, { useContext, useEffect, useState } from 'react';
+import React, { useContext, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Tab, Tabs, Paper, CircularProgress, Grid, Typography, Box } from '@mui/material';
import { useNavigate, useParams } from 'react-router-dom';
@@ -6,60 +6,59 @@ import { useNavigate, useParams } from 'react-router-dom';
import TradeBox from '../../components/TradeBox';
import OrderDetails from '../../components/OrderDetails';
-import { AppContext, closeAll, type UseAppStoreType } from '../../contexts/AppContext';
+import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
-import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
import { WarningDialog } from '../../components/Dialogs';
+import { Order, type Slot } from '../../models';
+import { type UseGarageStoreType, GarageContext } from '../../contexts/GarageContext';
const OrderPage = (): JSX.Element => {
- const {
- windowSize,
- open,
- setOpen,
- acknowledgedWarning,
- setAcknowledgedWarning,
- settings,
- navbarHeight,
- hostUrl,
- origin,
- } = useContext(AppContext);
- const { federation, currentOrder, currentOrderId, setCurrentOrderId } =
- useContext(FederationContext);
- const { badOrder } = useContext(GarageContext);
+ const { windowSize, setOpen, acknowledgedWarning, setAcknowledgedWarning, navbarHeight } =
+ useContext(AppContext);
+ const { federation } = useContext(FederationContext);
+ const { garage } = useContext(GarageContext);
const { t } = useTranslation();
const navigate = useNavigate();
const params = useParams();
+ const paramsRef = useRef(params);
const doublePageWidth: number = 50;
const maxHeight: number = (windowSize?.height - navbarHeight) * 0.85 - 3;
const [tab, setTab] = useState<'order' | 'contract'>('contract');
- const [baseUrl, setBaseUrl] = useState(hostUrl);
+ const [currentOrder, setCurrentOrder] = useState(null);
useEffect(() => {
+ paramsRef.current = params;
const shortAlias = params.shortAlias;
- const coordinator = federation.getCoordinator(shortAlias ?? '');
- if (coordinator) {
- const endpoint = coordinator?.getEndpoint(
- settings.network,
- origin,
- settings.selfhostedClient,
- hostUrl,
- );
-
- if (endpoint) setBaseUrl(`${endpoint?.url}${endpoint?.basePath}`);
-
- const orderId = Number(params.orderId);
- if (
- orderId &&
- currentOrderId.id !== orderId &&
- currentOrderId.shortAlias !== shortAlias &&
- shortAlias
- )
- setCurrentOrderId({ id: orderId, shortAlias });
- if (!acknowledgedWarning) setOpen({ ...closeAll, warning: true });
+ const orderId = Number(params.orderId);
+ const slot = garage.getSlot();
+ if (slot?.token) {
+ let order = new Order({ id: orderId, shortAlias });
+ if (slot.activeOrder?.id === orderId && slot.activeOrder?.shortAlias === shortAlias) {
+ order = slot.activeOrder;
+ } else if (slot.lastOrder?.id === orderId && slot.lastOrder?.shortAlias === shortAlias) {
+ order = slot.lastOrder;
+ }
+ void order.fecth(federation, slot).then((updatedOrder) => {
+ updateSlotFromOrder(updatedOrder, slot);
+ });
}
- }, [params, currentOrderId]);
+
+ return () => {
+ setCurrentOrder(null);
+ };
+ }, [params.orderId]);
+
+ const updateSlotFromOrder = (updatedOrder: Order, slot: Slot): void => {
+ if (
+ Number(paramsRef.current.orderId) === updatedOrder.id &&
+ paramsRef.current.shortAlias === updatedOrder.shortAlias
+ ) {
+ setCurrentOrder(updatedOrder);
+ slot.updateSlotFromOrder(updatedOrder);
+ }
+ };
const onClickCoordinator = function (): void {
if (currentOrder?.shortAlias != null) {
@@ -87,7 +86,7 @@ const OrderPage = (): JSX.Element => {
);
const tradeBoxSpace = currentOrder ? (
-
+
) : (
<>>
);
@@ -95,20 +94,19 @@ const OrderPage = (): JSX.Element => {
return (
{
- setOpen(closeAll);
setAcknowledgedWarning(true);
}}
longAlias={federation.getCoordinator(params.shortAlias ?? '')?.longAlias}
/>
- {currentOrder === null && badOrder === undefined && }
- {badOrder !== undefined ? (
+ {!currentOrder?.maker_hash_id && }
+ {currentOrder?.bad_request && currentOrder.status !== 5 ? (
- {t(badOrder)}
+ {t(currentOrder.bad_request)}
) : null}
- {currentOrder !== null && badOrder === undefined ? (
+ {currentOrder?.maker_hash_id && (!currentOrder.bad_request || currentOrder.status === 5) ? (
currentOrder.is_participant ? (
windowSize.width > doublePageWidth ? (
// DOUBLE PAPER VIEW
diff --git a/frontend/src/basic/RobotPage/RobotProfile.tsx b/frontend/src/basic/RobotPage/RobotProfile.tsx
index 4095d41a..97b0db30 100644
--- a/frontend/src/basic/RobotPage/RobotProfile.tsx
+++ b/frontend/src/basic/RobotPage/RobotProfile.tsx
@@ -22,7 +22,6 @@ import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import { genBase62Token } from '../../utils';
import { LoadingButton } from '@mui/lab';
import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
-import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
interface RobotProfileProps {
robot: Robot;
@@ -45,8 +44,7 @@ const RobotProfile = ({
width,
}: RobotProfileProps): JSX.Element => {
const { windowSize } = useContext(AppContext);
- const { garage, robotUpdatedAt, orderUpdatedAt } = useContext(GarageContext);
- const { setCurrentOrderId } = useContext(FederationContext);
+ const { garage, slotUpdatedAt } = useContext(GarageContext);
const { t } = useTranslation();
const theme = useTheme();
@@ -59,7 +57,7 @@ const RobotProfile = ({
if (slot?.hashId) {
setLoading(false);
}
- }, [orderUpdatedAt, robotUpdatedAt, loading]);
+ }, [slotUpdatedAt, loading]);
const handleAddRobot = (): void => {
getGenerateRobot(genBase62Token(36));
@@ -147,7 +145,7 @@ const RobotProfile = ({
tooltip={t('This is your trading avatar')}
tooltipPosition='top'
/>
- {robot?.found && Boolean(slot?.lastShortAlias) ? (
+ {robot?.found && Boolean(slot?.lastOrder?.id) ? (
{t('Welcome back!')}
@@ -156,38 +154,38 @@ const RobotProfile = ({
)}
- {loadingCoordinators > 0 && !robot?.activeOrderId ? (
+ {loadingCoordinators > 0 && !slot?.activeOrder?.id ? (
{t('Looking for orders!')}
) : null}
- {Boolean(robot?.activeOrderId) && Boolean(slot?.hashId) ? (
+ {slot?.activeOrder ? (
) : null}
- {Boolean(robot?.lastOrderId) && Boolean(slot?.hashId) ? (
+ {!slot?.activeOrder?.id && Boolean(slot?.lastOrder?.id) ? (
@@ -210,10 +208,7 @@ const RobotProfile = ({
) : null}
- {!robot?.activeOrderId &&
- slot?.hashId &&
- !robot?.lastOrderId &&
- loadingCoordinators === 0 ? (
+ {!slot?.activeOrder && !slot?.lastOrder && loadingCoordinators === 0 ? (
{t('No existing orders found')}
) : null}
diff --git a/frontend/src/basic/RobotPage/index.tsx b/frontend/src/basic/RobotPage/index.tsx
index 0902c2aa..d6c39081 100644
--- a/frontend/src/basic/RobotPage/index.tsx
+++ b/frontend/src/basic/RobotPage/index.tsx
@@ -45,7 +45,6 @@ const RobotPage = (): JSX.Element => {
if (token !== undefined && token !== null && page === 'robot') {
setInputToken(token);
if (window.NativeRobosats === undefined || torStatus === 'ON' || !settings.useProxy) {
- getGenerateRobot(token);
setView('profile');
}
}
@@ -70,7 +69,7 @@ const RobotPage = (): JSX.Element => {
pubKey: key.publicKeyArmored,
encPrivKey: key.encryptedPrivateKeyArmored,
});
- void federation.fetchRobot(garage, token);
+ void garage.fetchRobot(federation, token);
garage.setCurrentSlot(token);
})
.catch((error) => {
diff --git a/frontend/src/basic/SettingsPage/index.tsx b/frontend/src/basic/SettingsPage/index.tsx
index a47360e5..af9a8d53 100644
--- a/frontend/src/basic/SettingsPage/index.tsx
+++ b/frontend/src/basic/SettingsPage/index.tsx
@@ -5,10 +5,12 @@ import { AppContext, type UseAppStoreType } from '../../contexts/AppContext';
import FederationTable from '../../components/FederationTable';
import { t } from 'i18next';
import { FederationContext, type UseFederationStoreType } from '../../contexts/FederationContext';
+import { GarageContext, type UseGarageStoreType } from '../../contexts/GarageContext';
const SettingsPage = (): JSX.Element => {
const { windowSize, navbarHeight } = useContext(AppContext);
const { federation, addNewCoordinator } = useContext(FederationContext);
+ const { garage } = useContext(GarageContext);
const maxHeight = (windowSize.height - navbarHeight) * 0.85 - 3;
const [newAlias, setNewAlias] = useState('');
const [newUrl, setNewUrl] = useState('');
@@ -26,6 +28,7 @@ const SettingsPage = (): JSX.Element => {
fullNewUrl = `http://${newUrl}`;
}
addNewCoordinator(newAlias, fullNewUrl);
+ garage.syncCoordinator(federation, newAlias);
setNewAlias('');
setNewUrl('');
} else {
diff --git a/frontend/src/components/BookTable/index.tsx b/frontend/src/components/BookTable/index.tsx
index a42399e3..eb017cce 100644
--- a/frontend/src/components/BookTable/index.tsx
+++ b/frontend/src/components/BookTable/index.tsx
@@ -88,8 +88,7 @@ const BookTable = ({
onOrderClicked = () => null,
}: BookTableProps): JSX.Element => {
const { fav, setOpen } = useContext(AppContext);
- const { federation, coordinatorUpdatedAt } =
- useContext(FederationContext);
+ const { federation, federationUpdatedAt } = useContext(FederationContext);
const { t } = useTranslation();
const theme = useTheme();
@@ -123,7 +122,7 @@ const BookTable = ({
pageSize: federation.loading && orders.length === 0 ? 0 : defaultPageSize,
page: paginationModel.page,
});
- }, [coordinatorUpdatedAt, orders, defaultPageSize]);
+ }, [federationUpdatedAt, orders, defaultPageSize]);
const localeText = useMemo(() => {
return {
diff --git a/frontend/src/components/Charts/DepthChart/index.tsx b/frontend/src/components/Charts/DepthChart/index.tsx
index 89fdd118..474723a6 100644
--- a/frontend/src/components/Charts/DepthChart/index.tsx
+++ b/frontend/src/components/Charts/DepthChart/index.tsx
@@ -47,8 +47,7 @@ const DepthChart: React.FC = ({
onOrderClicked = () => null,
}) => {
const { fav } = useContext(AppContext);
- const { federation, coordinatorUpdatedAt, federationUpdatedAt } =
- useContext(FederationContext);
+ const { federation, federationUpdatedAt } = useContext(FederationContext);
const { t } = useTranslation();
const theme = useTheme();
const [enrichedOrders, setEnrichedOrders] = useState([]);
@@ -81,7 +80,7 @@ const DepthChart: React.FC = ({
});
setEnrichedOrders(enriched);
}
- }, [coordinatorUpdatedAt, currencyCode]);
+ }, [federationUpdatedAt, currencyCode]);
useEffect(() => {
if (enrichedOrders.length > 0) {
diff --git a/frontend/src/components/Dialogs/Exchange.tsx b/frontend/src/components/Dialogs/Exchange.tsx
index f7be51d3..3ea20200 100644
--- a/frontend/src/components/Dialogs/Exchange.tsx
+++ b/frontend/src/components/Dialogs/Exchange.tsx
@@ -34,14 +34,14 @@ interface Props {
const ExchangeDialog = ({ open = false, onClose }: Props): JSX.Element => {
const { t } = useTranslation();
- const { federation, coordinatorUpdatedAt, federationUpdatedAt } = useContext(FederationContext);
+ const { federation, federationUpdatedAt } = useContext(FederationContext);
const [loadingProgress, setLoadingProgress] = useState(0);
useEffect(() => {
const loadedCoordinators =
federation.exchange.enabledCoordinators - federation.exchange.loadingCoordinators;
setLoadingProgress((loadedCoordinators / federation.exchange.enabledCoordinators) * 100);
- }, [open, coordinatorUpdatedAt, federationUpdatedAt]);
+ }, [open, federationUpdatedAt]);
return (