import { DealTicketContainer, MarketInfoContainer, } from '@vegaprotocol/deal-ticket'; 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 { AccountsContainer } from '@vegaprotocol/accounts'; import { DepthChartContainer } from '@vegaprotocol/market-depth'; import { CandlesChartContainer } from '@vegaprotocol/candles-chart'; import { Tab, Tabs, ResizableGrid, ResizableGridPanel, ButtonLink, Tooltip, PriceCellChange, Link, } from '@vegaprotocol/ui-toolkit'; import { addDecimalsFormatNumber, getDateFormat, t, } from '@vegaprotocol/react-helpers'; import { SelectMarketPopover } from '@vegaprotocol/market-list'; import { useGlobalStore } from '../../stores'; 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 { TradingModeTooltip } from '../../components/trading-mode-tooltip'; 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) => { if (market.marketTimestamps.close === null) { return <>{t('Not time-based')}>; } const closeDate = new Date(market.marketTimestamps.close); const isExpired = Date.now() - closeDate.valueOf() > 0; const expiryDate = getDateFormat().format(closeDate); return <>{`${isExpired ? `${t('Expired')} ` : ''} ${expiryDate}`}>; }; 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; } export const TradeMarketHeader = ({ market }: TradeMarketHeaderProps) => { const { VEGA_EXPLORER_URL } = useEnvironment(); const { setAssetDetailsDialogOpen, setAssetDetailsDialogSymbol } = useAssetDetailsDialogStore(); const { update } = useGlobalStore((store) => ({ update: store.update, })); const onSelect = (marketId: string) => { if (marketId && marketId !== marketId) { update({ marketId }); } }; const candlesClose: string[] = (market?.candles || []) .map((candle) => candle?.close) .filter((c): c is CandleClose => c !== null); const hasExpiry = market.marketTimestamps.close !== null; const symbol = market.tradableInstrument.instrument.product?.settlementAsset?.symbol; const itemClass = 'min-w-min w-[120px] whitespace-nowrap pb-3 px-4 border-l border-neutral-300 dark:border-neutral-700'; const itemHeading = 'text-neutral-400'; return (