From 7f78f69df662e5c018480a38a350453d1ca74b6c Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Thu, 2 Nov 2023 14:15:18 +0000 Subject: [PATCH] More fixes --- frontend/src/components/BookTable/index.tsx | 2 +- frontend/src/components/Map/index.tsx | 4 +- .../components/OrderDetails/TakeButton.tsx | 8 +-- .../src/components/OrderDetails/index.tsx | 21 +++++--- frontend/src/components/RobotAvatar/index.tsx | 2 +- frontend/src/components/RobotInfo/index.tsx | 10 ++-- .../src/components/TradeBox/CancelButton.tsx | 9 ++-- .../components/TradeBox/CollabCancelAlert.tsx | 4 +- .../TradeBox/Dialogs/ConfirmUndoFiatSent.tsx | 1 - .../EncryptedSocketChat/index.tsx | 3 +- frontend/src/components/TradeBox/index.tsx | 11 ++-- frontend/src/contexts/FederationContext.ts | 54 ++++++++++--------- frontend/src/models/Coordinator.model.ts | 36 ++++++------- frontend/src/models/Exchange.model.ts | 2 +- frontend/src/models/Federation.model.ts | 32 +++++------ frontend/src/models/Garage.model.ts | 2 +- frontend/src/models/Robot.model.ts | 6 +-- frontend/src/pro/Widgets/Book.tsx | 2 +- frontend/src/pro/Widgets/Depth.tsx | 2 +- frontend/src/pro/Widgets/Maker.tsx | 2 +- 20 files changed, 113 insertions(+), 100 deletions(-) diff --git a/frontend/src/components/BookTable/index.tsx b/frontend/src/components/BookTable/index.tsx index 677c6ed8..9a65a9c1 100644 --- a/frontend/src/components/BookTable/index.tsx +++ b/frontend/src/components/BookTable/index.tsx @@ -835,7 +835,7 @@ const BookTable = ({ { - federation.update(); + void federation.update(); }} > diff --git a/frontend/src/components/Map/index.tsx b/frontend/src/components/Map/index.tsx index 6f7286c2..ee2a2ee4 100644 --- a/frontend/src/components/Map/index.tsx +++ b/frontend/src/components/Map/index.tsx @@ -81,7 +81,7 @@ const Map = ({ } eventHandlers={{ click: (_event: LeafletMouseEvent) => { - order?.id && onOrderClicked(order.id); + order?.id != null && onOrderClicked(order.id); }, }} > @@ -111,7 +111,7 @@ const Map = ({ return ( {orders.map((order) => { - if (!order?.latitude || !order?.longitude) return <>; + if (!(order?.latitude != null) || !(order?.longitude != null)) return <>; return RobotMarker(order.id, [order.latitude, order.longitude], order.type ?? 0, order); })} diff --git a/frontend/src/components/OrderDetails/TakeButton.tsx b/frontend/src/components/OrderDetails/TakeButton.tsx index 7a27aa4a..2facd2ba 100644 --- a/frontend/src/components/OrderDetails/TakeButton.tsx +++ b/frontend/src/components/OrderDetails/TakeButton.tsx @@ -82,7 +82,9 @@ const TakeButton = ({ }, [orderUpdatedAt, takeAmount, info]); const currencyCode: string = - garage.getOrder()?.currency === 1000 ? 'Sats' : currencies[`${garage.getOrder()?.currency}`]; + garage.getOrder()?.currency === 1000 + ? 'Sats' + : currencies[`${Number(garage.getOrder()?.currency)}`]; const InactiveMakerDialog = function (): JSX.Element { return ( @@ -188,7 +190,7 @@ const TakeButton = ({ }, [takeAmount, orderUpdatedAt]); const takeOrderButton = function (): JSX.Element { - if (garage.getOrder()?.has_range) { + if (garage.getOrder()?.has_range === true) { return ( - {currentOrder.order?.payment_method.includes('Cash F2F') && ( + {currentOrder.order?.payment_method.includes('Cash F2F') === true && (
@@ -457,14 +460,16 @@ const OrderDetails = ({ /> ) : null} - {currentOrder.order?.price_now === undefined && currentOrder.order?.is_explicit ? ( + {currentOrder.order?.price_now === undefined && + currentOrder.order?.is_explicit === true ? ( ) : null} - {currentOrder.order?.price_now === undefined && !currentOrder.order?.is_explicit ? ( + {currentOrder.order?.price_now === undefined && + !(currentOrder.order?.is_explicit === true) ? ( )} - {!currentOrder.order?.is_participant ? ( + {!(currentOrder.order?.is_participant === true) ? ( = ({ if (window.NativeRobosats === undefined) { setAvatarSrc(`${baseUrl}${path}${nickname}${small ? '.small' : ''}.webp`); setNicknameReady(true); - } else if (focusedCoordinator) { + } else if (focusedCoordinator != null) { setNicknameReady(true); const { url } = federation .getCoordinator(focusedCoordinator) diff --git a/frontend/src/components/RobotInfo/index.tsx b/frontend/src/components/RobotInfo/index.tsx index 58b493e4..3a419be5 100644 --- a/frontend/src/components/RobotInfo/index.tsx +++ b/frontend/src/components/RobotInfo/index.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useEffect, useMemo, useState } from 'react'; +import React, { useContext, useEffect, useState } from 'react'; import { Tooltip, @@ -66,7 +66,7 @@ const RobotInfo: React.FC = ({ robot, slotIndex, coordinator, onClose }: }; useEffect(() => { - handleWebln(); + void handleWebln(); }, []); const handleWeblnInvoiceClicked = async (e: MouseEvent): void => { @@ -87,10 +87,10 @@ const RobotInfo: React.FC = ({ robot, slotIndex, coordinator, onClose }: const robot = garage.getRobot(slotIndex); - if (robot.encPrivKey && robot.token) { + if (robot.encPrivKey != null && robot.token != null) { void signCleartextMessage(rewardInvoice, robot.encPrivKey, robot.token).then( (signedInvoice) => { - coordinator.fetchReward(signedInvoice, garage, slotIndex).then((data) => { + void coordinator.fetchReward(signedInvoice, garage, slotIndex).then((data) => { setBadInvoice(data.bad_invoice ?? ''); setShowRewardsSpinner(false); setWithdrawn(data.successful_withdrawal); @@ -103,7 +103,7 @@ const RobotInfo: React.FC = ({ robot, slotIndex, coordinator, onClose }: }; const setStealthInvoice = (wantsStealth: boolean): void => { - coordinator.fetchStealth(wantsStealth, garage, slotIndex); + void coordinator.fetchStealth(wantsStealth, garage, slotIndex); }; return ( diff --git a/frontend/src/components/TradeBox/CancelButton.tsx b/frontend/src/components/TradeBox/CancelButton.tsx index a9a5a29e..84fcbcc4 100644 --- a/frontend/src/components/TradeBox/CancelButton.tsx +++ b/frontend/src/components/TradeBox/CancelButton.tsx @@ -22,12 +22,13 @@ const CancelButton = ({ const { t } = useTranslation(); const showCancelButton = - (order?.is_maker && [0, 1, 2].includes(order?.status)) || + (order?.is_maker === true && [0, 1, 2].includes(order?.status)) ?? [3, 6, 7].includes(order?.status ?? -1); - const showCollabCancelButton = [8, 9].includes(order?.status ?? -1) && !order?.asked_for_cancel; + const showCollabCancelButton = + [8, 9].includes(order?.status ?? -1) && !(order?.asked_for_cancel === true); const noConfirmation = - (order?.is_maker && [0, 1, 2].includes(order?.status ?? -1)) || - (order?.is_taker && order?.status === 3); + (order?.is_maker === true && [0, 1, 2].includes(order?.status ?? -1)) ?? + (order?.is_taker === true && order?.status === 3); return ( diff --git a/frontend/src/components/TradeBox/CollabCancelAlert.tsx b/frontend/src/components/TradeBox/CollabCancelAlert.tsx index d1d365d6..479579b2 100644 --- a/frontend/src/components/TradeBox/CollabCancelAlert.tsx +++ b/frontend/src/components/TradeBox/CollabCancelAlert.tsx @@ -10,11 +10,11 @@ interface CollabCancelAlertProps { const CollabCancelAlert = ({ order }: CollabCancelAlertProps): JSX.Element => { const { t } = useTranslation(); let text = ''; - if (order?.pending_cancel) { + if (order?.pending_cancel === true) { text = t('{{nickname}} is asking for a collaborative cancel', { nickname: order?.is_maker ? order?.taker_nick : order?.maker_nick, }); - } else if (order?.asked_for_cancel) { + } else if (order?.asked_for_cancel === true) { text = t('You asked for a collaborative cancellation'); } diff --git a/frontend/src/components/TradeBox/Dialogs/ConfirmUndoFiatSent.tsx b/frontend/src/components/TradeBox/Dialogs/ConfirmUndoFiatSent.tsx index cb5f82ca..006e83ca 100644 --- a/frontend/src/components/TradeBox/Dialogs/ConfirmUndoFiatSent.tsx +++ b/frontend/src/components/TradeBox/Dialogs/ConfirmUndoFiatSent.tsx @@ -8,7 +8,6 @@ import { DialogContentText, Button, } from '@mui/material'; -import { type Order } from '../../../models'; import { LoadingButton } from '@mui/lab'; interface ConfirmUndoFiatSentDialogProps { diff --git a/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx b/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx index 42251b06..95f8f78e 100644 --- a/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx +++ b/frontend/src/components/TradeBox/EncryptedChat/EncryptedSocketChat/index.tsx @@ -1,10 +1,11 @@ -import React, { useEffect, useLayoutEffect, useState } from 'react'; +import React, { useEffect, useLayoutEffect, useState, useContext } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, TextField, Grid, Paper, Typography } from '@mui/material'; import { encryptMessage, decryptMessage } from '../../../../pgp'; import { AuditPGPDialog } from '../../../Dialogs'; import { websocketClient, type WebsocketConnection } from '../../../../services/Websocket'; import { type Robot } from '../../../../models'; +import { GarageContext, type UseGarageStoreType } from '../../../../contexts/GarageContext'; // Icons import CircularProgress from '@mui/material/CircularProgress'; diff --git a/frontend/src/components/TradeBox/index.tsx b/frontend/src/components/TradeBox/index.tsx index 8fcd7e88..77703d3a 100644 --- a/frontend/src/components/TradeBox/index.tsx +++ b/frontend/src/components/TradeBox/index.tsx @@ -58,6 +58,7 @@ interface loadingButtonsProps { cancel: boolean; fiatSent: boolean; fiatReceived: boolean; + undoFiatSent: boolean; submitInvoice: boolean; submitAddress: boolean; submitStatement: boolean; @@ -70,6 +71,7 @@ const noLoadingButtons: loadingButtonsProps = { cancel: false, fiatSent: false, fiatReceived: false, + undoFiatSent: false, submitInvoice: false, submitAddress: false, submitStatement: false, @@ -167,7 +169,7 @@ const TradeBox = ({ void apiClient .post( url, - `/api/order/?order_id=${currentOrder.id}`, + `/api/order/?order_id=${Number(currentOrder.id)}`, { action, invoice, @@ -234,7 +236,7 @@ const TradeBox = ({ const updateInvoice = function (invoice: string): void { const robot = garage.getRobot(); - if (robot !== null && robot.encPrivKey && robot.token) { + if (robot?.encPrivKey != null && robot?.token != null) { setLoadingButtons({ ...noLoadingButtons, submitInvoice: true }); void signCleartextMessage(invoice, robot.encPrivKey, robot.token).then((signedInvoice) => { submitAction({ @@ -249,7 +251,7 @@ const TradeBox = ({ const updateAddress = function (): void { const robot = garage.getRobot(); - if (robot !== null && robot.encPrivKey && robot.token) { + if (robot?.encPrivKey != null && robot?.token != null) { setLoadingButtons({ ...noLoadingButtons, submitAddress: true }); void signCleartextMessage(onchain.address, robot.encPrivKey, robot.token).then( (signedAddress) => { @@ -287,6 +289,7 @@ const TradeBox = ({ }); // If Webln implements locked payments compatibility, this logic might be simplier if (webln === undefined) { + console.log('WebLN dialog will not be shown'); } else if (order.is_maker && order.status === 0) { webln.sendPayment(order.bond_invoice); setWaitingWebln(true); @@ -324,7 +327,7 @@ const TradeBox = ({ useEffect(() => { if (currentOrder.order !== null && currentOrder.order.status !== lastOrderStatus) { setLastOrderStatus(currentOrder.order.status); - handleWebln(currentOrder.order); + void handleWebln(currentOrder.order); } // FIXME this should trigger with current order, not garage order }, [orderUpdatedAt]); diff --git a/frontend/src/contexts/FederationContext.ts b/frontend/src/contexts/FederationContext.ts index 7627216a..2d4810af 100644 --- a/frontend/src/contexts/FederationContext.ts +++ b/frontend/src/contexts/FederationContext.ts @@ -16,27 +16,29 @@ import { AppContext, type UseAppStoreType } from './AppContext'; import { GarageContext, type UseGarageStoreType } from './GarageContext'; // Refresh delays (ms) according to Order status -const statusToDelay = [ - 3000, // 'Waiting for maker bond' - 35000, // 'Public' - 180000, // 'Paused' - 3000, // 'Waiting for taker bond' - 999999, // 'Cancelled' - 999999, // 'Expired' - 8000, // 'Waiting for trade collateral and buyer invoice' - 8000, // 'Waiting only for seller trade collateral' - 8000, // 'Waiting only for buyer invoice' - 10000, // 'Sending fiat - In chatroom' - 10000, // 'Fiat sent - In chatroom' - 100000, // 'In dispute' - 999999, // 'Collaboratively cancelled' - 10000, // 'Sending satoshis to buyer' - 60000, // 'Sucessful trade' - 30000, // 'Failed lightning network routing' - 300000, // 'Wait for dispute resolution' - 300000, // 'Maker lost dispute' - 300000, // 'Taker lost dispute' -]; + +// FIXME statusToDelay is never used. On order received, we should setDelay according to new received status. +// const statusToDelay = [ +// 3000, // 'Waiting for maker bond' +// 35000, // 'Public' +// 180000, // 'Paused' +// 3000, // 'Waiting for taker bond' +// 999999, // 'Cancelled' +// 999999, // 'Expired' +// 8000, // 'Waiting for trade collateral and buyer invoice' +// 8000, // 'Waiting only for seller trade collateral' +// 8000, // 'Waiting only for buyer invoice' +// 10000, // 'Sending fiat - In chatroom' +// 10000, // 'Fiat sent - In chatroom' +// 100000, // 'In dispute' +// 999999, // 'Collaboratively cancelled' +// 10000, // 'Sending satoshis to buyer' +// 60000, // 'Sucessful trade' +// 30000, // 'Failed lightning network routing' +// 300000, // 'Wait for dispute resolution' +// 300000, // 'Maker lost dispute' +// 300000, // 'Taker lost dispute' +// ]; export interface fetchRobotProps { coordinator?: Coordinator; @@ -128,14 +130,14 @@ export const useFederationStore = (): UseFederationStoreType => { newFed.registerHook('onCoordinatorUpdate', () => { setFederationUpdatedAt(new Date().toISOString()); }); - newFed.start(origin, settings, hostUrl); + void newFed.start(origin, settings, hostUrl); return newFed; }); }, [settings.network, torStatus]); - const fetchCurrentOrder = () => { + const fetchCurrentOrder = (): void => { if (currentOrder.id != null && (page === 'order' || badOrder === undefined)) { - federation.fetchOrder(currentOrder, garage.getRobot()); + void federation.fetchOrder(currentOrder, garage.getRobot()); } }; @@ -157,14 +159,14 @@ export const useFederationStore = (): UseFederationStoreType => { if (robot !== null) { if (open.profile && robot?.avatarLoaded) { - federation.fetchRobot(garage, garage.currentSlot); // refresh/update existing robot + void federation.fetchRobot(garage, garage.currentSlot); // refresh/update existing robot } else if ( !robot.avatarLoaded && robot.token !== undefined && robot.encPrivKey !== undefined && robot.pubKey !== undefined ) { - federation.fetchRobot(garage, garage.currentSlot); // create new robot with existing token and keys (on network and coordinator change) + void federation.fetchRobot(garage, garage.currentSlot); // create new robot with existing token and keys (on network and coordinator change) } } }, [open.profile, hostUrl, robotUpdatedAt]); diff --git a/frontend/src/models/Coordinator.model.ts b/frontend/src/models/Coordinator.model.ts index 65c2d518..8369acad 100644 --- a/frontend/src/models/Coordinator.model.ts +++ b/frontend/src/models/Coordinator.model.ts @@ -1,4 +1,3 @@ -import { sha256 } from 'js-sha256'; import { type Robot, type LimitList, @@ -8,9 +7,8 @@ import { type Garage, } from '.'; import { apiClient } from '../services/api'; -import { hexToBase91, validateTokenEntropy } from '../utils'; +import { validateTokenEntropy } from '../utils'; import { compareUpdateLimit } from './Limit.model'; -import { signCleartextMessage } from '../pgp'; export interface Contact { nostr?: string | undefined; @@ -132,7 +130,7 @@ export class Coordinator { hostUrl: string, onStarted: (shortAlias: string) => void = () => {}, ): Promise => { - if (!this.enabled) return; + if (this.enabled !== true) return; if (settings.selfhostedClient && this.shortAlias !== 'local') { this.url = hostUrl; @@ -142,13 +140,13 @@ export class Coordinator { this.basePath = ''; } - this.update(() => { + void this.update(() => { onStarted(this.shortAlias); }); }; update = async (onUpdate: (shortAlias: string) => void = () => {}): Promise => { - const onDataLoad = () => { + const onDataLoad = (): void => { if (this.isUpdated()) onUpdate(this.shortAlias); }; @@ -157,7 +155,7 @@ export class Coordinator { this.loadInfo(onDataLoad); }; - loadBook = (onDataLoad: () => void = () => {}) => { + loadBook = (onDataLoad: () => void = () => {}): void => { if (this.loadingBook) return; this.loadingBook = true; @@ -181,7 +179,7 @@ export class Coordinator { }); }; - loadLimits = (onDataLoad: () => void = () => {}) => { + loadLimits = (onDataLoad: () => void = () => {}): void => { if (this.loadingLimits) return; this.loadingLimits = true; @@ -208,7 +206,7 @@ export class Coordinator { }); }; - loadInfo = (onDataLoad: () => void = () => {}) => { + loadInfo = (onDataLoad: () => void = () => {}): void => { if (this.loadingInfo) return; this.loadingInfo = true; @@ -227,25 +225,25 @@ export class Coordinator { }); }; - enable = (onEnabled: () => void = () => {}) => { + enable = (onEnabled: () => void = () => {}): void => { this.enabled = true; - this.update(() => { + void this.update(() => { onEnabled(); }); }; - disable = () => { + disable = (): void => { this.enabled = false; this.info = undefined; this.limits = {}; this.book = []; }; - isUpdated = () => { + isUpdated = (): boolean => { return !((this.loadingBook === this.loadingInfo) === this.loadingLimits); }; - getBaseUrl = () => { + getBaseUrl = (): string => { return this.url + this.basePath; }; @@ -265,7 +263,7 @@ export class Coordinator { fecthRobot = async (garage: Garage, index: number): Promise => { const robot = garage?.getRobot(index); - if (!robot?.token) return null; + if (robot?.token == null) return null; const authHeaders = robot.getAuthHeaders(); @@ -313,7 +311,7 @@ export class Coordinator { }; fetchOrder = async (orderId: number, robot: Robot): Promise => { - if (!robot.token) return null; + if (!(robot.token != null)) return null; const authHeaders = robot.getAuthHeaders(); @@ -340,7 +338,7 @@ export class Coordinator { }> => { const robot = garage.getRobot(index); - if (!robot?.token || !robot.encPrivKey) return null; + if (!(robot?.token != null) || !(robot.encPrivKey != null)) return null; const data = await apiClient.post( this.url, @@ -352,7 +350,7 @@ export class Coordinator { ); const newRobot = { ...robot, - earnedRewards: data?.successful_withdrawal ? 0 : robot.earnedRewards, + earnedRewards: data?.successful_withdrawal === true ? 0 : robot.earnedRewards, }; garage.updateRobot(newRobot, index); @@ -362,7 +360,7 @@ export class Coordinator { fetchStealth = async (wantsStealth: boolean, garage: Garage, index: number): Promise => { const robot = garage?.getRobot(index); - if (!robot?.token || !robot.encPrivKey) return null; + if (!(robot?.token != null) || !(robot.encPrivKey != null)) return null; await apiClient.post( this.url, diff --git a/frontend/src/models/Exchange.model.ts b/frontend/src/models/Exchange.model.ts index 731f1046..387d99f1 100644 --- a/frontend/src/models/Exchange.model.ts +++ b/frontend/src/models/Exchange.model.ts @@ -45,7 +45,7 @@ export const updateExchangeInfo = (federation: Federation): ExchangeInfo => { highestVersion = getHigherVer(highestVersion, coordinator.info.version); aggregations.forEach((key: any) => { - info[key] = info[key] + Number(coordinator.info[key]); + info[key] = Number(info[key]) + Number(coordinator.info[key]); }); } return null; diff --git a/frontend/src/models/Federation.model.ts b/frontend/src/models/Federation.model.ts index c983af95..cf05305e 100644 --- a/frontend/src/models/Federation.model.ts +++ b/frontend/src/models/Federation.model.ts @@ -53,7 +53,7 @@ export class Federation { }); }; - onCoordinatorSaved = (shortAlias: string) => { + onCoordinatorSaved = (shortAlias: string): void => { this.book = [...this.book, ...this.getCoordinator(shortAlias).book]; this.loading = false; this.triggerHook('onCoordinatorUpdate'); @@ -64,46 +64,48 @@ export class Federation { }; // Setup - start = (origin: Origin, settings: Settings, hostUrl: string): void => { - const onCoordinatorStarted = (shortAlias: string) => { + start = async (origin: Origin, settings: Settings, hostUrl: string): Promise => { + const onCoordinatorStarted = (shortAlias: string): void => { this.exchange.onlineCoordinators = this.exchange.onlineCoordinators + 1; this.onCoordinatorSaved(shortAlias); }; this.loading = true; - Object.values(this.coordinators).forEach(async (coor) => { + // Object.values(this.coordinators).forEach(async (coor) => { + for (const coor of Object.values(this.coordinators)) { await coor.start(origin, settings, hostUrl, onCoordinatorStarted); - }); + } }; - update = (): void => { + update = async (): Promise => { this.loading = false; - Object.values(this.coordinators).forEach(async (coor) => { + // Object.values(this.coordinators).forEach(async (coor) => { + for (const coor of Object.values(this.coordinators)) { await coor.update(() => { this.onCoordinatorSaved(coor.shortAlias); }); - }); + } }; - updateExchange = () => { + updateExchange = (): void => { this.exchange.info = updateExchangeInfo(this); }; // Fetchs fetchRobot = async (garage: Garage, slot: number): Promise => { Object.values(this.coordinators).forEach((coor) => { - coor.fecthRobot(garage, slot); + void coor.fecthRobot(garage, slot); }); }; fetchOrder = async (currentOrder: CurrentOrder, robot: Robot): Promise => { if (currentOrder.shortAlias !== null) { const coordinator = this.coordinators[currentOrder.shortAlias]; - if (coordinator && currentOrder.id !== null) { - const newOrber = await coordinator.fetchOrder(currentOrder.id, robot); + if (coordinator != null && currentOrder.id !== null) { + const newOrder = await coordinator.fetchOrder(currentOrder.id, robot); return { ...currentOrder, - order: newOrber, + order: newOrder, }; } } @@ -115,12 +117,12 @@ export class Federation { return this.coordinators[shortAlias]; }; - disableCoordinator = (shortAlias: string) => { + disableCoordinator = (shortAlias: string): void => { this.coordinators[shortAlias].disable(); this.triggerHook('onCoordinatorUpdate'); }; - enableCoordinator = (shortAlias: string) => { + enableCoordinator = (shortAlias: string): void => { this.coordinators[shortAlias].enable(() => { this.triggerHook('onCoordinatorUpdate'); }); diff --git a/frontend/src/models/Garage.model.ts b/frontend/src/models/Garage.model.ts index c7701dd6..09f77501 100644 --- a/frontend/src/models/Garage.model.ts +++ b/frontend/src/models/Garage.model.ts @@ -93,7 +93,7 @@ class Garage { index = this.currentSlot, ) => { const robot = this.getSlot(index).robot; - if (robot) { + if (robot != null) { robot.update(attributes); this.triggerHook('onRobotUpdate'); this.save(); diff --git a/frontend/src/models/Robot.model.ts b/frontend/src/models/Robot.model.ts index ae15a119..05e6bbf7 100644 --- a/frontend/src/models/Robot.model.ts +++ b/frontend/src/models/Robot.model.ts @@ -1,5 +1,5 @@ import { sha256 } from 'js-sha256'; -import { hexToBase91, validateTokenEntropy } from '../utils'; +import { hexToBase91 } from '../utils'; interface AuthHeaders { tokenSHA256: string; @@ -14,7 +14,7 @@ class Robot { if (garageRobot != null) { this.token = garageRobot?.token ?? undefined; this.tokenSHA256 = - garageRobot?.tokenSHA256 ?? (this.token ? hexToBase91(sha256(this.token)) : ''); + garageRobot?.tokenSHA256 ?? (this.token != null ? hexToBase91(sha256(this.token)) : ''); this.pubKey = garageRobot?.pubKey ?? undefined; this.encPrivKey = garageRobot?.encPrivKey ?? undefined; } @@ -40,7 +40,7 @@ class Robot { public copiedToken: boolean = false; public avatarLoaded: boolean = false; - update = (attributes: Record) => { + update = (attributes: Record): void => { Object.assign(this, attributes); }; diff --git a/frontend/src/pro/Widgets/Book.tsx b/frontend/src/pro/Widgets/Book.tsx index 0feb7381..ea698fa2 100644 --- a/frontend/src/pro/Widgets/Book.tsx +++ b/frontend/src/pro/Widgets/Book.tsx @@ -44,7 +44,7 @@ const BookWidget = React.forwardRef(function Component( /> ); - }, [book, layout, windowSize, fav]); + }, [layout, windowSize, fav, federation.book]); }); export default BookWidget; diff --git a/frontend/src/pro/Widgets/Depth.tsx b/frontend/src/pro/Widgets/Depth.tsx index df408563..ff1960bc 100644 --- a/frontend/src/pro/Widgets/Depth.tsx +++ b/frontend/src/pro/Widgets/Depth.tsx @@ -40,7 +40,7 @@ const DepthChartWidget = React.forwardRef(function Component( /> ); - }, [fav.currency, book, limits, exchange, layout]); + }, [fav.currency, layout, federation.exchange]); }); export default DepthChartWidget; diff --git a/frontend/src/pro/Widgets/Maker.tsx b/frontend/src/pro/Widgets/Maker.tsx index bdee616a..f4cbabc1 100644 --- a/frontend/src/pro/Widgets/Maker.tsx +++ b/frontend/src/pro/Widgets/Maker.tsx @@ -27,7 +27,7 @@ const MakerWidget = React.forwardRef(function Component( ); - }, [maker, limits, fav]); + }, [maker, fav, federation]); }); export default MakerWidget;