vega-frontend-monorepo/apps/trading/pages/index.page.tsx

92 lines
2.4 KiB
TypeScript
Raw Normal View History

import {
AgGridDynamic as AgGrid,
Button,
Callout,
Feat/63 Deal ticket (#82) * scaffold dealticket package, remove trading views from react-helpers * add deal ticket component, add intent utils, expand dialog and form group styles * add splash component, show market not found message if market doesnt exist * tidy up error handling * add handleError method for vega tx hook * add better testname for provider test, flesh out tests a bit more for deal ticket * Add unit tests for useVegaTransaction and useOrderSubmit hooks * add wrapper component for order dialog styles * add vega styled loader to ui toolkit and use in order dialog * add title prop to order dialog * split limit and market tickets into own files * add button radio component * revert dialog styles * move splash component to ui-toolkit, add story * convert intent to enum * Make button always type=button unless type prop is passed * inline filter logic for tif selector * add date-fns, add datetime to helpers * add order types to wallet package, make price undefined if order type is market * use enums in deal ticket logic * tidy up order state by moving submit and transaction hooks out of deal ticket * add comment for dialog styles * remove decimal from price input * add types package, delete old generated types from trading project * rename types package to graphql * update generate command to point to correct locations * fix use order submit test * use intent shadow helper * remove date-fns and format manually, update submit button error to use input-error * remove stray console.log
2022-03-17 19:35:46 +00:00
Intent,
} from '@vegaprotocol/ui-toolkit';
2022-03-23 07:25:20 +00:00
import type { GridApi } from 'ag-grid-community';
import { AgGridColumn } from 'ag-grid-react';
2022-03-23 07:25:20 +00:00
import { useState, useEffect, useRef } from 'react';
import { useApplyGridTransaction } from '@vegaprotocol/react-helpers';
2022-02-23 17:57:44 +00:00
2022-03-23 07:25:20 +00:00
const Grid = () => {
const rowData = [
{ make: 'Toyota', model: 'Celica', price: 35000 },
{ make: 'Ford', model: 'Mondeo', price: 32000 },
{ make: 'Porsche', model: 'Boxter', price: 72000 },
];
2022-03-23 07:25:20 +00:00
const ref = useRef(rowData);
const getRowNodeId = (data: { make: string }) => data.make;
const gridApi = useRef<GridApi | null>(null);
useEffect(() => {
const interval = setInterval(() => {
if (!gridApi) return;
const update = [];
const add = [];
// split into updates and adds
[...rowData].forEach((data) => {
if (!gridApi.current) return;
const rowNode = gridApi.current.getRowNode(getRowNodeId(data));
if (rowNode) {
if (rowNode.data !== data) {
update.push(data);
}
} else {
add.push(data);
}
});
// async transaction for optimal handling of high grequency updates
if (update.length || add.length) {
gridApi.current.applyTransaction({
update,
add,
addIndex: 0,
});
}
}, 1000);
return () => clearInterval(interval);
});
return (
<AgGrid
onGridReady={(params) => {
gridApi.current = params.api;
}}
getRowNodeId={getRowNodeId}
rowData={ref.current}
style={{ height: 400, width: 600 }}
>
<AgGridColumn field="make"></AgGridColumn>
<AgGridColumn field="model"></AgGridColumn>
<AgGridColumn field="price"></AgGridColumn>
</AgGrid>
);
};
export function Index() {
return (
2022-03-10 00:33:56 +00:00
<div className="m-24">
<div className="mb-24">
<Callout
Feat/63 Deal ticket (#82) * scaffold dealticket package, remove trading views from react-helpers * add deal ticket component, add intent utils, expand dialog and form group styles * add splash component, show market not found message if market doesnt exist * tidy up error handling * add handleError method for vega tx hook * add better testname for provider test, flesh out tests a bit more for deal ticket * Add unit tests for useVegaTransaction and useOrderSubmit hooks * add wrapper component for order dialog styles * add vega styled loader to ui toolkit and use in order dialog * add title prop to order dialog * split limit and market tickets into own files * add button radio component * revert dialog styles * move splash component to ui-toolkit, add story * convert intent to enum * Make button always type=button unless type prop is passed * inline filter logic for tif selector * add date-fns, add datetime to helpers * add order types to wallet package, make price undefined if order type is market * use enums in deal ticket logic * tidy up order state by moving submit and transaction hooks out of deal ticket * add comment for dialog styles * remove decimal from price input * add types package, delete old generated types from trading project * rename types package to graphql * update generate command to point to correct locations * fix use order submit test * use intent shadow helper * remove date-fns and format manually, update submit button error to use input-error * remove stray console.log
2022-03-17 19:35:46 +00:00
intent={Intent.Help}
title="Welcome to Vega Trading App"
iconName="endorsed"
headingLevel={1}
>
<div className="flex flex-col">
<div>With a longer explaination</div>
<Button className="block mt-8" variant="secondary">
Action
</Button>
</div>
</Callout>
</div>
2022-03-23 07:25:20 +00:00
<Grid />
</div>
);
}
2022-02-23 17:57:44 +00:00
export default Index;