07abc2b1eb
* feat: 470 edit orders hook and @vegaprotocol/vegawallet-service-api-client@0.4.14 * fix: 470 add methods for dialog intent and title * fix: #657 rename order-list lib to orders * chore: #657 move hooks to orders lib * chore: #657 vega tx dialog used for order cancellation and order submission * chore: #657 use client subscribe and unsubscribe on reset, refactor vegatxdialog * fix: #657 revert script src=./env-config.js ending * fix: #657 format project.json * Update project.json * fix: #657 cancel all subs and async tasks in useffect cleanup function * feat: #657 styling updates on vega order dialog * fix: #657 rename set dialog open and awaiting confirmation dialog update * fix: #657 updates on cancel order id check * fix: #657 fix vega tx dialog test * fix: #657 fix cypress trading-deal-tciket test * fix: #657 fix data-testid market test * Update libs/orders/README.md Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * Update libs/wallet/src/vega-order-transaction-dialog/vega-order-transaction-dialog.tsx Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * Update libs/wallet/src/vega-transaction-dialog/vega-transaction-dialog.tsx Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * Update libs/wallet/src/vega-order-transaction-dialog/vega-order-transaction-dialog.tsx Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * Update libs/wallet/src/vega-order-transaction-dialog/vega-order-transaction-dialog.tsx Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * fix: #657 remove the magic string and use the ordertype enum from types package * fix: #657 guarantee that order.id is present at this point or we need to determine the id of the order * fix: #657 fix translation in dialog * fix: #657 rename wallet types, delete ticket query, set finalized order null in submit * fix: #657 fix deal ticket steps test * fix: #657 remove settings.json * fix: #657 use order submit in orders lib * fix: #463 final modal links to block explorer * fix: #745 long/short instead of buy/sell * fix: #657 use only one vega tx dialog * fix: #657 keep ref of subscription and unsubscribe * fix: #657 hide cancelled orders * fix: #657 sub only when id set * fix: WIP: trying to unsub when order updated * fix: #745 long/short instead of buy/sell * fix: ensure observable defined * fix: #657 remove redundant test * Update libs/orders/src/lib/order-hooks/use-order-submit.ts * fix: failing test due to resizeobserver loop limit exceeded * fix: lint * fix: #657 fix test resize observer loop limit exceeded Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> Co-authored-by: Matthew Russell <mattrussell36@gmail.com> Co-authored-by: Joe <joe@vega.xyz>
155 lines
3.6 KiB
TypeScript
155 lines
3.6 KiB
TypeScript
import { gql } from '@apollo/client';
|
|
import { Splash } from '@vegaprotocol/ui-toolkit';
|
|
import { useRouter } from 'next/router';
|
|
import React, { useEffect, useState } from 'react';
|
|
import debounce from 'lodash/debounce';
|
|
import { PageQueryContainer } from '../../components/page-query-container';
|
|
import { TradeGrid, TradePanels } from './trade-grid';
|
|
import { t } from '@vegaprotocol/react-helpers';
|
|
import { useGlobalStore } from '../../stores';
|
|
import { LandingDialog } from '@vegaprotocol/market-list';
|
|
import type { Market, MarketVariables } from './__generated__/Market';
|
|
import { Interval } from '@vegaprotocol/types';
|
|
|
|
// Top level page query
|
|
const MARKET_QUERY = gql`
|
|
query Market($marketId: ID!, $interval: Interval!, $since: String!) {
|
|
market(id: $marketId) {
|
|
id
|
|
name
|
|
tradingMode
|
|
state
|
|
decimalPlaces
|
|
data {
|
|
market {
|
|
id
|
|
}
|
|
markPrice
|
|
indicativeVolume
|
|
bestBidVolume
|
|
bestOfferVolume
|
|
bestStaticBidVolume
|
|
bestStaticOfferVolume
|
|
indicativeVolume
|
|
}
|
|
tradableInstrument {
|
|
instrument {
|
|
name
|
|
code
|
|
metadata {
|
|
tags
|
|
}
|
|
}
|
|
}
|
|
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} />
|
|
)}
|
|
<LandingDialog
|
|
open={store.landingDialog}
|
|
setOpen={(isOpen) => store.setLandingDialog(isOpen)}
|
|
/>
|
|
</>
|
|
);
|
|
}}
|
|
/>
|
|
);
|
|
};
|
|
|
|
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;
|
|
};
|