diff --git a/src/components/Orderbook.tsx b/src/components/Orderbook.tsx index 71c70c0e..e2c2f8f8 100644 --- a/src/components/Orderbook.tsx +++ b/src/components/Orderbook.tsx @@ -1,4 +1,4 @@ -import { ReactElement, ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react' +import { ReactElement, useCallback, useEffect, useMemo, useState } from 'react' import { Table, Header, HeaderRow, HeaderCell, Body, Row, Cell } from '@table-library/react-table-library/table' import { usePagination } from '@table-library/react-table-library/pagination' import { useSort, HeaderCellSort, SortToggleType } from '@table-library/react-table-library/sort' @@ -16,6 +16,7 @@ import TablePagination from './TablePagination' import { factorToPercentage, isAbsoluteOffer, isRelativeOffer } from '../utils' import { isDevMode } from '../constants/debugFeatures' import styles from './Orderbook.module.css' +import ToggleSwitch from './ToggleSwitch' const TABLE_THEME = { Table: ` @@ -352,13 +353,13 @@ export function Orderbook({ entries, refresh, nickname }: OrderbookProps) { [tableData], ) + const ownOffers = useMemo(() => { + return nickname ? entries.filter((it) => it.counterparty === nickname) : [] + }, [nickname, entries]) + useEffect(() => { - if (!nickname || !isHighlightOwnOffers) { - setHighlightedOrders([]) - } else { - setHighlightedOrders(entries.filter((it) => it.counterparty === nickname)) - } - }, [entries, nickname, isHighlightOwnOffers]) + setHighlightedOrders(isHighlightOwnOffers ? ownOffers : []) + }, [ownOffers, isHighlightOwnOffers]) return (