chore(trading): cant view settled market (#4958)
This commit is contained in:
parent
ee73e4d5e2
commit
539abce8af
@ -0,0 +1,5 @@
|
|||||||
|
import MarketPage from '../market';
|
||||||
|
|
||||||
|
export const ClosedMarketPage = () => {
|
||||||
|
return <MarketPage closed />;
|
||||||
|
};
|
1
apps/trading/client-pages/closed-market/index.ts
Normal file
1
apps/trading/client-pages/closed-market/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { ClosedMarketPage as default } from './closed-market';
|
@ -9,9 +9,10 @@ import { useGlobalStore, usePageTitleStore } from '../../stores';
|
|||||||
import { TradeGrid } from './trade-grid';
|
import { TradeGrid } from './trade-grid';
|
||||||
import { TradePanels } from './trade-panels';
|
import { TradePanels } from './trade-panels';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { Links } from '../../lib/links';
|
import { Links, Routes } from '../../lib/links';
|
||||||
import { ViewType, useSidebar } from '../../components/sidebar';
|
import { ViewType, useSidebar } from '../../components/sidebar';
|
||||||
import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id';
|
import { useGetCurrentRouteId } from '../../lib/hooks/use-get-current-route-id';
|
||||||
|
import { MarketState } from '@vegaprotocol/types';
|
||||||
|
|
||||||
const calculatePrice = (markPrice?: string, decimalPlaces?: number) => {
|
const calculatePrice = (markPrice?: string, decimalPlaces?: number) => {
|
||||||
return markPrice && decimalPlaces
|
return markPrice && decimalPlaces
|
||||||
@ -56,7 +57,7 @@ const TitleUpdater = ({
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const MarketPage = () => {
|
export const MarketPage = ({ closed }: { closed?: boolean }) => {
|
||||||
const { marketId } = useParams();
|
const { marketId } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const currentRouteId = useGetCurrentRouteId();
|
const currentRouteId = useGetCurrentRouteId();
|
||||||
@ -70,16 +71,33 @@ export const MarketPage = () => {
|
|||||||
const { data, error, loading } = useMarket(marketId);
|
const { data, error, loading } = useMarket(marketId);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data?.id && data.id !== lastMarketId) {
|
if (
|
||||||
|
data?.state &&
|
||||||
|
[
|
||||||
|
MarketState.STATE_SETTLED,
|
||||||
|
MarketState.STATE_TRADING_TERMINATED,
|
||||||
|
].includes(data.state) &&
|
||||||
|
currentRouteId !== Routes.CLOSED_MARKETS &&
|
||||||
|
marketId
|
||||||
|
) {
|
||||||
|
navigate(Links.CLOSED_MARKETS(marketId));
|
||||||
|
}
|
||||||
|
}, [data?.state, currentRouteId, navigate, marketId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (data?.id && data.id !== lastMarketId && !closed) {
|
||||||
update({ marketId: data.id });
|
update({ marketId: data.id });
|
||||||
}
|
}
|
||||||
}, [update, lastMarketId, data?.id]);
|
}, [update, lastMarketId, data?.id, closed]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (largeScreen && view === undefined) {
|
if (largeScreen && view === undefined) {
|
||||||
setViews({ type: ViewType.Order }, currentRouteId);
|
setViews(
|
||||||
|
{ type: closed ? ViewType.Info : ViewType.Order },
|
||||||
|
currentRouteId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, [setViews, view, currentRouteId, largeScreen]);
|
}, [setViews, view, currentRouteId, largeScreen, closed]);
|
||||||
|
|
||||||
const pinnedAsset = data && getAsset(data);
|
const pinnedAsset = data && getAsset(data);
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ import { SettlementPriceCell } from './settlement-price-cell';
|
|||||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||||
import { MarketCodeCell } from './market-code-cell';
|
import { MarketCodeCell } from './market-code-cell';
|
||||||
import { MarketActionsDropdown } from './market-table-actions';
|
import { MarketActionsDropdown } from './market-table-actions';
|
||||||
|
import type { CellClickedEvent } from 'ag-grid-community';
|
||||||
|
import { useClosedMarketClickHandler } from '../../lib/hooks/use-market-click-handler';
|
||||||
|
|
||||||
type SettlementAsset = Pick<
|
type SettlementAsset = Pick<
|
||||||
Asset,
|
Asset,
|
||||||
@ -125,6 +127,7 @@ const ClosedMarketsDataGrid = ({
|
|||||||
rowData: Row[];
|
rowData: Row[];
|
||||||
error: Error | undefined;
|
error: Error | undefined;
|
||||||
}) => {
|
}) => {
|
||||||
|
const handleOnSelect = useClosedMarketClickHandler();
|
||||||
const openAssetDialog = useAssetDetailsDialogStore((store) => store.open);
|
const openAssetDialog = useAssetDetailsDialogStore((store) => store.open);
|
||||||
|
|
||||||
const colDefs = useMemo(() => {
|
const colDefs = useMemo(() => {
|
||||||
@ -281,6 +284,27 @@ const ClosedMarketsDataGrid = ({
|
|||||||
overlayNoRowsTemplate={error ? error.message : t('No markets')}
|
overlayNoRowsTemplate={error ? error.message : t('No markets')}
|
||||||
components={components}
|
components={components}
|
||||||
rowHeight={45}
|
rowHeight={45}
|
||||||
|
onCellClicked={({ data, column, event }: CellClickedEvent<Row>) => {
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
|
// prevent navigating to the market page if any of the below cells are clicked
|
||||||
|
// event.preventDefault or event.stopPropagation dont seem to apply for aggird
|
||||||
|
const colId = column.getColId();
|
||||||
|
|
||||||
|
if (
|
||||||
|
[
|
||||||
|
'settlementDate',
|
||||||
|
'settlementDataOracleId',
|
||||||
|
'settlementAsset',
|
||||||
|
'market-actions',
|
||||||
|
].includes(colId)
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ts-ignore metaKey exists
|
||||||
|
handleOnSelect(data.id, event ? event.metaKey : false);
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -23,6 +23,10 @@ export const LayoutWithSidebar = () => {
|
|||||||
<div className="col-span-full">
|
<div className="col-span-full">
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="markets/:marketId" element={<MarketHeader />} />
|
<Route path="markets/:marketId" element={<MarketHeader />} />
|
||||||
|
<Route
|
||||||
|
path="markets/all/closed/:marketId"
|
||||||
|
element={<MarketHeader />}
|
||||||
|
/>
|
||||||
<Route path="liquidity/:marketId" element={<LiquidityHeader />} />
|
<Route path="liquidity/:marketId" element={<LiquidityHeader />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
</div>
|
</div>
|
||||||
|
@ -135,6 +135,21 @@ export const Sidebar = () => {
|
|||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path="markets/all/closed/:marketId"
|
||||||
|
element={
|
||||||
|
<>
|
||||||
|
<AssetSidebarButtons />
|
||||||
|
<SidebarDivider />
|
||||||
|
<SidebarButton
|
||||||
|
view={ViewType.Info}
|
||||||
|
icon={VegaIconNames.BREAKDOWN}
|
||||||
|
tooltip={t('Market specification')}
|
||||||
|
routeId={currentRouteId}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
/>
|
||||||
</Routes>
|
</Routes>
|
||||||
</nav>
|
</nav>
|
||||||
<nav className={classNames(navClasses, 'ml-auto lg:mt-auto lg:ml-0')}>
|
<nav className={classNames(navClasses, 'ml-auto lg:mt-auto lg:ml-0')}>
|
||||||
|
@ -20,3 +20,16 @@ export const useMarketLiquidityClickHandler = () => {
|
|||||||
window.open(`/#/liquidity/${selectedId}`, metaKey ? '_blank' : '_self');
|
window.open(`/#/liquidity/${selectedId}`, metaKey ? '_blank' : '_self');
|
||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useClosedMarketClickHandler = (replace = false) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
return (selectedId: string, metaKey?: boolean) => {
|
||||||
|
const link = Links.CLOSED_MARKETS(selectedId);
|
||||||
|
if (metaKey) {
|
||||||
|
window.open(`/#${link}`, '_blank');
|
||||||
|
} else {
|
||||||
|
navigate(link, { replace });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
@ -5,6 +5,7 @@ import trimEnd from 'lodash/trimEnd';
|
|||||||
export const Routes = {
|
export const Routes = {
|
||||||
HOME: '/',
|
HOME: '/',
|
||||||
MARKETS: '/markets/all',
|
MARKETS: '/markets/all',
|
||||||
|
CLOSED_MARKETS: '/markets/all/closed/:marketId',
|
||||||
MARKET: '/markets/:marketId',
|
MARKET: '/markets/:marketId',
|
||||||
LIQUIDITY: '/liquidity/:marketId',
|
LIQUIDITY: '/liquidity/:marketId',
|
||||||
PORTFOLIO: '/portfolio',
|
PORTFOLIO: '/portfolio',
|
||||||
@ -28,6 +29,8 @@ export const Links: ConsoleLinks = {
|
|||||||
MARKET: (marketId: string) =>
|
MARKET: (marketId: string) =>
|
||||||
trimEnd(Routes.MARKET.replace(':marketId', marketId)),
|
trimEnd(Routes.MARKET.replace(':marketId', marketId)),
|
||||||
MARKETS: () => Routes.MARKETS,
|
MARKETS: () => Routes.MARKETS,
|
||||||
|
CLOSED_MARKETS: (marketId: string) =>
|
||||||
|
trimEnd(Routes.CLOSED_MARKETS.replace(':marketId', marketId)),
|
||||||
PORTFOLIO: () => Routes.PORTFOLIO,
|
PORTFOLIO: () => Routes.PORTFOLIO,
|
||||||
LIQUIDITY: (marketId: string) =>
|
LIQUIDITY: (marketId: string) =>
|
||||||
trimEnd(Routes.LIQUIDITY.replace(':marketId', marketId)),
|
trimEnd(Routes.LIQUIDITY.replace(':marketId', marketId)),
|
||||||
|
@ -26,6 +26,7 @@ import { FLAGS } from '@vegaprotocol/environment';
|
|||||||
// These must remain dynamically imported as pennant cannot be compiled by nextjs due to ESM
|
// These must remain dynamically imported as pennant cannot be compiled by nextjs due to ESM
|
||||||
// Using dynamic imports is a workaround for this until pennant is published as ESM
|
// Using dynamic imports is a workaround for this until pennant is published as ESM
|
||||||
const MarketPage = lazy(() => import('../client-pages/market'));
|
const MarketPage = lazy(() => import('../client-pages/market'));
|
||||||
|
const ClosedMarketPage = lazy(() => import('../client-pages/closed-market'));
|
||||||
const Portfolio = lazy(() => import('../client-pages/portfolio'));
|
const Portfolio = lazy(() => import('../client-pages/portfolio'));
|
||||||
|
|
||||||
const NotFound = () => (
|
const NotFound = () => (
|
||||||
@ -101,6 +102,11 @@ export const routerConfig: RouteObject[] = compact([
|
|||||||
element: <MarketPage />,
|
element: <MarketPage />,
|
||||||
id: Routes.MARKET,
|
id: Routes.MARKET,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'all/closed/:marketId',
|
||||||
|
element: <ClosedMarketPage />,
|
||||||
|
id: Routes.CLOSED_MARKETS,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user