import type { PinnedAsset } from '@vegaprotocol/accounts'; import type { Market } from '@vegaprotocol/markets'; import { OracleBanner } from '@vegaprotocol/markets'; import { useMarketClickHandler, useMarketLiquidityClickHandler, } from '../../lib/hooks/use-market-click-handler'; import type { TradingView } from './trade-views'; import { TradingViews } from './trade-views'; import { memo, useState } from 'react'; import { Icon, Splash, VegaIcon, VegaIconNames, } from '@vegaprotocol/ui-toolkit'; import { NO_MARKET } from './constants'; import AutoSizer from 'react-virtualized-auto-sizer'; import classNames from 'classnames'; import { HeaderStats } from './header-stats'; import * as DialogPrimitives from '@radix-ui/react-dialog'; import { HeaderTitle } from '../../components/header'; import { MarketSelector } from './market-selector'; interface TradePanelsProps { market: Market | null; onSelect: (marketId: string, metaKey?: boolean) => void; onMarketClick?: (marketId: string) => void; onOrderTypeClick?: (marketId: string) => void; onClickCollateral: () => void; pinnedAsset?: PinnedAsset; } export const TradePanels = ({ market, onSelect, onClickCollateral, pinnedAsset, }: TradePanelsProps) => { const [drawerOpen, setDrawerOpen] = useState(false); const onMarketClick = useMarketClickHandler(true); const onOrderTypeClick = useMarketLiquidityClickHandler(true); const [view, setView] = useState('candles'); const renderView = () => { const Component = memo<{ marketId: string; onSelect: (marketId: string, metaKey?: boolean) => void; onMarketClick?: (marketId: string) => void; onOrderTypeClick?: (marketId: string) => void; onClickCollateral: () => void; pinnedAsset?: PinnedAsset; }>(TradingViews[view].component); if (!Component) { throw new Error(`No component for view: ${view}`); } if (!market) return {NO_MARKET}; return ( ); }; 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 ( ); })}
{drawerOpen && ( setDrawerOpen(false)} /> )}
); };