From 88833a5a10bbe49b4b959ac7ccb43a7af855f10a Mon Sep 17 00:00:00 2001 From: KoalaSat Date: Wed, 15 Nov 2023 15:09:59 +0100 Subject: [PATCH] Fix last order --- frontend/src/basic/OrderPage/index.tsx | 18 +++++++++++++----- frontend/src/basic/RobotPage/RobotProfile.tsx | 6 +++--- frontend/src/components/RobotAvatar/index.tsx | 4 ++-- .../EncryptedTurtleChat/index.tsx | 12 ++++++------ frontend/src/components/TradeBox/index.tsx | 4 ++-- frontend/src/models/Garage.model.ts | 14 +++++++++----- frontend/src/models/Order.model.ts | 1 + frontend/src/models/Robot.model.ts | 1 - 8 files changed, 36 insertions(+), 24 deletions(-) diff --git a/frontend/src/basic/OrderPage/index.tsx b/frontend/src/basic/OrderPage/index.tsx index d622958b..1284f429 100644 --- a/frontend/src/basic/OrderPage/index.tsx +++ b/frontend/src/basic/OrderPage/index.tsx @@ -46,9 +46,13 @@ const OrderPage = (): JSX.Element => { } else { coordinator .fetchOrder(Number(params.orderId) ?? null, garage.getRobot()) - .then((response) => { - setCurrentOrder(response); - garage.updateOrder(response as Order); + .then((order) => { + if (order?.bad_request !== undefined) { + setBadOrder(order.bad_request); + } else { + setCurrentOrder(order); + garage.updateOrder(order as Order); + } }) .catch((e) => { console.log(e); @@ -57,8 +61,12 @@ const OrderPage = (): JSX.Element => { } else { coordinator .fetchOrder(Number(params.orderId) ?? null, garage.getRobot()) - .then((response) => { - setCurrentOrder(response); + .then((order) => { + if (order?.bad_request !== undefined) { + setBadOrder(order.bad_request); + } else { + setCurrentOrder(order); + } }) .catch((e) => { console.log(e); diff --git a/frontend/src/basic/RobotPage/RobotProfile.tsx b/frontend/src/basic/RobotPage/RobotProfile.tsx index 4d70dbe8..fc168b78 100644 --- a/frontend/src/basic/RobotPage/RobotProfile.tsx +++ b/frontend/src/basic/RobotPage/RobotProfile.tsx @@ -170,13 +170,13 @@ const RobotProfile = ({ diff --git a/frontend/src/components/RobotAvatar/index.tsx b/frontend/src/components/RobotAvatar/index.tsx index ca50b4fa..d49d8bda 100644 --- a/frontend/src/components/RobotAvatar/index.tsx +++ b/frontend/src/components/RobotAvatar/index.tsx @@ -68,11 +68,11 @@ const RobotAvatar: React.FC = ({ setNicknameReady(true); } else if (focusedCoordinator != null) { setNicknameReady(true); - const { url } = federation + const { url, basePath } = federation .getCoordinator(focusedCoordinator) .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); void apiClient - .fileImageUrl(url, `${path}${nickname}${small ? '.small' : ''}.webp`) + .fileImageUrl(url + basePath, `${path}${nickname}${small ? '.small' : ''}.webp`) .then(setAvatarSrc); } } else { diff --git a/frontend/src/components/TradeBox/EncryptedChat/EncryptedTurtleChat/index.tsx b/frontend/src/components/TradeBox/EncryptedChat/EncryptedTurtleChat/index.tsx index 52dcb1a6..8f5c9991 100644 --- a/frontend/src/components/TradeBox/EncryptedChat/EncryptedTurtleChat/index.tsx +++ b/frontend/src/components/TradeBox/EncryptedChat/EncryptedTurtleChat/index.tsx @@ -82,11 +82,11 @@ const EncryptedTurtleChat: React.FC = ({ }, [chatOffset]); const loadMessages: () => void = () => { - const { url } = federation + const { url, basePath } = federation .getCoordinator(focusedCoordinator) .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); apiClient - .get(url, `/api/chat/?order_id=${orderId}&offset=${lastIndex}`, { + .get(url + basePath, `/api/chat/?order_id=${orderId}&offset=${lastIndex}`, { tokenSHA256: robot.tokenSHA256, }) .then((results: any) => { @@ -177,12 +177,12 @@ const EncryptedTurtleChat: React.FC = ({ } // If input string contains '#' send unencrypted and unlogged message else if (value.substring(0, 1) === '#') { - const { url } = federation + const { url, basePath } = federation .getCoordinator(focusedCoordinator) .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); apiClient .post( - url, + url + basePath, `/api/chat/`, { PGP_message: value, @@ -210,12 +210,12 @@ const EncryptedTurtleChat: React.FC = ({ setLastSent(value); encryptMessage(value, robot.pubKey, peerPubKey, robot.encPrivKey, robot.token) .then((encryptedMessage) => { - const { url } = federation + const { url, basePath } = federation .getCoordinator(focusedCoordinator) .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); apiClient .post( - url, + url + basePath, `/api/chat/`, { PGP_message: String(encryptedMessage).split('\n').join('\\'), diff --git a/frontend/src/components/TradeBox/index.tsx b/frontend/src/components/TradeBox/index.tsx index 1338343f..4b42ec3f 100644 --- a/frontend/src/components/TradeBox/index.tsx +++ b/frontend/src/components/TradeBox/index.tsx @@ -165,12 +165,12 @@ const TradeBox = ({ statement, rating, }: SubmitActionProps): void { - const { url } = federation + const { url, basePath } = federation .getCoordinator(currentOrder.shortAlias) .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); void apiClient .post( - url, + url + basePath, `/api/order/?order_id=${Number(currentOrder.id)}`, { action, diff --git a/frontend/src/models/Garage.model.ts b/frontend/src/models/Garage.model.ts index 2eea25df..84d413d0 100644 --- a/frontend/src/models/Garage.model.ts +++ b/frontend/src/models/Garage.model.ts @@ -112,13 +112,17 @@ class Garage { const robot = this.getSlot(index).robot; if (robot != null) { robot.update(attributes); - if (attributes.activeOrderId != null) { - this.slots[index].activeOrderId = attributes.activeOrderId; - this.slots[index].activeOrderShortAlias = attributes.shortAlias; - } - if (attributes.lastOrderId != null) { + if (attributes.lastOrderId && attributes.lastOrderId != null) { this.slots[index].lastOrderId = attributes.lastOrderId; this.slots[index].lastOrderShortAlias = attributes.shortAlias; + if (attributes.lastOrderId === this.slots[index].activeOrderId) { + this.slots[index].activeOrderId = null; + this.slots[index].activeOrderShortAlias = null; + } + } + if (attributes.activeOrderId && attributes.activeOrderId != null) { + this.slots[index].activeOrderId = attributes.activeOrderId; + this.slots[index].activeOrderShortAlias = attributes.shortAlias; } this.triggerHook('onRobotUpdate'); this.save(); diff --git a/frontend/src/models/Order.model.ts b/frontend/src/models/Order.model.ts index 4237dab1..06371026 100644 --- a/frontend/src/models/Order.model.ts +++ b/frontend/src/models/Order.model.ts @@ -105,6 +105,7 @@ export interface Order { address: string; network: 'mainnet' | 'testnet'; shortAlias: string; + bad_request?: string; } export const defaultOrder: Order = { diff --git a/frontend/src/models/Robot.model.ts b/frontend/src/models/Robot.model.ts index 19d6d3fa..05e6bbf7 100644 --- a/frontend/src/models/Robot.model.ts +++ b/frontend/src/models/Robot.model.ts @@ -39,7 +39,6 @@ class Robot { public last_login: string = ''; public copiedToken: boolean = false; public avatarLoaded: boolean = false; - public shortAlias: string = ''; update = (attributes: Record): void => { Object.assign(this, attributes);