diff --git a/frontend/src/basic/OrderPage/index.tsx b/frontend/src/basic/OrderPage/index.tsx index 65466d25..4a48124f 100644 --- a/frontend/src/basic/OrderPage/index.tsx +++ b/frontend/src/basic/OrderPage/index.tsx @@ -56,6 +56,10 @@ const OrderPage = (): JSX.Element => { useEffect(() => { setCurrentOrder(null); + updateCurrentOrder(); + }, [currentOrderId]); + + const updateCurrentOrder = () => { if (currentOrderId !== null) { const coordinator = federation.getCoordinator(params.shortAlias ?? ''); const slot = garage.getSlot(); @@ -79,7 +83,7 @@ const OrderPage = (): JSX.Element => { }); } } - }, [currentOrderId]); + }; const onClickCoordinator = function (): void { if (currentOrder?.shortAlias != null) { @@ -97,8 +101,8 @@ const OrderPage = (): JSX.Element => { { navigate('/robot'); }} diff --git a/frontend/src/basic/RobotPage/RobotProfile.tsx b/frontend/src/basic/RobotPage/RobotProfile.tsx index 5a017096..94c7171a 100644 --- a/frontend/src/basic/RobotPage/RobotProfile.tsx +++ b/frontend/src/basic/RobotPage/RobotProfile.tsx @@ -69,6 +69,7 @@ const RobotProfile = ({ const handleChangeSlot = (e: SelectChangeEvent): void => { garage.currentSlot = e.target.value; + setInputToken(garage.getSlot()?.getRobot()?.token ?? ''); setLoading(true); }; diff --git a/frontend/src/components/OrderDetails/TakeButton.tsx b/frontend/src/components/OrderDetails/TakeButton.tsx index 7cb25700..7bc285aa 100644 --- a/frontend/src/components/OrderDetails/TakeButton.tsx +++ b/frontend/src/components/OrderDetails/TakeButton.tsx @@ -32,6 +32,7 @@ import { type UseFederationStoreType, FederationContext } from '../../contexts/F interface TakeButtonProps { currentOrder: Order; info?: Info; + updateCurrentOrder?: () => void; onClickGenerateRobot?: () => void; } @@ -44,6 +45,7 @@ const closeAll = { inactiveMaker: false, confirmation: false }; const TakeButton = ({ currentOrder, info, + updateCurrentOrder = () => null, onClickGenerateRobot = () => null, }: TakeButtonProps): JSX.Element => { const { t } = useTranslation(); @@ -333,11 +335,10 @@ const TakeButton = ({ { tokenSHA256: robot?.tokenSHA256 }, ) .then((data) => { - setLoadingTake(false); if (data?.bad_request !== undefined) { setBadRequest(data.bad_request); } else { - garage.updateOrder(data as Order); + updateCurrentOrder(); setBadRequest(''); } }) diff --git a/frontend/src/components/OrderDetails/index.tsx b/frontend/src/components/OrderDetails/index.tsx index ae994b0c..2ddf7784 100644 --- a/frontend/src/components/OrderDetails/index.tsx +++ b/frontend/src/components/OrderDetails/index.tsx @@ -1,4 +1,4 @@ -import React, { useState, useMemo, useContext } from 'react'; +import React, { useState, useMemo, useContext, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { List, @@ -47,27 +47,34 @@ import { type Order } from '../../models'; interface OrderDetailsProps { shortAlias: string; currentOrder: Order; + updateCurrentOrder?: () => void; onClickCoordinator?: () => void; - baseUrl: string; onClickGenerateRobot?: () => void; } const OrderDetails = ({ shortAlias, currentOrder, + updateCurrentOrder = () => null, onClickCoordinator = () => null, - baseUrl, onClickGenerateRobot = () => null, }: OrderDetailsProps): JSX.Element => { const { t } = useTranslation(); const theme = useTheme(); const { federation } = useContext(FederationContext); const { orderUpdatedAt } = useContext(GarageContext); - const [coordinator] = useState(federation.getCoordinator(shortAlias)); - const currencyCode: string = currencies[(currentOrder?.currency ?? 1).toString()]; + const [coordinator, setCoordinator] = useState( + federation.getCoordinator(shortAlias), + ); + const [currencyCode, setCurrecyCode] = useState(); const [showSatsDetails, setShowSatsDetails] = useState(false); const [openWorldmap, setOpenWorldmap] = useState(false); + useEffect(() => { + setCoordinator(federation.getCoordinator(shortAlias)); + setCurrecyCode(currencies[(currentOrder?.currency ?? 1).toString()]); + }, [orderUpdatedAt]); + const amountString = useMemo(() => { if (currentOrder === null || currentOrder.amount === null) return; @@ -262,7 +269,7 @@ const OrderDetails = ({ {' '} - + @@ -527,6 +534,7 @@ const OrderDetails = ({ diff --git a/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx b/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx index c9f76097..9d3d76bc 100644 --- a/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx +++ b/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx @@ -98,16 +98,20 @@ const EncryptedSocketChat: React.FC = ({ }, [serverMessages]); const connectWebsocket = (): void => { + const robot = garage.getSlot()?.getRobot(); + + if (!robot) return; + websocketClient .open( - `ws://${window.location.host}/ws/chat/${orderId}/?token_sha256_hex=${sha256(robot.token)}`, + `ws://${window.location.host}/ws/chat/${orderId}/?token_sha256_hex=${sha256(robot?.token)}`, ) .then((connection) => { setConnection(connection); setConnected(true); connection.send({ - message: garage.getSlot()?.getRobot()?.pubKey, + message: robot?.pubKey, nick: userNick, });