import compact from 'lodash/compact'; import { isAfter } from 'date-fns'; import type { VegaICellRendererParams, VegaValueFormatterParams, } from '@vegaprotocol/datagrid'; import { AgGridLazy as AgGrid, COL_DEFS, MarketNameCell, } from '@vegaprotocol/datagrid'; import { useMemo } from 'react'; import { t } from '@vegaprotocol/i18n'; import { MarketState, MarketStateMapping } from '@vegaprotocol/types'; import { addDecimalsFormatNumber, getMarketExpiryDate, } from '@vegaprotocol/utils'; import type { DataSourceFilterFragment, MarketMaybeWithData, } from '@vegaprotocol/markets'; import { MarketActionsDropdown, closedMarketsWithDataProvider, } from '@vegaprotocol/markets'; import { useAssetDetailsDialogStore } from '@vegaprotocol/assets'; import type { ColDef } from 'ag-grid-community'; import { FLAGS } from '@vegaprotocol/environment'; import { SettlementDateCell } from './settlement-date-cell'; import { SettlementPriceCell } from './settlement-price-cell'; import { useDataProvider } from '@vegaprotocol/data-provider'; import { SuccessorMarketRenderer } from './successor-market-cell'; type SettlementAsset = MarketMaybeWithData['tradableInstrument']['instrument']['product']['settlementAsset']; interface Row { id: string; code: string; name: string; decimalPlaces: number; state: MarketState; metadata: string[]; closeTimestamp: string | null; bestBidPrice: string | undefined; bestOfferPrice: string | undefined; markPrice: string | undefined; settlementDataOracleId: string; settlementDataSpecBinding: string; setlementDataSourceFilter: DataSourceFilterFragment | undefined; tradingTerminationOracleId: string; settlementAsset: SettlementAsset; productType: string; } export const Closed = () => { const { data: marketData, error } = useDataProvider({ dataProvider: closedMarketsWithDataProvider, variables: undefined, }); const rowData = compact(marketData).map((market) => { const instrument = market.tradableInstrument.instrument; const spec = instrument.product.dataSourceSpecForSettlementData.data.sourceType .__typename === 'DataSourceDefinitionExternal' ? instrument.product.dataSourceSpecForSettlementData.data.sourceType .sourceType : undefined; const filters = spec?.filters || []; const settlementDataSpecBinding = instrument.product.dataSourceSpecBinding.settlementDataProperty; const filter = filters?.find((filter) => { return filter.key.name === settlementDataSpecBinding; }); const row: Row = { id: market.id, code: instrument.code, name: instrument.name, decimalPlaces: market.decimalPlaces, state: market.state, metadata: instrument.metadata.tags ?? [], closeTimestamp: market.marketTimestamps.close, bestBidPrice: market.data?.bestBidPrice, bestOfferPrice: market.data?.bestOfferPrice, markPrice: market.data?.markPrice, settlementDataOracleId: instrument.product.dataSourceSpecForSettlementData.id, settlementDataSpecBinding, setlementDataSourceFilter: filter, tradingTerminationOracleId: instrument.product.dataSourceSpecForTradingTermination.id, settlementAsset: instrument.product.settlementAsset, productType: instrument.product.__typename || '', }; return row; }); return (