0523b56e39
* 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
179 lines
4.2 KiB
TypeScript
179 lines
4.2 KiB
TypeScript
import { gql } from '@apollo/client';
|
|
import { SelectMarketDialog } from '@vegaprotocol/market-list';
|
|
import { t } from '@vegaprotocol/react-helpers';
|
|
import { Interval } from '@vegaprotocol/types';
|
|
import { Splash } from '@vegaprotocol/ui-toolkit';
|
|
import debounce from 'lodash/debounce';
|
|
import { useRouter } from 'next/router';
|
|
import React, { useEffect, useState } from 'react';
|
|
import { PageQueryContainer } from '../../components/page-query-container';
|
|
import { useGlobalStore } from '../../stores';
|
|
import { TradeGrid, TradePanels } from './trade-grid';
|
|
|
|
import type { Market, MarketVariables } from './__generated__/Market';
|
|
// Top level page query
|
|
const MARKET_QUERY = gql`
|
|
query Market($marketId: ID!, $interval: Interval!, $since: String!) {
|
|
market(id: $marketId) {
|
|
id
|
|
name
|
|
tradingMode
|
|
state
|
|
decimalPlaces
|
|
positionDecimalPlaces
|
|
data {
|
|
market {
|
|
id
|
|
}
|
|
auctionStart
|
|
auctionEnd
|
|
markPrice
|
|
indicativeVolume
|
|
indicativePrice
|
|
suppliedStake
|
|
targetStake
|
|
bestBidVolume
|
|
bestOfferVolume
|
|
bestStaticBidVolume
|
|
bestStaticOfferVolume
|
|
trigger
|
|
}
|
|
tradableInstrument {
|
|
instrument {
|
|
name
|
|
code
|
|
metadata {
|
|
tags
|
|
}
|
|
product {
|
|
... on Future {
|
|
quoteName
|
|
settlementAsset {
|
|
id
|
|
symbol
|
|
name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
marketTimestamps {
|
|
open
|
|
close
|
|
}
|
|
candles(interval: $interval, since: $since) {
|
|
open
|
|
close
|
|
volume
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
const MarketPage = ({ id }: { id?: string }) => {
|
|
const { query } = useRouter();
|
|
const { w } = useWindowSize();
|
|
const store = useGlobalStore();
|
|
|
|
// Default to first marketId query item if found
|
|
const marketId =
|
|
id || (Array.isArray(query.marketId) ? query.marketId[0] : query.marketId);
|
|
|
|
// Cache timestamp for yesterday to prevent full unmount of market page when
|
|
// a rerender occurs
|
|
const [yTimestamp] = useState(() => {
|
|
const yesterday = Math.round(new Date().getTime() / 1000) - 24 * 3600;
|
|
return new Date(yesterday * 1000).toISOString();
|
|
});
|
|
|
|
if (!marketId) {
|
|
return (
|
|
<Splash>
|
|
<p>{t('Not found')}</p>
|
|
</Splash>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<PageQueryContainer<Market, MarketVariables>
|
|
query={MARKET_QUERY}
|
|
data-testid="market"
|
|
options={{
|
|
variables: {
|
|
marketId,
|
|
interval: Interval.I1H,
|
|
since: yTimestamp,
|
|
},
|
|
fetchPolicy: 'network-only',
|
|
}}
|
|
render={({ market }) => {
|
|
if (!market) {
|
|
return <Splash>{t('Market not found')}</Splash>;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{w > 960 ? (
|
|
<TradeGrid market={market} />
|
|
) : (
|
|
<TradePanels market={market} />
|
|
)}
|
|
<SelectMarketDialog
|
|
dialogOpen={store.landingDialog}
|
|
setDialogOpen={(isOpen: boolean) =>
|
|
store.setLandingDialog(isOpen)
|
|
}
|
|
onSelect={(marketId: string) => {
|
|
if (marketId && store.marketId !== marketId) {
|
|
store.setMarketId(marketId);
|
|
}
|
|
}}
|
|
title={t('Select a market to get started')}
|
|
/>
|
|
</>
|
|
);
|
|
}}
|
|
/>
|
|
);
|
|
};
|
|
|
|
MarketPage.getInitialProps = () => ({
|
|
page: 'market',
|
|
});
|
|
|
|
export default MarketPage;
|
|
|
|
const useWindowSize = () => {
|
|
const [windowSize, setWindowSize] = useState(() => {
|
|
if (typeof window !== 'undefined') {
|
|
return {
|
|
w: window.innerWidth,
|
|
h: window.innerHeight,
|
|
};
|
|
}
|
|
|
|
// Something sensible for server rendered page
|
|
return {
|
|
w: 1200,
|
|
h: 900,
|
|
};
|
|
});
|
|
|
|
useEffect(() => {
|
|
const handleResize = debounce(({ target }) => {
|
|
setWindowSize({
|
|
w: target.innerWidth,
|
|
h: target.innerHeight,
|
|
});
|
|
}, 300);
|
|
|
|
window.addEventListener('resize', handleResize);
|
|
|
|
return () => {
|
|
window.removeEventListener('resize', handleResize);
|
|
};
|
|
}, []);
|
|
|
|
return windowSize;
|
|
};
|