2022-12-13 13:31:28 +00:00
|
|
|
import React, { useCallback } from 'react';
|
|
|
|
import { useMarketList } from '@vegaprotocol/market-list';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { t } from '@vegaprotocol/i18n';
|
2022-12-13 13:31:28 +00:00
|
|
|
import { useAssetDetailsDialogStore } from '@vegaprotocol/assets';
|
2023-03-25 00:01:12 +00:00
|
|
|
import { Link as UILink, TinyScroll } from '@vegaprotocol/ui-toolkit';
|
2023-02-09 14:20:31 +00:00
|
|
|
import type { OnCellClickHandler } from '../select-market';
|
|
|
|
import type { MarketMaybeWithDataAndCandles } from '@vegaprotocol/market-list';
|
2022-12-13 13:31:28 +00:00
|
|
|
import {
|
|
|
|
ColumnKind,
|
|
|
|
columns,
|
|
|
|
SelectMarketTableHeader,
|
|
|
|
SelectMarketTableRow,
|
|
|
|
} from '../select-market';
|
|
|
|
import { WelcomeDialogHeader } from './welcome-dialog-header';
|
2023-04-11 09:34:44 +00:00
|
|
|
import { Link } from 'react-router-dom';
|
2022-12-13 13:31:28 +00:00
|
|
|
import { ProposedMarkets } from './proposed-markets';
|
2022-12-22 14:24:20 +00:00
|
|
|
import { Links, Routes } from '../../pages/client-router';
|
2023-04-11 09:34:44 +00:00
|
|
|
import { useMarketClickHandler } from '../../lib/hooks/use-market-click-handler';
|
2022-12-13 13:31:28 +00:00
|
|
|
|
|
|
|
export const SelectMarketLandingTable = ({
|
|
|
|
markets,
|
|
|
|
onClose,
|
|
|
|
}: {
|
2023-02-09 14:20:31 +00:00
|
|
|
markets: MarketMaybeWithDataAndCandles[] | null;
|
2022-12-13 13:31:28 +00:00
|
|
|
onClose: () => void;
|
|
|
|
}) => {
|
2023-04-11 09:34:44 +00:00
|
|
|
const onSelect = useMarketClickHandler();
|
2022-12-13 13:31:28 +00:00
|
|
|
const onSelectMarket = useCallback(
|
2023-04-11 09:34:44 +00:00
|
|
|
(id: string, metaKey?: boolean) => {
|
|
|
|
onSelect(id, metaKey);
|
|
|
|
if (!metaKey) {
|
|
|
|
onClose();
|
|
|
|
}
|
2022-12-13 13:31:28 +00:00
|
|
|
},
|
|
|
|
[onSelect, onClose]
|
|
|
|
);
|
|
|
|
const { open: openAssetDetailsDialog } = useAssetDetailsDialogStore();
|
|
|
|
const onCellClick = useCallback<OnCellClickHandler>(
|
|
|
|
(e, kind, value) => {
|
|
|
|
if (value && kind === ColumnKind.Asset) {
|
|
|
|
openAssetDetailsDialog(value, e.target as HTMLElement);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[openAssetDetailsDialog]
|
|
|
|
);
|
|
|
|
const showProposed = (markets?.length || 0) <= 5;
|
|
|
|
return (
|
|
|
|
<>
|
2023-03-25 00:01:12 +00:00
|
|
|
<TinyScroll
|
|
|
|
className="max-h-[60vh] overflow-x-auto -mr-4 pr-4"
|
2022-12-13 13:31:28 +00:00
|
|
|
data-testid="select-market-list"
|
|
|
|
>
|
2023-01-16 17:36:06 +00:00
|
|
|
<p className="text-neutral-500 dark:text-neutral-400 mb-4">
|
2022-12-13 13:31:28 +00:00
|
|
|
{t('Select a market to get started...')}
|
|
|
|
</p>
|
|
|
|
<table className="text-sm relative h-full min-w-full whitespace-nowrap">
|
|
|
|
<thead className="sticky top-0 z-10 bg-white dark:bg-black">
|
|
|
|
<SelectMarketTableHeader />
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{markets?.map((market, i) => (
|
|
|
|
<SelectMarketTableRow
|
|
|
|
marketId={market.id}
|
|
|
|
key={i}
|
|
|
|
detailed={false}
|
|
|
|
onSelect={onSelectMarket}
|
2023-04-11 09:34:44 +00:00
|
|
|
columns={columns(market, onSelectMarket, onCellClick)}
|
2022-12-13 13:31:28 +00:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
2023-03-25 00:01:12 +00:00
|
|
|
</TinyScroll>
|
2022-12-13 13:31:28 +00:00
|
|
|
<div className="mt-4 text-md">
|
|
|
|
<Link
|
2022-12-22 14:24:20 +00:00
|
|
|
to={Links[Routes.MARKETS]()}
|
2022-12-13 13:31:28 +00:00
|
|
|
data-testid="view-market-list-link"
|
|
|
|
onClick={() => onClose()}
|
|
|
|
>
|
2023-01-26 13:46:44 +00:00
|
|
|
<UILink className="text-sm underline">
|
2023-01-16 17:36:06 +00:00
|
|
|
{'Or view full market list'}
|
|
|
|
</UILink>
|
2022-12-13 13:31:28 +00:00
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
{showProposed && <ProposedMarkets />}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface LandingDialogContainerProps {
|
|
|
|
onClose: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const WelcomeLandingDialog = ({
|
|
|
|
onClose,
|
|
|
|
}: LandingDialogContainerProps) => {
|
|
|
|
const { data, loading, error } = useMarketList();
|
|
|
|
if (error) {
|
|
|
|
return (
|
|
|
|
<div className="flex justify-center items-center">
|
|
|
|
<p className="my-8">{t('Failed to load markets')}</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loading) {
|
|
|
|
return (
|
|
|
|
<div className="flex justify-center items-center">
|
|
|
|
<p className="my-8">{t('Loading...')}</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WelcomeDialogHeader />
|
|
|
|
<SelectMarketLandingTable markets={data} onClose={onClose} />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|