import { useAssetDetailsDialogStore } from '@vegaprotocol/assets'; import { useEnvironment } from '@vegaprotocol/environment'; import { ButtonLink, Link } from '@vegaprotocol/ui-toolkit'; import { MarketProposalNotification } from '@vegaprotocol/governance'; import { getExpiryDate, getMarketExpiryDate, t, } from '@vegaprotocol/react-helpers'; import type { SingleMarketFieldsFragment } from '@vegaprotocol/market-list'; import { ColumnKind, SelectMarketPopover, } from '../../components/select-market'; import type { OnCellClickHandler } from '../../components/select-market'; import { Header, HeaderStat } from '../../components/header'; import { NO_MARKET } from './constants'; import { MarketMarkPrice } from '../../components/market-mark-price'; import { Last24hPriceChange } from '../../components/last-24h-price-change'; import { Last24hVolume } from '../../components/last-24h-volume'; import { MarketState } from '../../components/market-state'; import { HeaderStatMarketTradingMode } from '../../components/market-trading-mode'; import { MarketLiquiditySupplied } from '../../components/liquidity-supplied'; import { MarketState as State } from '@vegaprotocol/types'; interface TradeMarketHeaderProps { market: SingleMarketFieldsFragment | null; onSelect: (marketId: string) => void; } export const TradeMarketHeader = ({ market, onSelect, }: TradeMarketHeaderProps) => { const { VEGA_EXPLORER_URL } = useEnvironment(); const { open: openAssetDetailsDialog } = useAssetDetailsDialogStore(); const asset = market?.tradableInstrument.instrument.product?.settlementAsset; const onCellClick: OnCellClickHandler = (e, kind, value) => { if (value && kind === ColumnKind.Asset) { openAssetDetailsDialog(value, e.target as HTMLElement); } }; return (
} > ) } testId="market-expiry" > {asset ? (
{ openAssetDetailsDialog(asset.id, e.target as HTMLElement); }} > {asset.symbol}
) : null}
); }; type ExpiryLabelProps = { market: SingleMarketFieldsFragment | null; }; const ExpiryLabel = ({ market }: ExpiryLabelProps) => { const content = market && market.tradableInstrument.instrument.metadata.tags ? getExpiryDate( market.tradableInstrument.instrument.metadata.tags, market.marketTimestamps.close, market.state ) : '-'; return
{content}
; }; type ExpiryTooltipContentProps = { market: SingleMarketFieldsFragment; explorerUrl?: string; }; const ExpiryTooltipContent = ({ market, explorerUrl, }: ExpiryTooltipContentProps) => { if (market?.marketTimestamps.close === null) { const oracleId = market.tradableInstrument.instrument.product .dataSourceSpecForTradingTermination?.id; const metadataExpiryDate = getMarketExpiryDate( market.tradableInstrument.instrument.metadata.tags ); const isExpired = metadataExpiryDate && Date.now() - metadataExpiryDate.valueOf() > 0 && (market.state === State.STATE_TRADING_TERMINATED || market.state === State.STATE_SETTLED); return (

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

{metadataExpiryDate && !isExpired && (

{t( 'This timestamp is user curated metadata and does not drive any on-chain functionality.' )}

)} {explorerUrl && oracleId && ( {t('View oracle specification')} )}
); } return null; };