import type { RefObject } from 'react'; import { TradingModeTooltip } from '@vegaprotocol/deal-ticket'; import { useInView } from 'react-intersection-observer'; import * as Schema from '@vegaprotocol/types'; import { HeaderStat } from '../header'; import { Tooltip } from '@vegaprotocol/ui-toolkit'; import { useStaticMarketData } from '@vegaprotocol/markets'; import { useT } from '../../lib/use-t'; const getTradingModeLabel = ( marketTradingMode?: Schema.MarketTradingMode, trigger?: Schema.AuctionTrigger ) => { return ( (marketTradingMode === Schema.MarketTradingMode.TRADING_MODE_MONITORING_AUCTION && trigger && trigger !== Schema.AuctionTrigger.AUCTION_TRIGGER_UNSPECIFIED ? `${Schema.MarketTradingModeMapping[marketTradingMode]} - ${Schema.AuctionTriggerMapping[trigger]}` : Schema.MarketTradingModeMapping[ marketTradingMode as Schema.MarketTradingMode ]) || '-' ); }; interface HeaderStatMarketTradingModeProps { marketId?: string; onSelect?: (marketId: string, metaKey?: boolean) => void; } export const HeaderStatMarketTradingMode = ({ marketId, onSelect, }: HeaderStatMarketTradingModeProps) => { const t = useT(); const { data } = useStaticMarketData(marketId); const { marketTradingMode, trigger } = data || {}; return ( } testId="market-trading-mode" >
{getTradingModeLabel(marketTradingMode, trigger)}
); }; export const MarketTradingMode = ({ marketId, inViewRoot, }: Omit & { inViewRoot?: RefObject; }) => { const [ref, inView] = useInView({ root: inViewRoot?.current }); const { data } = useStaticMarketData(marketId, !inView); return ( } > {getTradingModeLabel(data?.marketTradingMode, data?.trigger)} ); };