2023-07-24 08:37:18 +00:00
|
|
|
import { memo } from 'react';
|
2023-05-16 16:57:36 +00:00
|
|
|
import type { ReactNode } from 'react';
|
2022-08-31 04:35:46 +00:00
|
|
|
import { LayoutPriority } from 'allotment';
|
feat: market list mega dropdown (rich popover) (#889)
* feat: use MarketList query only
* fix: remove Market.ts from index
* feat: 30 refactor dialog, market list, change query
* feat: #30 add indicativeVolume, total fees, tooltip, large dialog, tooltip accepts html description
* fix: #30 total fees display in tooltip
* fix: #30 toggle title on dialog open
* fix: #30 fix order, price, high, low utils
* fix: #30 fix test for market utils
* feat: #30 add popover with markets to select
* feat: #30 storybook popover
* feat: #30 remove border on trigger and add some other classes
* fix: #30 fix format check with format:write
* feat: #30 add tooltip on taker fee
* feat: #30 add tooltip on taker fee
* fix: #30 format on select market list
* fix: #30 remove unknown cast in test mock data
* fix: #30 show markets where you have open positions
* fix: #30 double check if open positions
* fix: #30 dialog has only small/large sizes
* feat: #30 add border on trigger and change padding and no wrap
* fix: #30 if fees or factors are not found
* fix: #30 remove markets.cy tests as markets page is now gone
* fix #30 remove view full market list test
* fix: #30 add rotating arrow on market title
* fix: #30 add ease-in-out on popover
* fix: #30 add ease-in-out on popover
* fix: #30 align select a market table
* fix: #30 select a market title
* fix: #30 select a market title
* fix: #30 fix any validateDOMnesting issues
* fix: #30 show loading market data
* fix: #30 add list of header columns
* fix: #30 add list of header columns
* fix: #30 small refactoring after review
* fix: #30 update bold undreline class names
* fix: #30 add large-mobile size
* feat: #30 refactor select markets tables to render array of columns
* fix: #30 remove size from select market dialog
* fix: #30 add extra file for columns
* fix: #30 update formtting
* fix: #30 make sure popup closes on same market navigation
* fix: rename market-utils, add calcCandle methods, store market id on select
* fix: useMemo ondata and marketPositionData + orderbook stories fix
* feat: #30 add open volume positions
* fix: add market summary back
* fix: update formatting
* fix: use currentcolor on arrow
* fix: create all markets page
* fix: add overflow-y auto
* fix: enlarge select market to get started dialog
* fix: revert markets container
* fix: use query to fix flickering on position markets
* fix: edit unordered list in tooltips
* fix: fix tooltip table
* fix: fix home.cy.ts
* chore: skip /markets tests
2022-08-11 11:56:35 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
2023-05-16 16:57:36 +00:00
|
|
|
import type { PinnedAsset } from '@vegaprotocol/accounts';
|
2023-02-28 18:56:29 +00:00
|
|
|
import { t } from '@vegaprotocol/i18n';
|
2023-05-18 11:22:54 +00:00
|
|
|
import { OracleBanner } from '@vegaprotocol/markets';
|
|
|
|
import type { Market } from '@vegaprotocol/markets';
|
2023-05-16 16:57:36 +00:00
|
|
|
import { Filter } from '@vegaprotocol/orders';
|
2023-07-24 08:37:18 +00:00
|
|
|
import { Tab, LocalStoragePersistTabs as Tabs } from '@vegaprotocol/ui-toolkit';
|
2023-04-21 15:16:04 +00:00
|
|
|
import {
|
|
|
|
ResizableGrid,
|
|
|
|
ResizableGridPanel,
|
2023-07-04 15:47:04 +00:00
|
|
|
usePaneLayout,
|
2023-04-21 15:16:04 +00:00
|
|
|
} from '../../components/resizable-grid';
|
2023-05-16 16:57:36 +00:00
|
|
|
import { TradingViews } from './trade-views';
|
2023-07-27 14:54:00 +00:00
|
|
|
import {
|
|
|
|
MarketSuccessorBanner,
|
|
|
|
MarketSuccessorProposalBanner,
|
|
|
|
} from '../../components/market-banner';
|
2023-07-25 09:12:53 +00:00
|
|
|
import { FLAGS } from '@vegaprotocol/environment';
|
|
|
|
|
2022-06-20 23:52:25 +00:00
|
|
|
interface TradeGridProps {
|
2023-02-09 14:20:31 +00:00
|
|
|
market: Market | null;
|
2023-02-17 13:32:20 +00:00
|
|
|
pinnedAsset?: PinnedAsset;
|
2022-06-20 23:52:25 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 09:50:43 +00:00
|
|
|
const MainGrid = memo(
|
|
|
|
({
|
|
|
|
marketId,
|
|
|
|
pinnedAsset,
|
|
|
|
}: {
|
|
|
|
marketId: string;
|
|
|
|
pinnedAsset?: PinnedAsset;
|
|
|
|
}) => {
|
2023-05-22 14:09:37 +00:00
|
|
|
const [sizes, handleOnLayoutChange] = usePaneLayout({ id: 'top' });
|
2023-05-03 08:44:45 +00:00
|
|
|
const [sizesMiddle, handleOnMiddleLayoutChange] = usePaneLayout({
|
2023-05-22 14:09:37 +00:00
|
|
|
id: 'middle-1',
|
2023-05-03 08:44:45 +00:00
|
|
|
});
|
|
|
|
|
2023-03-17 09:50:43 +00:00
|
|
|
return (
|
2023-05-03 08:44:45 +00:00
|
|
|
<ResizableGrid vertical onChange={handleOnLayoutChange}>
|
2023-08-09 10:04:32 +00:00
|
|
|
<ResizableGridPanel
|
|
|
|
preferredSize={sizes[0]}
|
|
|
|
priority={LayoutPriority.High}
|
|
|
|
minSize={200}
|
|
|
|
>
|
|
|
|
<ResizableGrid onChange={handleOnMiddleLayoutChange}>
|
2023-03-17 09:50:43 +00:00
|
|
|
<ResizableGridPanel
|
2023-05-22 15:55:02 +00:00
|
|
|
priority={LayoutPriority.High}
|
2023-05-22 13:40:42 +00:00
|
|
|
minSize={200}
|
2023-08-09 10:04:32 +00:00
|
|
|
preferredSize={sizesMiddle[0] || '75%'}
|
2023-05-22 13:40:42 +00:00
|
|
|
>
|
|
|
|
<TradeGridChild>
|
|
|
|
<Tabs storageKey="console-trade-grid-main-left">
|
2023-08-02 14:29:41 +00:00
|
|
|
<Tab
|
|
|
|
id="chart"
|
|
|
|
name={t('Chart')}
|
|
|
|
menu={<TradingViews.candles.menu />}
|
|
|
|
>
|
2023-05-22 13:40:42 +00:00
|
|
|
<TradingViews.candles.component marketId={marketId} />
|
|
|
|
</Tab>
|
|
|
|
<Tab id="depth" name={t('Depth')}>
|
|
|
|
<TradingViews.depth.component marketId={marketId} />
|
|
|
|
</Tab>
|
|
|
|
<Tab id="liquidity" name={t('Liquidity')}>
|
|
|
|
<TradingViews.liquidity.component marketId={marketId} />
|
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
</TradeGridChild>
|
|
|
|
</ResizableGridPanel>
|
|
|
|
<ResizableGridPanel
|
2023-03-17 09:50:43 +00:00
|
|
|
minSize={200}
|
2023-08-09 10:04:32 +00:00
|
|
|
preferredSize={sizesMiddle[1] || 300}
|
2023-03-17 09:50:43 +00:00
|
|
|
>
|
|
|
|
<TradeGridChild>
|
2023-03-22 23:34:58 +00:00
|
|
|
<Tabs storageKey="console-trade-grid-main-right">
|
2023-03-17 09:50:43 +00:00
|
|
|
<Tab id="orderbook" name={t('Orderbook')}>
|
2023-05-04 10:09:55 +00:00
|
|
|
<TradingViews.orderbook.component marketId={marketId} />
|
2023-03-17 09:50:43 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab id="trades" name={t('Trades')}>
|
2023-05-04 10:09:55 +00:00
|
|
|
<TradingViews.trades.component marketId={marketId} />
|
2023-03-17 09:50:43 +00:00
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
</TradeGridChild>
|
|
|
|
</ResizableGridPanel>
|
|
|
|
</ResizableGrid>
|
|
|
|
</ResizableGridPanel>
|
|
|
|
<ResizableGridPanel
|
2023-05-03 08:44:45 +00:00
|
|
|
preferredSize={sizes[1] || '25%'}
|
2023-03-17 09:50:43 +00:00
|
|
|
minSize={50}
|
2023-08-09 10:04:32 +00:00
|
|
|
priority={LayoutPriority.Low}
|
2023-03-17 09:50:43 +00:00
|
|
|
>
|
2023-07-24 08:37:18 +00:00
|
|
|
<TradeGridChild>
|
|
|
|
<Tabs storageKey="console-trade-grid-bottom">
|
|
|
|
<Tab id="positions" name={t('Positions')}>
|
2023-08-10 15:02:46 +00:00
|
|
|
<TradingViews.positions.component />
|
2023-07-24 08:37:18 +00:00
|
|
|
</Tab>
|
2023-08-10 15:02:46 +00:00
|
|
|
<Tab
|
|
|
|
id="open-orders"
|
|
|
|
name={t('Open')}
|
|
|
|
menu={<TradingViews.activeOrders.menu marketId={marketId} />}
|
|
|
|
>
|
|
|
|
<TradingViews.orders.component filter={Filter.Open} />
|
2023-07-24 08:37:18 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab id="closed-orders" name={t('Closed')}>
|
2023-08-10 15:02:46 +00:00
|
|
|
<TradingViews.orders.component filter={Filter.Closed} />
|
2023-07-24 08:37:18 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab id="rejected-orders" name={t('Rejected')}>
|
2023-08-10 15:02:46 +00:00
|
|
|
<TradingViews.orders.component filter={Filter.Rejected} />
|
2023-07-24 08:37:18 +00:00
|
|
|
</Tab>
|
2023-08-10 15:02:46 +00:00
|
|
|
<Tab
|
|
|
|
id="orders"
|
|
|
|
name={t('All')}
|
|
|
|
menu={<TradingViews.orders.menu marketId={marketId} />}
|
|
|
|
>
|
|
|
|
<TradingViews.orders.component />
|
2023-07-24 08:37:18 +00:00
|
|
|
</Tab>
|
2023-08-02 10:28:33 +00:00
|
|
|
{FLAGS.STOP_ORDERS ? (
|
|
|
|
<Tab id="stop-orders" name={t('Stop orders')}>
|
2023-08-02 15:34:04 +00:00
|
|
|
<TradingViews.stopOrders.component />
|
2023-08-02 10:28:33 +00:00
|
|
|
</Tab>
|
|
|
|
) : null}
|
2023-07-24 08:37:18 +00:00
|
|
|
<Tab id="fills" name={t('Fills')}>
|
2023-08-10 15:02:46 +00:00
|
|
|
<TradingViews.fills.component marketId={marketId} />
|
2023-07-24 08:37:18 +00:00
|
|
|
</Tab>
|
2023-08-10 15:02:46 +00:00
|
|
|
<Tab
|
|
|
|
id="accounts"
|
|
|
|
name={t('Collateral')}
|
|
|
|
menu={<TradingViews.collateral.menu />}
|
|
|
|
>
|
|
|
|
<TradingViews.collateral.component pinnedAsset={pinnedAsset} />
|
2023-07-24 08:37:18 +00:00
|
|
|
</Tab>
|
|
|
|
</Tabs>
|
|
|
|
</TradeGridChild>
|
2023-03-17 09:50:43 +00:00
|
|
|
</ResizableGridPanel>
|
|
|
|
</ResizableGrid>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
MainGrid.displayName = 'MainGrid';
|
2022-10-11 12:30:07 +00:00
|
|
|
|
2023-05-16 16:57:36 +00:00
|
|
|
export const TradeGrid = ({ market, pinnedAsset }: TradeGridProps) => {
|
|
|
|
const wrapperClasses = classNames(
|
|
|
|
'h-full grid',
|
2023-07-24 08:37:18 +00:00
|
|
|
'grid-rows-[min-content_1fr]'
|
2023-05-16 16:57:36 +00:00
|
|
|
);
|
|
|
|
|
2022-10-11 12:30:07 +00:00
|
|
|
return (
|
2023-05-16 16:57:36 +00:00
|
|
|
<div className={wrapperClasses}>
|
2023-07-24 08:37:18 +00:00
|
|
|
<div>
|
2023-07-27 14:54:00 +00:00
|
|
|
{FLAGS.SUCCESSOR_MARKETS && (
|
|
|
|
<>
|
|
|
|
<MarketSuccessorBanner market={market} />
|
|
|
|
<MarketSuccessorProposalBanner marketId={market?.id} />
|
|
|
|
</>
|
|
|
|
)}
|
2023-04-21 16:31:52 +00:00
|
|
|
<OracleBanner marketId={market?.id || ''} />
|
|
|
|
</div>
|
2023-07-24 08:37:18 +00:00
|
|
|
<div className="min-h-0 p-0.5">
|
2023-05-16 16:57:36 +00:00
|
|
|
<MainGrid marketId={market?.id || ''} pinnedAsset={pinnedAsset} />
|
|
|
|
</div>
|
2022-08-31 04:35:46 +00:00
|
|
|
</div>
|
2022-03-02 02:08:42 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface TradeGridChildProps {
|
|
|
|
children: ReactNode;
|
|
|
|
}
|
|
|
|
|
2022-08-31 04:35:46 +00:00
|
|
|
const TradeGridChild = ({ children }: TradeGridChildProps) => {
|
2022-03-02 02:08:42 +00:00
|
|
|
return (
|
2023-07-24 08:37:18 +00:00
|
|
|
<section className="h-full p-1">
|
2022-03-02 02:08:42 +00:00
|
|
|
<AutoSizer>
|
2023-07-24 08:37:18 +00:00
|
|
|
{({ width, height }) => (
|
|
|
|
<div
|
|
|
|
style={{ width, height }}
|
|
|
|
className="border border-default rounded-sm"
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
)}
|
2022-03-02 02:08:42 +00:00
|
|
|
</AutoSizer>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
};
|