import classNames from 'classnames'; import AutoSizer from 'react-virtualized-auto-sizer'; import type { ReactNode } from 'react'; import { useState } from 'react'; import { DealTicketContainer, MarketInfoContainer, } from '@vegaprotocol/deal-ticket'; import { OrderListContainer } from '@vegaprotocol/orders'; import { TradesContainer } from '@vegaprotocol/trades'; import { PositionsContainer } from '@vegaprotocol/positions'; import { OrderbookContainer } from '@vegaprotocol/market-depth'; import type { Market_market } from './__generated__/Market'; import { addDecimalsFormatNumber, formatLabel, t, } from '@vegaprotocol/react-helpers'; import { AccountsContainer } from '@vegaprotocol/accounts'; import { DepthChartContainer } from '@vegaprotocol/market-depth'; import { CandlesChartContainer } from '@vegaprotocol/candles-chart'; import { SelectMarketDialog } from '@vegaprotocol/market-list'; import { ArrowDown, Tab, Tabs, PriceCellChange, } from '@vegaprotocol/ui-toolkit'; import type { CandleClose } from '@vegaprotocol/types'; import { AuctionTrigger } from '@vegaprotocol/types'; import { MarketTradingMode } from '@vegaprotocol/types'; import { Allotment, LayoutPriority } from 'allotment'; import 'allotment/dist/style.css'; const TradingViews = { Candles: CandlesChartContainer, Depth: DepthChartContainer, Ticket: DealTicketContainer, Info: MarketInfoContainer, Orderbook: OrderbookContainer, Trades: TradesContainer, Positions: PositionsContainer, Orders: OrderListContainer, Collateral: AccountsContainer, }; type TradingView = keyof typeof TradingViews; interface TradeMarketHeaderProps { market: Market_market; className?: string; } export const TradeMarketHeader = ({ market, className, }: TradeMarketHeaderProps) => { const [open, setOpen] = useState(false); const candlesClose: string[] = (market?.candles || []) .map((candle) => candle?.close) .filter((c): c is CandleClose => c !== null); const headerItemClassName = 'whitespace-nowrap flex flex-col'; const itemClassName = 'font-sans font-normal mb-0 text-black-60 dark:text-white-80 text-ui-small'; const itemValueClassName = 'font-sans tracking-tighter text-black dark:text-white text-ui'; const headerClassName = classNames( 'w-full p-8 bg-white dark:bg-black', className ); return (
Change (24h)
Volume {market.data && market.data.indicativeVolume !== '0' ? addDecimalsFormatNumber( market.data.indicativeVolume, market.positionDecimalPlaces ) : '-'}
Trading mode {market.tradingMode === MarketTradingMode.MonitoringAuction && market.data?.trigger && market.data.trigger !== AuctionTrigger.Unspecified ? `${formatLabel( market.tradingMode )} - ${market.data?.trigger.toLowerCase()}` : formatLabel(market.tradingMode)}
); }; interface TradeGridProps { market: Market_market; } export const TradeGrid = ({ market }: TradeGridProps) => { const wrapperClasses = classNames( 'h-full max-h-full', 'flex flex-col', 'bg-black-10 dark:bg-black-70', 'text-ui' ); return ( <>
); }; interface TradeGridChildProps { children: ReactNode; className?: string; } const TradeGridChild = ({ children, className }: TradeGridChildProps) => { const gridChildClasses = classNames('bg-white dark:bg-black', className); return (
{({ width, height }) => (
{children}
)}
); }; interface TradePanelsProps { market: Market_market; } export const TradePanels = ({ market }: TradePanelsProps) => { const [view, setView] = useState('Candles'); const renderView = () => { const Component = TradingViews[view]; if (!Component) { throw new Error(`No component for view: ${view}`); } return ; }; return (
{({ width, height }) => (
{renderView()}
)}
{Object.keys(TradingViews).map((key) => { const isActive = view === key; const className = classNames('py-4', 'px-12', 'capitalize', { 'text-black dark:text-vega-yellow': isActive, 'bg-white dark:bg-black': isActive, 'text-black dark:text-white': !isActive, 'bg-black-10 dark:bg-white-10': !isActive, }); return ( ); })}
); };