Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83067deede | ||
|
|
c19207d5d7 | ||
|
|
0d5b81c1d9 | ||
|
|
bff45c2439 | ||
|
|
84da7b2660 | ||
|
|
c46881281b | ||
|
|
362424ca02 | ||
|
|
500e1a3e5d | ||
|
|
33637a5505 | ||
|
|
b32b6d1e63 | ||
|
|
4e09b545f2 | ||
|
|
420f33abb7 | ||
|
|
40774dcc25 | ||
|
|
ef6892acdc | ||
|
|
5570513d25 | ||
|
|
3773ff8fc9 | ||
|
|
9fe7270839 | ||
|
|
513db4b40a | ||
|
|
de90f8fa05 | ||
|
|
857a07ef40 | ||
|
|
e6d2c5f688 | ||
|
|
7030b3c9cf | ||
|
|
3cca711eea | ||
|
|
fd69a4915b | ||
|
|
72a2a1be99 | ||
|
|
97d923c94d | ||
|
|
2b6e7bcfab | ||
|
|
e4139f6d36 | ||
|
|
4033ed960e | ||
|
|
e23dd57ec5 | ||
|
|
acdf209cef | ||
|
|
e0d1412562 | ||
|
|
395d05b4b8 | ||
|
|
f2ad04e126 | ||
|
|
ddaebea67d | ||
|
|
e89e37e5b6 | ||
|
|
bfcd66248c | ||
|
|
f5f214aaff | ||
|
|
44658b00d5 | ||
|
|
32a70a69a3 |
@@ -6,6 +6,7 @@ import '@testing-library/jest-dom';
|
||||
import dev from './i18n/translations/dev.json';
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
import ResizeObserver from 'resize-observer-polyfill';
|
||||
|
||||
// Set up i18n instance so that components have the correct default
|
||||
// en translations
|
||||
@@ -22,3 +23,5 @@ i18n.use(initReactI18next).init({
|
||||
ns: ['translations'],
|
||||
defaultNS: 'translations',
|
||||
});
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
||||
@@ -155,6 +155,7 @@ const MarketBottomPanel = memo(
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
enforceBottomPlaceholder
|
||||
storeKey="marketOpenOrders"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -166,6 +167,7 @@ const MarketBottomPanel = memo(
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
enforceBottomPlaceholder
|
||||
storeKey="marketClosedOrders"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -177,6 +179,7 @@ const MarketBottomPanel = memo(
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
enforceBottomPlaceholder
|
||||
storeKey="marketRejectOrders"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -187,6 +190,7 @@ const MarketBottomPanel = memo(
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
enforceBottomPlaceholder
|
||||
storeKey="marketAllOrders"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -195,6 +199,7 @@ const MarketBottomPanel = memo(
|
||||
<TradingViews.fills.component
|
||||
marketId={marketId}
|
||||
onMarketClick={onMarketClick}
|
||||
storeKey="marketFills"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -213,6 +218,7 @@ const MarketBottomPanel = memo(
|
||||
<TradingViews.positions.component
|
||||
onMarketClick={onMarketClick}
|
||||
noBottomPlaceholder
|
||||
storeKey="marketPositions"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -222,6 +228,7 @@ const MarketBottomPanel = memo(
|
||||
pinnedAsset={pinnedAsset}
|
||||
noBottomPlaceholder
|
||||
hideButtons
|
||||
storeKey="marketCollateral"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -234,7 +241,10 @@ const MarketBottomPanel = memo(
|
||||
<Tabs storageKey="console-trade-grid-bottom">
|
||||
<Tab id="positions" name={t('Positions')}>
|
||||
<VegaWalletContainer>
|
||||
<TradingViews.positions.component onMarketClick={onMarketClick} />
|
||||
<TradingViews.positions.component
|
||||
onMarketClick={onMarketClick}
|
||||
storeKey="marketPositions"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
<Tab id="open-orders" name={t('Open')}>
|
||||
@@ -245,6 +255,7 @@ const MarketBottomPanel = memo(
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
enforceBottomPlaceholder
|
||||
storeKey="marketOpenOrders"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -256,6 +267,7 @@ const MarketBottomPanel = memo(
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
enforceBottomPlaceholder
|
||||
storeKey="marketClosedOrders"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -267,6 +279,7 @@ const MarketBottomPanel = memo(
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
enforceBottomPlaceholder
|
||||
storeKey="marketRejectedOrders"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -277,6 +290,7 @@ const MarketBottomPanel = memo(
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
enforceBottomPlaceholder
|
||||
storeKey="marketAllOrders"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -285,6 +299,7 @@ const MarketBottomPanel = memo(
|
||||
<TradingViews.fills.component
|
||||
marketId={marketId}
|
||||
onMarketClick={onMarketClick}
|
||||
storeKey="marketFills"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -293,6 +308,7 @@ const MarketBottomPanel = memo(
|
||||
<TradingViews.collateral.component
|
||||
pinnedAsset={pinnedAsset}
|
||||
hideButtons
|
||||
storeKey="marketCollateral"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
|
||||
@@ -264,6 +264,7 @@ const ClosedMarketsDataGrid = ({ rowData }: { rowData: Row[] }) => {
|
||||
{
|
||||
headerName: t('Market ID'),
|
||||
field: 'id',
|
||||
flex: 1,
|
||||
},
|
||||
];
|
||||
return cols;
|
||||
@@ -276,10 +277,10 @@ const ClosedMarketsDataGrid = ({ rowData }: { rowData: Row[] }) => {
|
||||
columnDefs={colDefs}
|
||||
getRowId={({ data }) => data.id}
|
||||
defaultColDef={{
|
||||
flex: 1,
|
||||
resizable: true,
|
||||
}}
|
||||
overlayNoRowsTemplate="No data"
|
||||
storeKey="closedMarkets"
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -53,6 +53,7 @@ export const Portfolio = () => {
|
||||
<PositionsContainer
|
||||
onMarketClick={onMarketClick}
|
||||
noBottomPlaceholder
|
||||
storeKey="portfolioPositions"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
@@ -61,12 +62,16 @@ export const Portfolio = () => {
|
||||
<OrderListContainer
|
||||
onMarketClick={onMarketClick}
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
storeKey="portfolioOrders"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
<Tab id="fills" name={t('Fills')}>
|
||||
<VegaWalletContainer>
|
||||
<FillsContainer onMarketClick={onMarketClick} />
|
||||
<FillsContainer
|
||||
onMarketClick={onMarketClick}
|
||||
storeKey="portfolioFills"
|
||||
/>
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
<Tab id="ledger-entries" name={t('Ledger entries')}>
|
||||
@@ -86,7 +91,7 @@ export const Portfolio = () => {
|
||||
<Tabs storageKey="console-portfolio-bottom">
|
||||
<Tab id="collateral" name={t('Collateral')}>
|
||||
<VegaWalletContainer>
|
||||
<AccountsContainer />
|
||||
<AccountsContainer storeKey="portfolioCollateral" />
|
||||
</VegaWalletContainer>
|
||||
</Tab>
|
||||
<Tab id="deposits" name={t('Deposits')}>
|
||||
|
||||
@@ -13,10 +13,12 @@ export const AccountsContainer = ({
|
||||
pinnedAsset,
|
||||
hideButtons,
|
||||
noBottomPlaceholder,
|
||||
storeKey,
|
||||
}: {
|
||||
pinnedAsset?: PinnedAsset;
|
||||
hideButtons?: boolean;
|
||||
noBottomPlaceholder?: boolean;
|
||||
storeKey?: string;
|
||||
}) => {
|
||||
const { pubKey, isReadOnly } = useVegaWallet();
|
||||
const { open: openAssetDetailsDialog } = useAssetDetailsDialogStore();
|
||||
@@ -49,6 +51,7 @@ export const AccountsContainer = ({
|
||||
isReadOnly={isReadOnly}
|
||||
pinnedAsset={pinnedAsset}
|
||||
noBottomPlaceholder={noBottomPlaceholder}
|
||||
storeKey={storeKey}
|
||||
/>
|
||||
{!isReadOnly && !hideButtons && (
|
||||
<div className="flex gap-2 justify-end p-2 px-[11px] absolute lg:fixed bottom-0 right-3 dark:bg-black/75 bg-white/75 rounded">
|
||||
|
||||
@@ -17,6 +17,7 @@ interface AccountManagerProps {
|
||||
isReadOnly: boolean;
|
||||
pinnedAsset?: PinnedAsset;
|
||||
noBottomPlaceholder?: boolean;
|
||||
storeKey?: string;
|
||||
}
|
||||
|
||||
export const AccountManager = ({
|
||||
@@ -27,6 +28,7 @@ export const AccountManager = ({
|
||||
isReadOnly,
|
||||
pinnedAsset,
|
||||
noBottomPlaceholder,
|
||||
storeKey,
|
||||
}: AccountManagerProps) => {
|
||||
const gridRef = useRef<AgGridReact | null>(null);
|
||||
const variables = useMemo(() => ({ partyId }), [partyId]);
|
||||
@@ -59,6 +61,7 @@ export const AccountManager = ({
|
||||
suppressLoadingOverlay
|
||||
suppressNoRowsOverlay
|
||||
pinnedAsset={pinnedAsset}
|
||||
storeKey={storeKey}
|
||||
{...bottomPlaceholderProps}
|
||||
/>
|
||||
<div className="pointer-events-none absolute inset-0">
|
||||
|
||||
@@ -100,6 +100,7 @@ export interface AccountTableProps extends AgGridReactProps {
|
||||
onClickDeposit?: (assetId: string) => void;
|
||||
isReadOnly: boolean;
|
||||
pinnedAsset?: PinnedAsset;
|
||||
storeKey?: string;
|
||||
}
|
||||
|
||||
export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
|
||||
@@ -155,7 +156,6 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
|
||||
(data) => data.asset.id !== pinnedAssetId
|
||||
)}
|
||||
defaultColDef={{
|
||||
flex: 1,
|
||||
resizable: true,
|
||||
tooltipComponent: TooltipCellComponent,
|
||||
sortable: true,
|
||||
@@ -187,7 +187,6 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
|
||||
</ButtonLink>
|
||||
);
|
||||
}}
|
||||
maxWidth={300}
|
||||
/>
|
||||
<AgGridColumn
|
||||
headerName={t('Used')}
|
||||
@@ -362,6 +361,7 @@ export const AccountTable = forwardRef<AgGridReact, AccountTableProps>(
|
||||
);
|
||||
}
|
||||
}}
|
||||
flex={1}
|
||||
/>
|
||||
}
|
||||
</AgGrid>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from './lib/ag-grid/ag-grid-lazy';
|
||||
export * from './lib/ag-grid/use-column-sizes';
|
||||
|
||||
export * from './lib/cells/cumulative-vol-cell';
|
||||
export * from './lib/cells/flash-cell';
|
||||
|
||||
@@ -1,22 +1,30 @@
|
||||
import type { AgGridReactProps, AgReactUiProps } from 'ag-grid-react';
|
||||
import { AgGridReact } from 'ag-grid-react';
|
||||
import { useThemeSwitcher } from '@vegaprotocol/react-helpers';
|
||||
import { useColumnSizes } from './use-column-sizes';
|
||||
import classNames from 'classnames';
|
||||
|
||||
export const AgGridThemed = ({
|
||||
style,
|
||||
gridRef,
|
||||
storeKey,
|
||||
...props
|
||||
}: (AgGridReactProps | AgReactUiProps) & {
|
||||
style?: React.CSSProperties;
|
||||
gridRef?: React.ForwardedRef<AgGridReact>;
|
||||
storeKey?: string;
|
||||
}) => {
|
||||
const commonColumnCallbacks = useColumnSizes({
|
||||
storeKey,
|
||||
props,
|
||||
});
|
||||
const { theme } = useThemeSwitcher();
|
||||
const defaultProps = {
|
||||
rowHeight: 22,
|
||||
headerHeight: 22,
|
||||
enableCellTextSelection: true,
|
||||
};
|
||||
|
||||
const wrapperClasses = classNames('vega-ag-grid', {
|
||||
'ag-theme-balham': theme === 'light',
|
||||
'ag-theme-balham-dark': theme === 'dark',
|
||||
@@ -24,7 +32,12 @@ export const AgGridThemed = ({
|
||||
|
||||
return (
|
||||
<div className={wrapperClasses} style={style}>
|
||||
<AgGridReact {...defaultProps} {...props} ref={gridRef} />
|
||||
<AgGridReact
|
||||
{...defaultProps}
|
||||
{...props}
|
||||
{...commonColumnCallbacks}
|
||||
ref={gridRef}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { AgGridReactProps, AgGridReact } from 'ag-grid-react';
|
||||
type Props = AgGridReactProps & {
|
||||
style?: React.CSSProperties;
|
||||
gridRef?: React.Ref<AgGridReact>;
|
||||
storeKey?: string;
|
||||
};
|
||||
|
||||
export const AgGridLazyInternal = lazy(() =>
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
import type {
|
||||
Column,
|
||||
ColumnResizedEvent,
|
||||
GridSizeChangedEvent,
|
||||
GridReadyEvent,
|
||||
} from 'ag-grid-community';
|
||||
import { renderHook, act, waitFor } from '@testing-library/react';
|
||||
import { useColumnSizes } from './use-column-sizes';
|
||||
|
||||
const mockApis = {
|
||||
api: {
|
||||
sizeColumnsToFit: jest.fn(),
|
||||
},
|
||||
columnApi: {
|
||||
setColumnWidths: jest.fn(),
|
||||
},
|
||||
};
|
||||
|
||||
const mockValueSetter = jest.fn();
|
||||
const mockStore = {
|
||||
sizes: { testid: { col1: 100 } },
|
||||
valueSetter: mockValueSetter,
|
||||
};
|
||||
jest.mock('zustand', () => ({
|
||||
...jest.requireActual('zustand'),
|
||||
create: () =>
|
||||
jest.fn(() =>
|
||||
jest.fn().mockImplementation((creator) => {
|
||||
return creator(mockStore);
|
||||
})
|
||||
),
|
||||
}));
|
||||
describe('UseColumnSizes hook', () => {
|
||||
const storeKey = 'testid';
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
it('should return proper methods', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useColumnSizes({ storeKey, props: {} })
|
||||
);
|
||||
expect(Object.keys(result.current)).toHaveLength(3);
|
||||
expect(result.current).toStrictEqual({
|
||||
onColumnResized: expect.any(Function),
|
||||
onGridReady: expect.any(Function),
|
||||
onGridSizeChanged: expect.any(Function),
|
||||
});
|
||||
});
|
||||
|
||||
it('onGridSizeChanged should call setSize', async () => {
|
||||
const { result } = renderHook(() =>
|
||||
useColumnSizes({ storeKey, props: {} })
|
||||
);
|
||||
await act(() => {
|
||||
result.current.onGridSizeChanged?.({
|
||||
clientWidth: 1000,
|
||||
...mockApis,
|
||||
} as GridSizeChangedEvent);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(mockApis.columnApi.setColumnWidths).toHaveBeenCalledWith([
|
||||
{ key: 'col1', newWidth: 100 },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('onColumnResized should fill up store', async () => {
|
||||
const columns: Column[] = [
|
||||
{ getColId: () => 'col1', getActualWidth: () => 100 },
|
||||
{ getColId: () => 'col2', getActualWidth: () => 200 },
|
||||
] as Column[];
|
||||
const sizeObj = { col1: 100, col2: 200, clientWidth: 1000 };
|
||||
const { result } = renderHook(() =>
|
||||
useColumnSizes({ storeKey, props: {} })
|
||||
);
|
||||
await act(() => {
|
||||
result.current.onGridSizeChanged?.({
|
||||
clientWidth: 1000,
|
||||
...mockApis,
|
||||
} as GridSizeChangedEvent);
|
||||
});
|
||||
await act(() => {
|
||||
result.current.onColumnResized?.({
|
||||
columns,
|
||||
finished: true,
|
||||
source: 'uiColumnDragged',
|
||||
...mockApis,
|
||||
} as ColumnResizedEvent);
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(mockValueSetter).toHaveBeenCalledWith(storeKey, sizeObj);
|
||||
});
|
||||
});
|
||||
|
||||
it('onGridReady should call setSizes', async () => {
|
||||
const props = { onGridReady: jest.fn() };
|
||||
const { result } = renderHook(() => useColumnSizes({ storeKey, props }));
|
||||
const obTest = { cool: 1, ...mockApis };
|
||||
await act(() => {
|
||||
result.current.onGridReady?.(obTest as GridReadyEvent);
|
||||
});
|
||||
expect(props.onGridReady).toHaveBeenCalledWith(obTest);
|
||||
expect(mockApis.api.sizeColumnsToFit).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('if no storeKey should be transparent', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useColumnSizes({ storeKey: '', props: {} })
|
||||
);
|
||||
expect(result.current).toStrictEqual({
|
||||
onColumnResized: undefined,
|
||||
onGridReady: undefined,
|
||||
onGridSizeChanged: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,143 @@
|
||||
import { useCallback, useRef } from 'react';
|
||||
import type {
|
||||
GridSizeChangedEvent,
|
||||
GridReadyEvent,
|
||||
ColumnResizedEvent,
|
||||
} from 'ag-grid-community';
|
||||
import type { AgGridReactProps, AgReactUiProps } from 'ag-grid-react';
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
|
||||
const STORAGE_KEY = 'vega_columns_sizes_store';
|
||||
|
||||
export const useColumnSizesStore = create<{
|
||||
sizes: Record<string, Record<string, number>>;
|
||||
valueSetter: (storeKey: string, value: Record<string, number>) => void;
|
||||
}>()(
|
||||
persist(
|
||||
immer((set) => ({
|
||||
sizes: {},
|
||||
valueSetter: (storeKey, value) =>
|
||||
set((state) => {
|
||||
state.sizes[storeKey] = {
|
||||
...(state.sizes[storeKey] || {}),
|
||||
...value,
|
||||
};
|
||||
return state;
|
||||
}),
|
||||
})),
|
||||
{ name: STORAGE_KEY }
|
||||
)
|
||||
);
|
||||
|
||||
interface UseColumnSizesProps {
|
||||
props: AgGridReactProps | AgReactUiProps;
|
||||
storeKey?: string;
|
||||
}
|
||||
|
||||
export const useColumnSizes = ({
|
||||
storeKey = '',
|
||||
props,
|
||||
}: UseColumnSizesProps): {
|
||||
onColumnResized?: (event: ColumnResizedEvent) => void;
|
||||
onGridReady?: (event: GridReadyEvent) => void;
|
||||
onGridSizeChanged?: (event: GridSizeChangedEvent) => void;
|
||||
} => {
|
||||
const sizes = useColumnSizesStore((store) => store.sizes[storeKey] || {});
|
||||
const valueSetter = useColumnSizesStore((store) => store.valueSetter);
|
||||
const widthRef = useRef(sizes['clientWidth'] || 0);
|
||||
const {
|
||||
onColumnResized: parentOnColumnResized,
|
||||
onGridReady: parentOnGridReady,
|
||||
onGridSizeChanged: parentOnGridSizeChanged,
|
||||
} = props;
|
||||
const recalculateSizes = useCallback((sizes: Record<string, number>) => {
|
||||
if (
|
||||
widthRef.current &&
|
||||
sizes['clientWidth'] &&
|
||||
widthRef.current !== sizes['clientWidth']
|
||||
) {
|
||||
const oldWidth = sizes['clientWidth'];
|
||||
const ratio = widthRef.current / oldWidth;
|
||||
return {
|
||||
...Object.entries(sizes).reduce((agg, [key, value]) => {
|
||||
agg[key] = value * ratio;
|
||||
return agg;
|
||||
}, {} as Record<string, number>),
|
||||
width: widthRef.current,
|
||||
} as Record<string, number>;
|
||||
}
|
||||
return sizes;
|
||||
}, []);
|
||||
|
||||
const onColumnResized = useCallback(
|
||||
(event: ColumnResizedEvent) => {
|
||||
parentOnColumnResized?.(event);
|
||||
if (
|
||||
storeKey &&
|
||||
event.source === 'uiColumnDragged' &&
|
||||
event.finished &&
|
||||
widthRef.current
|
||||
) {
|
||||
const { columns } = event;
|
||||
if (columns?.length) {
|
||||
const sizesObj = columns.reduce((aggr, column) => {
|
||||
aggr[column.getColId()] = column.getActualWidth();
|
||||
return aggr;
|
||||
}, {} as Record<string, number>);
|
||||
sizesObj['clientWidth'] = widthRef.current;
|
||||
valueSetter(storeKey, sizesObj);
|
||||
}
|
||||
}
|
||||
},
|
||||
[valueSetter, storeKey, parentOnColumnResized]
|
||||
);
|
||||
|
||||
const setSizes = useCallback(
|
||||
(apiEvent: GridReadyEvent | GridSizeChangedEvent) => {
|
||||
if (!storeKey || !Object.keys(sizes).length || !widthRef.current) {
|
||||
apiEvent.api.sizeColumnsToFit();
|
||||
} else {
|
||||
const recalculatedSizes = recalculateSizes(sizes);
|
||||
const newSizes = Object.entries(recalculatedSizes).map(
|
||||
([key, size]) => ({
|
||||
key,
|
||||
newWidth: size,
|
||||
})
|
||||
);
|
||||
apiEvent.columnApi.setColumnWidths(newSizes);
|
||||
}
|
||||
},
|
||||
[storeKey, recalculateSizes, sizes]
|
||||
);
|
||||
|
||||
const onGridReady = useCallback(
|
||||
(event: GridReadyEvent) => {
|
||||
parentOnGridReady?.(event);
|
||||
setSizes(event);
|
||||
},
|
||||
[setSizes, parentOnGridReady]
|
||||
);
|
||||
|
||||
const onGridSizeChanged = useCallback(
|
||||
(event: GridSizeChangedEvent) => {
|
||||
parentOnGridSizeChanged?.(event);
|
||||
widthRef.current = event.clientWidth;
|
||||
setSizes(event);
|
||||
},
|
||||
[parentOnGridSizeChanged, setSizes]
|
||||
);
|
||||
if (storeKey) {
|
||||
return {
|
||||
onGridReady,
|
||||
onGridSizeChanged,
|
||||
onColumnResized,
|
||||
};
|
||||
}
|
||||
return {
|
||||
onGridReady: parentOnGridReady,
|
||||
onGridSizeChanged: parentOnGridSizeChanged,
|
||||
onColumnResized: parentOnColumnResized,
|
||||
};
|
||||
};
|
||||
@@ -1 +1,4 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import ResizeObserver from 'resize-observer-polyfill';
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
||||
@@ -26,9 +26,10 @@ export const DepositsTable = forwardRef<
|
||||
<AgGrid
|
||||
ref={ref}
|
||||
overlayNoRowsTemplate={t('No deposits')}
|
||||
defaultColDef={{ flex: 1, resizable: true }}
|
||||
defaultColDef={{ resizable: true }}
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
suppressCellFocus={true}
|
||||
storeKey="depositTable"
|
||||
{...props}
|
||||
>
|
||||
<AgGridColumn headerName="Asset" field="asset.symbol" />
|
||||
@@ -80,6 +81,7 @@ export const DepositsTable = forwardRef<
|
||||
</EtherscanLink>
|
||||
);
|
||||
}}
|
||||
flex={1}
|
||||
/>
|
||||
</AgGrid>
|
||||
);
|
||||
|
||||
@@ -6,9 +6,11 @@ import { FillsManager } from './fills-manager';
|
||||
export const FillsContainer = ({
|
||||
marketId,
|
||||
onMarketClick,
|
||||
storeKey,
|
||||
}: {
|
||||
marketId?: string;
|
||||
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
storeKey?: string;
|
||||
}) => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
@@ -25,6 +27,7 @@ export const FillsContainer = ({
|
||||
partyId={pubKey}
|
||||
marketId={marketId}
|
||||
onMarketClick={onMarketClick}
|
||||
storeKey={storeKey}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -12,12 +12,14 @@ interface FillsManagerProps {
|
||||
partyId: string;
|
||||
marketId?: string;
|
||||
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
storeKey?: string;
|
||||
}
|
||||
|
||||
export const FillsManager = ({
|
||||
partyId,
|
||||
marketId,
|
||||
onMarketClick,
|
||||
storeKey,
|
||||
}: FillsManagerProps) => {
|
||||
const gridRef = useRef<AgGridReact | null>(null);
|
||||
const scrolledToTop = useRef(true);
|
||||
@@ -83,6 +85,7 @@ export const FillsManager = ({
|
||||
fullWidthCellRenderer={fullWidthCellRenderer}
|
||||
rowClassRules={rowClassRules}
|
||||
getRowHeight={getRowHeight}
|
||||
storeKey={storeKey}
|
||||
/>
|
||||
<div className="pointer-events-none absolute inset-0">
|
||||
<AsyncRenderer
|
||||
|
||||
@@ -34,6 +34,7 @@ export type Role = typeof TAKER | typeof MAKER | '-';
|
||||
export type Props = (AgGridReactProps | AgReactUiProps) & {
|
||||
partyId: string;
|
||||
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
storeKey?: string;
|
||||
};
|
||||
|
||||
export const FillsTable = forwardRef<AgGridReact, Props>(
|
||||
@@ -42,7 +43,7 @@ export const FillsTable = forwardRef<AgGridReact, Props>(
|
||||
<AgGrid
|
||||
ref={ref}
|
||||
overlayNoRowsTemplate={t('No fills')}
|
||||
defaultColDef={{ flex: 1, resizable: true }}
|
||||
defaultColDef={{ resizable: true }}
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
getRowId={({ data }) => data?.id}
|
||||
tooltipShowDelay={0}
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import ResizeObserver from 'resize-observer-polyfill';
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
||||
@@ -53,7 +53,6 @@ export const LedgerTable = forwardRef<AgGridReact, LedgerEntryProps>(
|
||||
ref={ref}
|
||||
tooltipShowDelay={500}
|
||||
defaultColDef={{
|
||||
flex: 1,
|
||||
resizable: true,
|
||||
sortable: true,
|
||||
tooltipComponent: TransferTooltipCellComponent,
|
||||
@@ -62,6 +61,7 @@ export const LedgerTable = forwardRef<AgGridReact, LedgerEntryProps>(
|
||||
buttons: ['reset'],
|
||||
},
|
||||
}}
|
||||
storeKey="ledgerTable"
|
||||
suppressLoadingOverlay
|
||||
suppressNoRowsOverlay
|
||||
{...props}
|
||||
@@ -203,6 +203,7 @@ export const LedgerTable = forwardRef<AgGridReact, LedgerEntryProps>(
|
||||
}
|
||||
filterParams={dateRangeFilterParams}
|
||||
filter={DateRangeFilter}
|
||||
flex={1}
|
||||
/>
|
||||
</AgGrid>
|
||||
);
|
||||
|
||||
@@ -59,12 +59,12 @@ export const LiquidityTable = forwardRef<AgGridReact, LiquidityTableProps>(
|
||||
ref={ref}
|
||||
tooltipShowDelay={500}
|
||||
defaultColDef={{
|
||||
flex: 1,
|
||||
resizable: true,
|
||||
minWidth: 100,
|
||||
tooltipComponent: TooltipCellComponent,
|
||||
sortable: true,
|
||||
}}
|
||||
storeKey="liquidityProvisionTable"
|
||||
{...props}
|
||||
>
|
||||
<AgGridColumn
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import ResizeObserver from 'resize-observer-polyfill';
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
||||
@@ -37,7 +37,6 @@ export const MarketListTable = forwardRef<
|
||||
getRowId={getRowId}
|
||||
ref={ref}
|
||||
defaultColDef={{
|
||||
flex: 1,
|
||||
resizable: true,
|
||||
sortable: true,
|
||||
filter: true,
|
||||
@@ -45,6 +44,7 @@ export const MarketListTable = forwardRef<
|
||||
}}
|
||||
suppressCellFocus
|
||||
components={{ PriceFlashCell, MarketNameCell }}
|
||||
storeKey="allMarkets"
|
||||
{...props}
|
||||
>
|
||||
<AgGridColumn
|
||||
@@ -198,7 +198,7 @@ export const MarketListTable = forwardRef<
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<AgGridColumn headerName={t('Market ID')} field="id" />
|
||||
<AgGridColumn headerName={t('Market ID')} field="id" flex={1} />
|
||||
</AgGrid>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface OrderListContainerProps {
|
||||
onOrderTypeClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
enforceBottomPlaceholder?: boolean;
|
||||
filter?: Filter;
|
||||
storeKey?: string;
|
||||
}
|
||||
|
||||
export const OrderListContainer = ({
|
||||
@@ -18,6 +19,7 @@ export const OrderListContainer = ({
|
||||
onOrderTypeClick,
|
||||
enforceBottomPlaceholder,
|
||||
filter,
|
||||
storeKey,
|
||||
}: OrderListContainerProps) => {
|
||||
const { pubKey, isReadOnly } = useVegaWallet();
|
||||
|
||||
@@ -34,6 +36,7 @@ export const OrderListContainer = ({
|
||||
onOrderTypeClick={onOrderTypeClick}
|
||||
isReadOnly={isReadOnly}
|
||||
enforceBottomPlaceholder={enforceBottomPlaceholder}
|
||||
storeKey={storeKey}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -45,6 +45,7 @@ export interface OrderListManagerProps {
|
||||
isReadOnly: boolean;
|
||||
enforceBottomPlaceholder?: boolean;
|
||||
filter?: Filter;
|
||||
storeKey?: string;
|
||||
}
|
||||
|
||||
const CancelAllOrdersButton = ({ onClick }: { onClick: () => void }) => (
|
||||
@@ -68,6 +69,7 @@ export const OrderListManager = ({
|
||||
isReadOnly,
|
||||
enforceBottomPlaceholder,
|
||||
filter,
|
||||
storeKey,
|
||||
}: OrderListManagerProps) => {
|
||||
const gridRef = useRef<AgGridReact | null>(null);
|
||||
const [hasData, setHasData] = useState(false);
|
||||
@@ -152,8 +154,10 @@ export const OrderListManager = ({
|
||||
onFilterChanged={onFilterChanged}
|
||||
isReadOnly={isReadOnly}
|
||||
blockLoadDebounceMillis={100}
|
||||
storeKey={storeKey}
|
||||
suppressLoadingOverlay
|
||||
suppressNoRowsOverlay
|
||||
suppressAutoSize
|
||||
{...bottomPlaceholderProps}
|
||||
/>
|
||||
<div className="pointer-events-none absolute inset-0">
|
||||
|
||||
@@ -8,6 +8,7 @@ import * as Schema from '@vegaprotocol/types';
|
||||
import { ButtonLink } from '@vegaprotocol/ui-toolkit';
|
||||
import { AgGridColumn } from 'ag-grid-react';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import type { ForwardedRef } from 'react';
|
||||
import { memo, forwardRef } from 'react';
|
||||
import {
|
||||
AgGridLazy as AgGrid,
|
||||
@@ -25,19 +26,22 @@ import type {
|
||||
} from '@vegaprotocol/datagrid';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
import type { Order } from '../order-data-provider';
|
||||
import * as React from 'react';
|
||||
|
||||
type OrderListProps = TypedDataAgGrid<Order> & { marketId?: string };
|
||||
|
||||
export type OrderListTableProps = OrderListProps & {
|
||||
export type OrderListTableProps = TypedDataAgGrid<Order> & {
|
||||
marketId?: string;
|
||||
cancel: (order: Order) => void;
|
||||
setEditOrder: (order: Order) => void;
|
||||
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
onOrderTypeClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
readonlyStatusFilter?: boolean;
|
||||
isReadOnly: boolean;
|
||||
storeKey?: string;
|
||||
};
|
||||
|
||||
export const OrderListTable = memo(
|
||||
export const OrderListTable = memo<
|
||||
OrderListTableProps & { ref?: ForwardedRef<AgGridReact> }
|
||||
>(
|
||||
forwardRef<AgGridReact, OrderListTableProps>(
|
||||
(
|
||||
{
|
||||
@@ -54,7 +58,6 @@ export const OrderListTable = memo(
|
||||
<AgGrid
|
||||
ref={ref}
|
||||
defaultColDef={{
|
||||
flex: 1,
|
||||
resizable: true,
|
||||
sortable: true,
|
||||
filterParams: { buttons: ['reset'] },
|
||||
@@ -163,7 +166,6 @@ export const OrderListTable = memo(
|
||||
valueFormatter={({
|
||||
data,
|
||||
value,
|
||||
node,
|
||||
}: VegaValueFormatterParams<Order, 'remaining'>) => {
|
||||
if (!data) {
|
||||
return undefined;
|
||||
@@ -189,7 +191,6 @@ export const OrderListTable = memo(
|
||||
valueFormatter={({
|
||||
value,
|
||||
data,
|
||||
node,
|
||||
}: VegaValueFormatterParams<Order, 'price'>) => {
|
||||
if (!data) {
|
||||
return undefined;
|
||||
@@ -240,7 +241,6 @@ export const OrderListTable = memo(
|
||||
field="createdAt"
|
||||
filter={DateRangeFilter}
|
||||
cellRenderer={({
|
||||
data,
|
||||
value,
|
||||
}: VegaICellRendererParams<Order, 'createdAt'>) => {
|
||||
return (
|
||||
@@ -291,6 +291,7 @@ export const OrderListTable = memo(
|
||||
) : null;
|
||||
}}
|
||||
sortable={false}
|
||||
flex={1}
|
||||
/>
|
||||
</AgGrid>
|
||||
);
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import ResizeObserver from 'resize-observer-polyfill';
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
||||
@@ -6,9 +6,11 @@ import { PositionsManager } from './positions-manager';
|
||||
export const PositionsContainer = ({
|
||||
onMarketClick,
|
||||
noBottomPlaceholder,
|
||||
storeKey,
|
||||
}: {
|
||||
onMarketClick?: (marketId: string) => void;
|
||||
noBottomPlaceholder?: boolean;
|
||||
storeKey?: string;
|
||||
}) => {
|
||||
const { pubKey, isReadOnly } = useVegaWallet();
|
||||
|
||||
@@ -25,6 +27,7 @@ export const PositionsContainer = ({
|
||||
onMarketClick={onMarketClick}
|
||||
isReadOnly={isReadOnly}
|
||||
noBottomPlaceholder={noBottomPlaceholder}
|
||||
storeKey={storeKey}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@ interface PositionsManagerProps {
|
||||
onMarketClick?: (marketId: string) => void;
|
||||
isReadOnly: boolean;
|
||||
noBottomPlaceholder?: boolean;
|
||||
storeKey?: string;
|
||||
}
|
||||
|
||||
export const PositionsManager = ({
|
||||
@@ -20,6 +21,7 @@ export const PositionsManager = ({
|
||||
onMarketClick,
|
||||
isReadOnly,
|
||||
noBottomPlaceholder,
|
||||
storeKey,
|
||||
}: PositionsManagerProps) => {
|
||||
const gridRef = useRef<AgGridReact | null>(null);
|
||||
const { data, error, loading, reload } = usePositionsData(partyId, gridRef);
|
||||
@@ -82,6 +84,7 @@ export const PositionsManager = ({
|
||||
onFilterChanged={updateRowCount}
|
||||
onRowDataUpdated={updateRowCount}
|
||||
{...bottomPlaceholderProps}
|
||||
storeKey={storeKey}
|
||||
/>
|
||||
<div className="pointer-events-none absolute inset-0">
|
||||
<AsyncRenderer
|
||||
|
||||
@@ -46,6 +46,7 @@ interface Props extends TypedDataAgGrid<Position> {
|
||||
onMarketClick?: (id: string, metaKey?: boolean) => void;
|
||||
style?: CSSProperties;
|
||||
isReadOnly: boolean;
|
||||
storeKey?: string;
|
||||
}
|
||||
|
||||
export interface AmountCellProps {
|
||||
@@ -89,7 +90,6 @@ export const PositionsTable = forwardRef<AgGridReact, Props>(
|
||||
ref={ref}
|
||||
tooltipShowDelay={500}
|
||||
defaultColDef={{
|
||||
flex: 1,
|
||||
resizable: true,
|
||||
sortable: true,
|
||||
filter: true,
|
||||
@@ -383,6 +383,7 @@ export const PositionsTable = forwardRef<AgGridReact, Props>(
|
||||
) : null
|
||||
}
|
||||
minWidth={80}
|
||||
flex={1}
|
||||
/>
|
||||
) : null}
|
||||
</AgGrid>
|
||||
|
||||
@@ -21,9 +21,6 @@ export const getNewMarketProposals = (data: ProposalListFieldsFragment[]) =>
|
||||
export const ProposalsList = () => {
|
||||
const gridRef = useRef<AgGridReact | null>(null);
|
||||
const [dataCount, setDataCount] = useState(0);
|
||||
const handleOnGridReady = useCallback(() => {
|
||||
gridRef.current?.api?.sizeColumnsToFit();
|
||||
}, [gridRef]);
|
||||
const { data, loading, error, reload } = useDataProvider({
|
||||
dataProvider: proposalsDataProvider,
|
||||
variables: {
|
||||
@@ -47,10 +44,10 @@ export const ProposalsList = () => {
|
||||
columnDefs={columnDefs}
|
||||
rowData={filteredData}
|
||||
defaultColDef={defaultColDef}
|
||||
onGridReady={handleOnGridReady}
|
||||
suppressLoadingOverlay
|
||||
suppressNoRowsOverlay
|
||||
onFilterChanged={onFilterChanged}
|
||||
storeKey="proposedMarkets"
|
||||
/>
|
||||
<div className="pointer-events-none absolute inset-0">
|
||||
<AsyncRenderer
|
||||
|
||||
@@ -132,6 +132,7 @@ export const useColumnDefs = () => {
|
||||
'terms.enactmentDatetime'
|
||||
>) => (value ? getDateTimeFormat().format(new Date(value)) : '-'),
|
||||
filter: DateRangeFilter,
|
||||
flex: 1,
|
||||
},
|
||||
];
|
||||
}, [VEGA_TOKEN_URL, requiredMajorityPercentage]);
|
||||
@@ -139,7 +140,6 @@ export const useColumnDefs = () => {
|
||||
return {
|
||||
sortable: true,
|
||||
cellClass: cellCss,
|
||||
flex: 1,
|
||||
resizable: true,
|
||||
filter: true,
|
||||
filterParams: { buttons: ['reset'] },
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import ResizeObserver from 'resize-observer-polyfill';
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import ResizeObserver from 'resize-observer-polyfill';
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
||||
@@ -33,7 +33,7 @@ export const WithdrawalsTable = (
|
||||
return (
|
||||
<AgGrid
|
||||
overlayNoRowsTemplate={t('No withdrawals')}
|
||||
defaultColDef={{ flex: 1, resizable: true }}
|
||||
defaultColDef={{ resizable: true }}
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
components={{
|
||||
RecipientCell,
|
||||
@@ -43,6 +43,7 @@ export const WithdrawalsTable = (
|
||||
}}
|
||||
suppressCellFocus
|
||||
ref={gridRef}
|
||||
storeKey="withdrawals"
|
||||
{...bottomPlaceholderProps}
|
||||
{...props}
|
||||
>
|
||||
|
||||
@@ -1 +1,4 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import ResizeObserver from 'resize-observer-polyfill';
|
||||
|
||||
global.ResizeObserver = ResizeObserver;
|
||||
|
||||
Reference in New Issue
Block a user