diff --git a/src/abacus-ts/ontology.ts b/src/abacus-ts/ontology.ts index ec075ec17..87ca3c23c 100644 --- a/src/abacus-ts/ontology.ts +++ b/src/abacus-ts/ontology.ts @@ -26,6 +26,7 @@ import { selectLatestIndexerHeight, selectLatestValidatorHeight, } from './selectors/apiStatus'; +import { selectAllAssetsInfo, selectAllAssetsInfoLoading } from './selectors/assets'; import { selectRawIndexerHeightDataLoading, selectRawValidatorHeightDataLoading, @@ -77,6 +78,7 @@ export const BonsaiCore = { data: selectAllMarketSummaries, loading: selectAllMarketSummariesLoading, }, + assets: { data: selectAllAssetsInfo, loading: selectAllAssetsInfoLoading }, }, network: { indexerHeight: { diff --git a/src/lib/marketsHelpers.ts b/src/lib/marketsHelpers.ts index 0bf13f279..67dd2d1d4 100644 --- a/src/lib/marketsHelpers.ts +++ b/src/lib/marketsHelpers.ts @@ -55,7 +55,7 @@ export function getMarketDataFromPerpetualMarketSummary( assetId, displayId, clobPairId, - effectiveInitialMarginFraction: effectiveInitialMarginFraction?.toNumber(), + effectiveInitialMarginFraction, logo, initialMarginFraction: MustBigNumber(initialMarginFraction).toNumber(), isNew, diff --git a/src/views/tables/LiveTrades.tsx b/src/views/tables/LiveTrades.tsx index 9ad61835b..fce521740 100644 --- a/src/views/tables/LiveTrades.tsx +++ b/src/views/tables/LiveTrades.tsx @@ -1,12 +1,14 @@ import { useMemo } from 'react'; +import { BonsaiHelpers, BonsaiHooks } from '@/abacus-ts/ontology'; +import { LiveTrade } from '@/abacus-ts/types/summaryTypes'; import { OrderSide } from '@dydxprotocol/v4-client-js'; -import { shallowEqual } from 'react-redux'; import styled, { css, keyframes } from 'styled-components'; -import { MarketTrade } from '@/constants/abacus'; import { STRING_KEYS } from '@/constants/localization'; import { TOKEN_DECIMALS } from '@/constants/numbers'; +import { EMPTY_ARR } from '@/constants/objects'; +import { IndexerOrderSide } from '@/types/indexer/indexerApiGen'; import { useBreakpoints } from '@/hooks/useBreakpoints'; import { useLocaleSeparators } from '@/hooks/useLocaleSeparators'; @@ -18,14 +20,12 @@ import { LoadingSpace } from '@/components/Loading/LoadingSpinner'; import { Output, OutputType } from '@/components/Output'; import { useAppSelector } from '@/state/appTypes'; -import { getCurrentMarketAssetData } from '@/state/assetsSelectors'; import { getSelectedLocale } from '@/state/localizationSelectors'; -import { getCurrentMarketConfig, getCurrentMarketLiveTrades } from '@/state/perpetualsSelectors'; import { getConsistentAssetSizeString } from '@/lib/consistentAssetSize'; import { getSimpleStyledOutputType } from '@/lib/genericFunctionalComponentUtils'; import { isTruthy } from '@/lib/isTruthy'; -import { getSelectedOrderSide } from '@/lib/tradeData'; +import { MaybeBigNumber, MustBigNumber } from '@/lib/numbers'; import { OrderbookTradesOutput, OrderbookTradesTable } from './OrderbookTradesTable'; @@ -39,7 +39,7 @@ type StyleProps = { // Current fix for styled-component not preserving generic row type RowData = { - key: number; + key: string; createdAtMilliseconds: number; price: number; side: OrderSide; @@ -49,23 +49,32 @@ type RowData = { export const LiveTrades = ({ className, histogramSide = 'left' }: StyleProps) => { const stringGetter = useStringGetter(); const { isTablet } = useBreakpoints(); - const currentMarketAssetData = useAppSelector(getCurrentMarketAssetData, shallowEqual); - const currentMarketConfig = useAppSelector(getCurrentMarketConfig, shallowEqual); - const currentMarketLiveTrades = useAppSelector(getCurrentMarketLiveTrades, shallowEqual); + const currentMarketConfig = useAppSelector(BonsaiHelpers.currentMarket.stableMarketInfo); + const currentMarketLiveTrades = + BonsaiHooks.useCurrentMarketLiveTrades().data?.trades ?? EMPTY_ARR; - const { displayableAssetId } = currentMarketAssetData ?? {}; - const { stepSizeDecimals, tickSizeDecimals, stepSize } = currentMarketConfig ?? {}; + const { + stepSizeDecimals, + tickSizeDecimals, + stepSize, + displayableAsset: displayableAssetId, + } = currentMarketConfig ?? {}; const { decimal: decimalSeparator, group: groupSeparator } = useLocaleSeparators(); const selectedLocale = useAppSelector(getSelectedLocale); - const rows = currentMarketLiveTrades.map( - ({ createdAtMilliseconds, price, size, side }: MarketTrade, idx) => ({ - key: idx, - createdAtMilliseconds, - price, - side: getSelectedOrderSide(side), - size, - }) + const rows = useMemo( + () => + currentMarketLiveTrades.map( + ({ createdAt, price, size, side, id }: LiveTrade): RowData => ({ + key: id, + createdAtMilliseconds: new Date(createdAt).getTime(), + price: MustBigNumber(price).toNumber(), + // todo use same helper as the horizontal panel files + side: side === IndexerOrderSide.BUY ? OrderSide.BUY : OrderSide.SELL, + size: MustBigNumber(size).toNumber(), + }) + ), + [currentMarketLiveTrades] ); const columns = useMemo(() => { @@ -109,7 +118,7 @@ export const LiveTrades = ({ className, histogramSide = 'left' }: StyleProps) => decimalSeparator, groupSeparator, selectedLocale, - stepSize: stepSize ?? 10 ** (-1 * TOKEN_DECIMALS), + stepSize: MaybeBigNumber(stepSize)?.toNumber() ?? 10 ** (-1 * TOKEN_DECIMALS), stepSizeDecimals: stepSizeDecimals ?? TOKEN_DECIMALS, })} tw="text-[color:--accent-color] tablet:text-color-text-1"