2023-07-24 08:37:18 +00:00
|
|
|
import { Popover, VegaIcon, VegaIconNames } from '@vegaprotocol/ui-toolkit';
|
|
|
|
import { Header, HeaderTitle } from '../header';
|
2023-10-16 18:18:26 +00:00
|
|
|
import { Route, Routes, useParams } from 'react-router-dom';
|
2023-07-24 08:37:18 +00:00
|
|
|
import { MarketSelector } from '../../components/market-selector/market-selector';
|
|
|
|
import { MarketHeaderStats } from '../../client-pages/market/market-header-stats';
|
2023-08-24 09:05:09 +00:00
|
|
|
import { useMarket, useMarketList } from '@vegaprotocol/markets';
|
2023-07-31 16:08:55 +00:00
|
|
|
import { useState } from 'react';
|
2023-09-22 08:39:56 +00:00
|
|
|
import { ProductTypeShortName } from '@vegaprotocol/types';
|
2023-07-24 08:37:18 +00:00
|
|
|
|
|
|
|
export const MarketHeader = () => {
|
|
|
|
const { marketId } = useParams();
|
|
|
|
const { data } = useMarket(marketId);
|
2023-07-31 16:08:55 +00:00
|
|
|
const [open, setOpen] = useState(false);
|
2023-07-24 08:37:18 +00:00
|
|
|
|
2023-08-24 09:05:09 +00:00
|
|
|
// Ensure that markets are kept cached so opening the list
|
|
|
|
// shows all markets instantly
|
|
|
|
useMarketList();
|
|
|
|
|
2023-07-24 08:37:18 +00:00
|
|
|
if (!data) return null;
|
|
|
|
|
|
|
|
return (
|
2023-10-16 18:18:26 +00:00
|
|
|
<Routes>
|
|
|
|
<Route
|
|
|
|
path=":marketId"
|
|
|
|
element={
|
|
|
|
<Header
|
|
|
|
title={
|
|
|
|
<Popover
|
|
|
|
open={open}
|
2023-12-28 12:33:18 +00:00
|
|
|
onOpenChange={setOpen}
|
2023-10-16 18:18:26 +00:00
|
|
|
trigger={
|
|
|
|
<HeaderTitle>
|
|
|
|
<span>
|
|
|
|
{data.tradableInstrument.instrument.code}
|
|
|
|
<span className="ml-1 text-xs uppercase text-muted">
|
|
|
|
{data.tradableInstrument.instrument.product
|
|
|
|
.__typename &&
|
|
|
|
ProductTypeShortName[
|
|
|
|
data.tradableInstrument.instrument.product
|
|
|
|
.__typename
|
|
|
|
]}
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
<VegaIcon name={VegaIconNames.CHEVRON_DOWN} size={14} />
|
|
|
|
</HeaderTitle>
|
|
|
|
}
|
|
|
|
alignOffset={-10}
|
|
|
|
>
|
|
|
|
<MarketSelector
|
|
|
|
currentMarketId={marketId}
|
|
|
|
onSelect={() => setOpen(false)}
|
|
|
|
/>
|
|
|
|
</Popover>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<MarketHeaderStats market={data} />
|
|
|
|
</Header>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Routes>
|
2023-07-24 08:37:18 +00:00
|
|
|
);
|
|
|
|
};
|