mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-23 04:33:23 +00:00
@ -56,6 +56,10 @@ const OrderPage = (): JSX.Element => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCurrentOrder(null);
|
setCurrentOrder(null);
|
||||||
|
updateCurrentOrder();
|
||||||
|
}, [currentOrderId]);
|
||||||
|
|
||||||
|
const updateCurrentOrder = () => {
|
||||||
if (currentOrderId !== null) {
|
if (currentOrderId !== null) {
|
||||||
const coordinator = federation.getCoordinator(params.shortAlias ?? '');
|
const coordinator = federation.getCoordinator(params.shortAlias ?? '');
|
||||||
const slot = garage.getSlot();
|
const slot = garage.getSlot();
|
||||||
@ -79,7 +83,7 @@ const OrderPage = (): JSX.Element => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [currentOrderId]);
|
};
|
||||||
|
|
||||||
const onClickCoordinator = function (): void {
|
const onClickCoordinator = function (): void {
|
||||||
if (currentOrder?.shortAlias != null) {
|
if (currentOrder?.shortAlias != null) {
|
||||||
@ -97,8 +101,8 @@ const OrderPage = (): JSX.Element => {
|
|||||||
<OrderDetails
|
<OrderDetails
|
||||||
shortAlias={String(currentOrder.shortAlias)}
|
shortAlias={String(currentOrder.shortAlias)}
|
||||||
currentOrder={currentOrder}
|
currentOrder={currentOrder}
|
||||||
|
updateCurrentOrder={updateCurrentOrder}
|
||||||
onClickCoordinator={onClickCoordinator}
|
onClickCoordinator={onClickCoordinator}
|
||||||
baseUrl={baseUrl}
|
|
||||||
onClickGenerateRobot={() => {
|
onClickGenerateRobot={() => {
|
||||||
navigate('/robot');
|
navigate('/robot');
|
||||||
}}
|
}}
|
||||||
|
@ -69,6 +69,7 @@ const RobotProfile = ({
|
|||||||
|
|
||||||
const handleChangeSlot = (e: SelectChangeEvent<number | 'loading'>): void => {
|
const handleChangeSlot = (e: SelectChangeEvent<number | 'loading'>): void => {
|
||||||
garage.currentSlot = e.target.value;
|
garage.currentSlot = e.target.value;
|
||||||
|
setInputToken(garage.getSlot()?.getRobot()?.token ?? '');
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import { type UseFederationStoreType, FederationContext } from '../../contexts/F
|
|||||||
interface TakeButtonProps {
|
interface TakeButtonProps {
|
||||||
currentOrder: Order;
|
currentOrder: Order;
|
||||||
info?: Info;
|
info?: Info;
|
||||||
|
updateCurrentOrder?: () => void;
|
||||||
onClickGenerateRobot?: () => void;
|
onClickGenerateRobot?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ const closeAll = { inactiveMaker: false, confirmation: false };
|
|||||||
const TakeButton = ({
|
const TakeButton = ({
|
||||||
currentOrder,
|
currentOrder,
|
||||||
info,
|
info,
|
||||||
|
updateCurrentOrder = () => null,
|
||||||
onClickGenerateRobot = () => null,
|
onClickGenerateRobot = () => null,
|
||||||
}: TakeButtonProps): JSX.Element => {
|
}: TakeButtonProps): JSX.Element => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -333,11 +335,10 @@ const TakeButton = ({
|
|||||||
{ tokenSHA256: robot?.tokenSHA256 },
|
{ tokenSHA256: robot?.tokenSHA256 },
|
||||||
)
|
)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setLoadingTake(false);
|
|
||||||
if (data?.bad_request !== undefined) {
|
if (data?.bad_request !== undefined) {
|
||||||
setBadRequest(data.bad_request);
|
setBadRequest(data.bad_request);
|
||||||
} else {
|
} else {
|
||||||
garage.updateOrder(data as Order);
|
updateCurrentOrder();
|
||||||
setBadRequest('');
|
setBadRequest('');
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -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 { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
List,
|
List,
|
||||||
@ -47,27 +47,34 @@ import { type Order } from '../../models';
|
|||||||
interface OrderDetailsProps {
|
interface OrderDetailsProps {
|
||||||
shortAlias: string;
|
shortAlias: string;
|
||||||
currentOrder: Order;
|
currentOrder: Order;
|
||||||
|
updateCurrentOrder?: () => void;
|
||||||
onClickCoordinator?: () => void;
|
onClickCoordinator?: () => void;
|
||||||
baseUrl: string;
|
|
||||||
onClickGenerateRobot?: () => void;
|
onClickGenerateRobot?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const OrderDetails = ({
|
const OrderDetails = ({
|
||||||
shortAlias,
|
shortAlias,
|
||||||
currentOrder,
|
currentOrder,
|
||||||
|
updateCurrentOrder = () => null,
|
||||||
onClickCoordinator = () => null,
|
onClickCoordinator = () => null,
|
||||||
baseUrl,
|
|
||||||
onClickGenerateRobot = () => null,
|
onClickGenerateRobot = () => null,
|
||||||
}: OrderDetailsProps): JSX.Element => {
|
}: OrderDetailsProps): JSX.Element => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { federation } = useContext<UseFederationStoreType>(FederationContext);
|
const { federation } = useContext<UseFederationStoreType>(FederationContext);
|
||||||
const { orderUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
|
const { orderUpdatedAt } = useContext<UseGarageStoreType>(GarageContext);
|
||||||
const [coordinator] = useState<Coordinator | null>(federation.getCoordinator(shortAlias));
|
const [coordinator, setCoordinator] = useState<Coordinator | null>(
|
||||||
const currencyCode: string = currencies[(currentOrder?.currency ?? 1).toString()];
|
federation.getCoordinator(shortAlias),
|
||||||
|
);
|
||||||
|
const [currencyCode, setCurrecyCode] = useState<string | null>();
|
||||||
const [showSatsDetails, setShowSatsDetails] = useState<boolean>(false);
|
const [showSatsDetails, setShowSatsDetails] = useState<boolean>(false);
|
||||||
const [openWorldmap, setOpenWorldmap] = useState<boolean>(false);
|
const [openWorldmap, setOpenWorldmap] = useState<boolean>(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setCoordinator(federation.getCoordinator(shortAlias));
|
||||||
|
setCurrecyCode(currencies[(currentOrder?.currency ?? 1).toString()]);
|
||||||
|
}, [orderUpdatedAt]);
|
||||||
|
|
||||||
const amountString = useMemo(() => {
|
const amountString = useMemo(() => {
|
||||||
if (currentOrder === null || currentOrder.amount === null) return;
|
if (currentOrder === null || currentOrder.amount === null) return;
|
||||||
|
|
||||||
@ -262,7 +269,7 @@ const OrderDetails = ({
|
|||||||
{' '}
|
{' '}
|
||||||
<Grid container direction='row' justifyContent='center' alignItems='center'>
|
<Grid container direction='row' justifyContent='center' alignItems='center'>
|
||||||
<Grid item xs={2}>
|
<Grid item xs={2}>
|
||||||
<RobotAvatar shortAlias={coordinator.shortAlias} coordinator={true} small={true} />
|
<RobotAvatar shortAlias={coordinator.shortAlias} small={true} />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={4}>
|
<Grid item xs={4}>
|
||||||
<ListItemText primary={coordinator.longAlias} secondary={t('Order host')} />
|
<ListItemText primary={coordinator.longAlias} secondary={t('Order host')} />
|
||||||
@ -527,6 +534,7 @@ const OrderDetails = ({
|
|||||||
<TakeButton
|
<TakeButton
|
||||||
currentOrder={currentOrder}
|
currentOrder={currentOrder}
|
||||||
info={coordinator.info}
|
info={coordinator.info}
|
||||||
|
updateCurrentOrder={updateCurrentOrder}
|
||||||
onClickGenerateRobot={onClickGenerateRobot}
|
onClickGenerateRobot={onClickGenerateRobot}
|
||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -98,16 +98,20 @@ const EncryptedSocketChat: React.FC<Props> = ({
|
|||||||
}, [serverMessages]);
|
}, [serverMessages]);
|
||||||
|
|
||||||
const connectWebsocket = (): void => {
|
const connectWebsocket = (): void => {
|
||||||
|
const robot = garage.getSlot()?.getRobot();
|
||||||
|
|
||||||
|
if (!robot) return;
|
||||||
|
|
||||||
websocketClient
|
websocketClient
|
||||||
.open(
|
.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) => {
|
.then((connection) => {
|
||||||
setConnection(connection);
|
setConnection(connection);
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
|
|
||||||
connection.send({
|
connection.send({
|
||||||
message: garage.getSlot()?.getRobot()?.pubKey,
|
message: robot?.pubKey,
|
||||||
nick: userNick,
|
nick: userNick,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user