Fix last order

This commit is contained in:
KoalaSat 2023-11-15 15:09:59 +01:00 committed by Reckless_Satoshi
parent 7c06c229b4
commit 88833a5a10
8 changed files with 36 additions and 24 deletions

View File

@ -46,9 +46,13 @@ const OrderPage = (): JSX.Element => {
} else { } else {
coordinator coordinator
.fetchOrder(Number(params.orderId) ?? null, garage.getRobot()) .fetchOrder(Number(params.orderId) ?? null, garage.getRobot())
.then((response) => { .then((order) => {
setCurrentOrder(response); if (order?.bad_request !== undefined) {
garage.updateOrder(response as Order); setBadOrder(order.bad_request);
} else {
setCurrentOrder(order);
garage.updateOrder(order as Order);
}
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);
@ -57,8 +61,12 @@ const OrderPage = (): JSX.Element => {
} else { } else {
coordinator coordinator
.fetchOrder(Number(params.orderId) ?? null, garage.getRobot()) .fetchOrder(Number(params.orderId) ?? null, garage.getRobot())
.then((response) => { .then((order) => {
setCurrentOrder(response); if (order?.bad_request !== undefined) {
setBadOrder(order.bad_request);
} else {
setCurrentOrder(order);
}
}) })
.catch((e) => { .catch((e) => {
console.log(e); console.log(e);

View File

@ -170,13 +170,13 @@ const RobotProfile = ({
<Button <Button
onClick={() => { onClick={() => {
navigate( navigate(
`/order/${String(garage.getRobot()?.shortAlias)}/${String( `/order/${String(garage.getSlot().lastOrderShortAlias)}/${String(
garage.getRobot()?.lastOrderId, garage.getSlot().lastOrderId,
)}`, )}`,
); );
}} }}
> >
{t('Last order #{{orderID}}', { orderID: garage.getRobot().lastOrderId })} {t('Last order #{{orderID}}', { orderID: garage.getSlot().lastOrderId })}
</Button> </Button>
</Grid> </Grid>
<Grid item> <Grid item>

View File

@ -68,11 +68,11 @@ const RobotAvatar: React.FC<Props> = ({
setNicknameReady(true); setNicknameReady(true);
} else if (focusedCoordinator != null) { } else if (focusedCoordinator != null) {
setNicknameReady(true); setNicknameReady(true);
const { url } = federation const { url, basePath } = federation
.getCoordinator(focusedCoordinator) .getCoordinator(focusedCoordinator)
.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl);
void apiClient void apiClient
.fileImageUrl(url, `${path}${nickname}${small ? '.small' : ''}.webp`) .fileImageUrl(url + basePath, `${path}${nickname}${small ? '.small' : ''}.webp`)
.then(setAvatarSrc); .then(setAvatarSrc);
} }
} else { } else {

View File

@ -82,11 +82,11 @@ const EncryptedTurtleChat: React.FC<Props> = ({
}, [chatOffset]); }, [chatOffset]);
const loadMessages: () => void = () => { const loadMessages: () => void = () => {
const { url } = federation const { url, basePath } = federation
.getCoordinator(focusedCoordinator) .getCoordinator(focusedCoordinator)
.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl);
apiClient apiClient
.get(url, `/api/chat/?order_id=${orderId}&offset=${lastIndex}`, { .get(url + basePath, `/api/chat/?order_id=${orderId}&offset=${lastIndex}`, {
tokenSHA256: robot.tokenSHA256, tokenSHA256: robot.tokenSHA256,
}) })
.then((results: any) => { .then((results: any) => {
@ -177,12 +177,12 @@ const EncryptedTurtleChat: React.FC<Props> = ({
} }
// If input string contains '#' send unencrypted and unlogged message // If input string contains '#' send unencrypted and unlogged message
else if (value.substring(0, 1) === '#') { else if (value.substring(0, 1) === '#') {
const { url } = federation const { url, basePath } = federation
.getCoordinator(focusedCoordinator) .getCoordinator(focusedCoordinator)
.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl);
apiClient apiClient
.post( .post(
url, url + basePath,
`/api/chat/`, `/api/chat/`,
{ {
PGP_message: value, PGP_message: value,
@ -210,12 +210,12 @@ const EncryptedTurtleChat: React.FC<Props> = ({
setLastSent(value); setLastSent(value);
encryptMessage(value, robot.pubKey, peerPubKey, robot.encPrivKey, robot.token) encryptMessage(value, robot.pubKey, peerPubKey, robot.encPrivKey, robot.token)
.then((encryptedMessage) => { .then((encryptedMessage) => {
const { url } = federation const { url, basePath } = federation
.getCoordinator(focusedCoordinator) .getCoordinator(focusedCoordinator)
.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl);
apiClient apiClient
.post( .post(
url, url + basePath,
`/api/chat/`, `/api/chat/`,
{ {
PGP_message: String(encryptedMessage).split('\n').join('\\'), PGP_message: String(encryptedMessage).split('\n').join('\\'),

View File

@ -165,12 +165,12 @@ const TradeBox = ({
statement, statement,
rating, rating,
}: SubmitActionProps): void { }: SubmitActionProps): void {
const { url } = federation const { url, basePath } = federation
.getCoordinator(currentOrder.shortAlias) .getCoordinator(currentOrder.shortAlias)
.getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl); .getEndpoint(settings.network, origin, settings.selfhostedClient, hostUrl);
void apiClient void apiClient
.post( .post(
url, url + basePath,
`/api/order/?order_id=${Number(currentOrder.id)}`, `/api/order/?order_id=${Number(currentOrder.id)}`,
{ {
action, action,

View File

@ -112,13 +112,17 @@ class Garage {
const robot = this.getSlot(index).robot; const robot = this.getSlot(index).robot;
if (robot != null) { if (robot != null) {
robot.update(attributes); robot.update(attributes);
if (attributes.activeOrderId != null) { if (attributes.lastOrderId && attributes.lastOrderId != null) {
this.slots[index].activeOrderId = attributes.activeOrderId;
this.slots[index].activeOrderShortAlias = attributes.shortAlias;
}
if (attributes.lastOrderId != null) {
this.slots[index].lastOrderId = attributes.lastOrderId; this.slots[index].lastOrderId = attributes.lastOrderId;
this.slots[index].lastOrderShortAlias = attributes.shortAlias; 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.triggerHook('onRobotUpdate');
this.save(); this.save();

View File

@ -105,6 +105,7 @@ export interface Order {
address: string; address: string;
network: 'mainnet' | 'testnet'; network: 'mainnet' | 'testnet';
shortAlias: string; shortAlias: string;
bad_request?: string;
} }
export const defaultOrder: Order = { export const defaultOrder: Order = {

View File

@ -39,7 +39,6 @@ class Robot {
public last_login: string = ''; public last_login: string = '';
public copiedToken: boolean = false; public copiedToken: boolean = false;
public avatarLoaded: boolean = false; public avatarLoaded: boolean = false;
public shortAlias: string = '';
update = (attributes: Record<string, any>): void => { update = (attributes: Record<string, any>): void => {
Object.assign(this, attributes); Object.assign(this, attributes);