import { compileGridData, DealTicketContainer, TradingModeTooltip, } from '@vegaprotocol/deal-ticket'; import { MarketInfoContainer } from '@vegaprotocol/market-info'; import { OrderbookContainer } from '@vegaprotocol/market-depth'; import { OrderListContainer } from '@vegaprotocol/orders'; import { FillsContainer } from '@vegaprotocol/fills'; import { PositionsContainer } from '@vegaprotocol/positions'; import { TradesContainer } from '@vegaprotocol/trades'; import { LayoutPriority } from 'allotment'; import classNames from 'classnames'; import AutoSizer from 'react-virtualized-auto-sizer'; import { useState } from 'react'; import type { ReactNode } from 'react'; import type { Market_market } from './__generated__/Market'; import { DepthChartContainer } from '@vegaprotocol/market-depth'; import { CandlesChartContainer } from '@vegaprotocol/candles-chart'; import { Tab, Tabs, ResizableGrid, ResizableGridPanel, ButtonLink, PriceCellChange, Link, } from '@vegaprotocol/ui-toolkit'; import { addDecimalsFormatNumber, getDateFormat, t, } from '@vegaprotocol/react-helpers'; import { useAssetDetailsDialogStore } from '@vegaprotocol/assets'; import { useEnvironment } from '@vegaprotocol/environment'; import type { CandleClose } from '@vegaprotocol/types'; import { AuctionTrigger, AuctionTriggerMapping, MarketTradingMode, MarketTradingModeMapping, } from '@vegaprotocol/types'; import { Header, HeaderStat } from '../../components/header'; import { AccountsContainer } from '../portfolio/accounts-container'; import { ColumnKind, SelectMarketPopover, } from '../../components/select-market'; import type { OnCellClickHandler } from '../../components/select-market'; const TradingViews = { Candles: CandlesChartContainer, Depth: DepthChartContainer, Ticket: DealTicketContainer, Info: MarketInfoContainer, Orderbook: OrderbookContainer, Trades: TradesContainer, Positions: PositionsContainer, Orders: OrderListContainer, Collateral: AccountsContainer, Fills: FillsContainer, }; type TradingView = keyof typeof TradingViews; type ExpiryLabelProps = { market: Market_market; }; const ExpiryLabel = ({ market }: ExpiryLabelProps) => { let content = null; if (market.marketTimestamps.close === null) { content = t('Not time-based'); } else { const closeDate = new Date(market.marketTimestamps.close); const isExpired = Date.now() - closeDate.valueOf() > 0; const expiryDate = getDateFormat().format(closeDate); content = `${isExpired ? `${t('Expired')} ` : ''} ${expiryDate}`; } return
{content}
; }; type ExpiryTooltipContentProps = { market: Market_market; explorerUrl?: string; }; const ExpiryTooltipContent = ({ market, explorerUrl, }: ExpiryTooltipContentProps) => { if (market.marketTimestamps.close === null) { const oracleId = market.tradableInstrument.instrument.product .oracleSpecForTradingTermination?.id; return ( <>

{t( 'This market expires when triggered by its oracle, not on a set date.' )}

{explorerUrl && oracleId && ( {t('View oracle specification')} )} ); } return null; }; interface TradeMarketHeaderProps { market: Market_market; onSelect: (marketId: string) => void; } export const TradeMarketHeader = ({ market, onSelect, }: TradeMarketHeaderProps) => { const { VEGA_EXPLORER_URL } = useEnvironment(); const { open: openAssetDetailsDialog } = useAssetDetailsDialogStore(); const candlesClose: string[] = (market?.candlesConnection?.edges || []) .map((candle) => candle?.node.close) .filter((c): c is CandleClose => c !== null); const symbol = market.tradableInstrument.instrument.product?.settlementAsset?.symbol; const onCellClick: OnCellClickHandler = (e, kind, value) => { if (value && kind === ColumnKind.Asset) { openAssetDetailsDialog(value, e.target as HTMLElement); } }; return (
} > } >
{market.data && market.data.markPrice !== '0' ? addDecimalsFormatNumber( market.data.markPrice, market.decimalPlaces ) : '-'}
{market.data && market.data.indicativeVolume !== '0' ? addDecimalsFormatNumber( market.data.indicativeVolume, market.positionDecimalPlaces ) : '-'}
} >
{market.tradingMode === MarketTradingMode.TRADING_MODE_MONITORING_AUCTION && market.data?.trigger && market.data.trigger !== AuctionTrigger.AUCTION_TRIGGER_UNSPECIFIED ? `${MarketTradingModeMapping[market.tradingMode]} - ${AuctionTriggerMapping[market.data.trigger]}` : MarketTradingModeMapping[market.tradingMode]}
{symbol ? (
{ openAssetDetailsDialog(symbol, e.target as HTMLElement); }} > {symbol}
) : null}
); }; interface TradeGridProps { market: Market_market; onSelect: (marketId: string) => void; } export const TradeGrid = ({ market, onSelect }: TradeGridProps) => { return (
{ onSelect(id); }} />
); }; interface TradeGridChildProps { children: ReactNode; } const TradeGridChild = ({ children }: TradeGridChildProps) => { return (
{({ width, height }) =>
{children}
}
); }; interface TradePanelsProps { market: Market_market; onSelect: (marketId: string) => void; } export const TradePanels = ({ market, onSelect }: TradePanelsProps) => { const [view, setView] = useState('Candles'); const renderView = () => { const Component = TradingViews[view]; if (!Component) { throw new Error(`No component for view: ${view}`); } return ( { onSelect(id); }} /> ); }; return (
{({ width, height }) => (
{renderView()}
)}
{Object.keys(TradingViews).map((key) => { const isActive = view === key; const className = classNames('p-4 min-w-[100px] capitalize', { 'text-black dark:text-vega-yellow': isActive, 'bg-neutral-200 dark:bg-neutral-800': isActive, }); return ( ); })}
); };