vega-frontend-monorepo/apps/trading/pages/index.page.tsx
m.ray c0532a8507
Feat/470 edit order ()
* feat: 470 edit orders hook and @vegaprotocol/vegawallet-service-api-client@0.4.14

* fix: 470 add methods for dialog intent and title

* fix:  rename order-list lib to orders

* chore:  move hooks to orders lib

* chore:  vega tx dialog used for order cancellation and order submission

* chore:  use client subscribe and unsubscribe on reset, refactor vegatxdialog

* fix:  revert script src=./env-config.js ending

* fix:  format project.json

* Update project.json

* fix:  cancel all subs and async tasks in useffect cleanup function

* feat:  styling updates on vega order dialog

* fix:  rename set dialog open and awaiting confirmation dialog update

* fix:  updates on cancel order id check

* fix:   fix vega tx dialog test

* fix:   fix cypress trading-deal-tciket test

* fix:   fix data-testid market test

* fix:   add use order edit hook

* fix:   edit order button

* 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:  remove the magic string and use the ordertype enum from types package

* fix:  guarantee that order.id is present at this point or we need to determine the id of the order

* fix:  fix translation in dialog

* fix:  rename wallet types, delete ticket query, set finalized order null in submit

* fix:  fix deal ticket steps test

* fix:  remove settings.json

* fix:  use order submit in orders lib

* fix:  open edit order modal and update storybook

* feat:   edit modals set up

* fix:  final modal links to block explorer

* fix:  long/short instead of buy/sell

* fix:  use only one vega tx dialog

* fix:  keep ref of subscription and unsubscribe

* fix:   hide cancelled orders

* fix:  sub only when id set

* fix: WIP: trying to unsub when order updated

* fix:  long/short instead of buy/sell

* fix: ensure observable defined

* fix:  remove redundant test

* fix:  merge with new order hooks

* fix:  fix use-order-edit no red update order-list with code

* fix:   invert order show price last in dialog

* fix:  able to edit order

* fix:  fix dialog transition

* fix:    show Continuous trading and market state from trade grid header

* fix:  filter out rejected markets

* fix:  filter out rejected markets

* fix:   revert to 17.0.2 react

* fix:   revert to 17.0.2 react

* fix:  filter out rejected markets & dialog lg width

* fix:  show trading mode Continuous Trading and hide market state

* fix:  modify order validation to trade when suspended

* fix:  fix use order validation tests

* fix:  format volume no

* fix: format volume with positionDecimalPlaces

* fix: tests don't need to be async

* fix: md:w-[720px] to prevent dialog overflow

* fix: add market state translations

* fix: imprt type validation props

* fix:  working edit submit on GTC not on GTT as it is missing expiresAt

* Update libs/orders/src/lib/order-hooks/use-order-validation.tsx

Co-authored-by: candida-d <62548908+candida-d@users.noreply.github.com>

* Update libs/orders/src/lib/order-hooks/use-order-validation.tsx

Co-authored-by: candida-d <62548908+candida-d@users.noreply.github.com>

* Update libs/orders/src/lib/order-hooks/use-order-validation.tsx

Co-authored-by: candida-d <62548908+candida-d@users.noreply.github.com>

* Update libs/orders/src/lib/order-hooks/use-order-validation.tsx

Co-authored-by: candida-d <62548908+candida-d@users.noreply.github.com>

* Update libs/orders/src/lib/order-hooks/use-order-validation.tsx

Co-authored-by: candida-d <62548908+candida-d@users.noreply.github.com>

* Update libs/orders/src/lib/order-hooks/use-order-validation.spec.tsx

Co-authored-by: candida-d <62548908+candida-d@users.noreply.github.com>

* Update apps/trading/pages/markets/__generated__/Market.ts

Co-authored-by: candida-d <62548908+candida-d@users.noreply.github.com>

* fix: fix warning messages based on feedback

* fix: capitalize trading mode

* fix: capitalize trading mode

* fix: remove line 72 on markets.cy.ts

* fix: don't show trigger if unspecified

* fix: format last price and shrink 0 on warning icon

* fix: order sizes must be whole numbers for this market and input warning size 20

* fix: order sizes must be whole numbers for this market and input warning size 20

* fix: format market list

* fix:  fix expiresAt and price unmarshall values

* fix:  fix expiresAt and price unmarshall values

* fix:  add extra test on editing order

* fix: pass child react node for order edit on vega tx default

* fix: status and rejection reason optional

* fix: add header transalations and remove commented line

* fix: simplify get list of markets

* fix: check if order.market undefined

* fix: remove cast and check market id

Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com>
Co-authored-by: Matthew Russell <mattrussell36@gmail.com>
Co-authored-by: candida-d <62548908+candida-d@users.noreply.github.com>
2022-07-20 17:40:28 +01:00

66 lines
1.7 KiB
TypeScript

import { gql, useQuery } from '@apollo/client';
import { AsyncRenderer } from '@vegaprotocol/ui-toolkit';
import orderBy from 'lodash/orderBy';
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { useGlobalStore } from '../stores';
import type { MarketsLanding } from './__generated__/MarketsLanding';
const MARKETS_QUERY = gql`
query MarketsLanding {
markets {
id
tradingMode
state
marketTimestamps {
open
}
}
}
`;
const getMarketList = ({ markets = [] }: MarketsLanding) => {
return orderBy(
markets,
['marketTimestamps.open', 'id'],
['asc', 'asc', 'asc']
);
};
export function Index() {
const { replace } = useRouter();
// The default market selected in the platform behind the overlay
// should be the oldest market that is currently trading in continuous mode(i.e. not in auction).
const { data, error, loading } = useQuery<MarketsLanding>(MARKETS_QUERY);
const setLandingDialog = useGlobalStore((state) => state.setLandingDialog);
useEffect(() => {
if (data) {
const marketId = getMarketList(data)[0]?.id;
// If a default market is found, go to it with the landing dialog open
if (marketId) {
setLandingDialog(true);
replace(`/markets/${marketId}`);
}
// Fallback to the markets list page
else {
replace('/markets');
}
}
}, [data, replace, setLandingDialog]);
return (
<AsyncRenderer data={data} loading={loading} error={error}>
{/* Render a loading and error state but we will redirect if markets are found */}
{null}
</AsyncRenderer>
);
}
Index.getInitialProps = () => ({
page: 'home',
});
export default Index;