2023-01-16 17:51:30 +00:00
|
|
|
import type { RefObject } from 'react';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { t } from '@vegaprotocol/i18n';
|
2023-01-16 17:51:30 +00:00
|
|
|
import { TradingModeTooltip } from '@vegaprotocol/deal-ticket';
|
|
|
|
import { useInView } from 'react-intersection-observer';
|
2022-12-08 21:13:30 +00:00
|
|
|
import * as Schema from '@vegaprotocol/types';
|
2022-10-11 12:30:07 +00:00
|
|
|
import { HeaderStat } from '../header';
|
2022-11-30 11:02:59 +00:00
|
|
|
import { Tooltip } from '@vegaprotocol/ui-toolkit';
|
2023-02-09 14:20:31 +00:00
|
|
|
import { useStaticMarketData } from '@vegaprotocol/market-list';
|
2022-10-11 12:30:07 +00:00
|
|
|
|
2023-01-16 17:51:30 +00:00
|
|
|
const getTradingModeLabel = (
|
2023-02-09 14:20:31 +00:00
|
|
|
marketTradingMode?: Schema.MarketTradingMode,
|
2023-01-16 17:51:30 +00:00
|
|
|
trigger?: Schema.AuctionTrigger
|
|
|
|
) => {
|
|
|
|
return (
|
2023-02-09 14:20:31 +00:00
|
|
|
(marketTradingMode ===
|
|
|
|
Schema.MarketTradingMode.TRADING_MODE_MONITORING_AUCTION &&
|
2023-01-16 17:51:30 +00:00
|
|
|
trigger &&
|
|
|
|
trigger !== Schema.AuctionTrigger.AUCTION_TRIGGER_UNSPECIFIED
|
2023-02-09 14:20:31 +00:00
|
|
|
? `${Schema.MarketTradingModeMapping[marketTradingMode]} - ${Schema.AuctionTriggerMapping[trigger]}`
|
2023-01-16 17:51:30 +00:00
|
|
|
: Schema.MarketTradingModeMapping[
|
2023-02-09 14:20:31 +00:00
|
|
|
marketTradingMode as Schema.MarketTradingMode
|
2023-01-16 17:51:30 +00:00
|
|
|
]) || '-'
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface HeaderStatMarketTradingModeProps {
|
2022-11-18 17:08:48 +00:00
|
|
|
marketId?: string;
|
2023-03-31 13:23:44 +00:00
|
|
|
onSelect?: (marketId: string, metaKey?: boolean) => void;
|
2023-01-16 17:51:30 +00:00
|
|
|
initialTradingMode?: Schema.MarketTradingMode;
|
2022-12-08 21:13:30 +00:00
|
|
|
initialTrigger?: Schema.AuctionTrigger;
|
2022-10-11 12:30:07 +00:00
|
|
|
}
|
|
|
|
|
2023-01-16 17:51:30 +00:00
|
|
|
export const HeaderStatMarketTradingMode = ({
|
2022-11-30 11:02:59 +00:00
|
|
|
marketId,
|
|
|
|
onSelect,
|
2023-01-16 17:51:30 +00:00
|
|
|
initialTradingMode,
|
2022-11-30 11:02:59 +00:00
|
|
|
initialTrigger,
|
2023-01-16 17:51:30 +00:00
|
|
|
}: HeaderStatMarketTradingModeProps) => {
|
2023-02-09 14:20:31 +00:00
|
|
|
const { data } = useStaticMarketData(marketId);
|
|
|
|
const marketTradingMode = data?.marketTradingMode ?? initialTradingMode;
|
2023-01-16 17:51:30 +00:00
|
|
|
const trigger = data?.trigger ?? initialTrigger;
|
2022-10-11 12:30:07 +00:00
|
|
|
|
2023-01-16 17:51:30 +00:00
|
|
|
return (
|
2022-10-11 12:30:07 +00:00
|
|
|
<HeaderStat
|
|
|
|
heading={t('Trading mode')}
|
|
|
|
description={
|
2023-01-16 17:51:30 +00:00
|
|
|
<TradingModeTooltip marketId={marketId} onSelect={onSelect} />
|
2022-10-11 12:30:07 +00:00
|
|
|
}
|
2022-10-14 08:15:34 +00:00
|
|
|
testId="market-trading-mode"
|
2022-10-11 12:30:07 +00:00
|
|
|
>
|
2023-02-09 14:20:31 +00:00
|
|
|
<div>{getTradingModeLabel(marketTradingMode, trigger)}</div>
|
2022-10-11 12:30:07 +00:00
|
|
|
</HeaderStat>
|
2023-01-16 17:51:30 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const MarketTradingMode = ({
|
|
|
|
marketId,
|
|
|
|
initialTradingMode,
|
|
|
|
initialTrigger,
|
|
|
|
inViewRoot,
|
|
|
|
}: Omit<HeaderStatMarketTradingModeProps, 'onUpdate'> & {
|
|
|
|
inViewRoot?: RefObject<Element>;
|
|
|
|
}) => {
|
|
|
|
const [ref, inView] = useInView({ root: inViewRoot?.current });
|
2023-02-09 14:20:31 +00:00
|
|
|
const { data } = useStaticMarketData(marketId, !inView);
|
2023-01-16 17:51:30 +00:00
|
|
|
|
|
|
|
return (
|
2022-11-30 11:02:59 +00:00
|
|
|
<Tooltip
|
2023-03-31 13:23:44 +00:00
|
|
|
description={
|
|
|
|
<TradingModeTooltip marketId={marketId} skip={!inView} skipGrid />
|
|
|
|
}
|
2022-11-30 11:02:59 +00:00
|
|
|
>
|
2023-01-16 17:51:30 +00:00
|
|
|
<span ref={ref}>
|
|
|
|
{getTradingModeLabel(
|
|
|
|
data?.marketTradingMode ?? initialTradingMode,
|
|
|
|
data?.trigger ?? initialTrigger
|
|
|
|
)}
|
|
|
|
</span>
|
2022-11-30 11:02:59 +00:00
|
|
|
</Tooltip>
|
2022-10-11 12:30:07 +00:00
|
|
|
);
|
|
|
|
};
|