chore: fix positions data provider restarts (#1509)
This commit is contained in:
parent
e310f04034
commit
414b8ced13
@ -17,11 +17,11 @@ const getRowId = ({ data }: { data: Position }) => data.marketId;
|
|||||||
|
|
||||||
const PositionsAsset = ({ partyId, assetSymbol }: Props) => {
|
const PositionsAsset = ({ partyId, assetSymbol }: Props) => {
|
||||||
const gridRef = useRef<AgGridReact | null>(null);
|
const gridRef = useRef<AgGridReact | null>(null);
|
||||||
const { data, error, loading, getRows } = usePositionsData({
|
const { data, error, loading, getRows } = usePositionsData(
|
||||||
partyId,
|
partyId,
|
||||||
assetSymbol,
|
|
||||||
gridRef,
|
gridRef,
|
||||||
});
|
assetSymbol
|
||||||
|
);
|
||||||
const { columnDefs, defaultColDef } = useColumnDefinitions();
|
const { columnDefs, defaultColDef } = useColumnDefinitions();
|
||||||
return (
|
return (
|
||||||
<AsyncRenderer loading={loading} error={error} data={data}>
|
<AsyncRenderer loading={loading} error={error} data={data}>
|
||||||
|
@ -6,9 +6,7 @@ import PositionsAsset from './positions-asset';
|
|||||||
|
|
||||||
const Positions = () => {
|
const Positions = () => {
|
||||||
const { partyId } = useOutletContext<{ partyId: string }>();
|
const { partyId } = useOutletContext<{ partyId: string }>();
|
||||||
const { data, error, loading, assetSymbols } = usePositionsAssets({
|
const { data, error, loading, assetSymbols } = usePositionsAssets(partyId);
|
||||||
partyId,
|
|
||||||
});
|
|
||||||
return (
|
return (
|
||||||
<AsyncRenderer loading={loading} error={error} data={data}>
|
<AsyncRenderer loading={loading} error={error} data={data}>
|
||||||
{assetSymbols && assetSymbols.length > 0 && (
|
{assetSymbols && assetSymbols.length > 0 && (
|
||||||
|
@ -160,7 +160,7 @@ export const SelectMarketPopover = ({
|
|||||||
PositionsSubscription_positions[]
|
PositionsSubscription_positions[]
|
||||||
>({
|
>({
|
||||||
dataProvider: positionsDataProvider,
|
dataProvider: positionsDataProvider,
|
||||||
update: () => false,
|
noUpdate: true,
|
||||||
variables,
|
variables,
|
||||||
skip: !keypair,
|
skip: !keypair,
|
||||||
});
|
});
|
||||||
|
@ -17,10 +17,7 @@ export const PositionsManager = ({ partyId }: PositionsManagerProps) => {
|
|||||||
[submit]
|
[submit]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data, error, loading, assetSymbols } = usePositionsAssets({
|
const { data, error, loading, assetSymbols } = usePositionsAssets(partyId);
|
||||||
partyId,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<AsyncRenderer loading={loading} error={error} data={data}>
|
<AsyncRenderer loading={loading} error={error} data={data}>
|
||||||
|
@ -16,11 +16,11 @@ interface PositionsProps {
|
|||||||
export const Positions = memo(
|
export const Positions = memo(
|
||||||
({ partyId, assetSymbol, onClose }: PositionsProps) => {
|
({ partyId, assetSymbol, onClose }: PositionsProps) => {
|
||||||
const gridRef = useRef<AgGridReact | null>(null);
|
const gridRef = useRef<AgGridReact | null>(null);
|
||||||
const { data, error, loading, getRows } = usePositionsData({
|
const { data, error, loading, getRows } = usePositionsData(
|
||||||
partyId,
|
partyId,
|
||||||
assetSymbol,
|
|
||||||
gridRef,
|
gridRef,
|
||||||
});
|
assetSymbol
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AsyncRenderer loading={loading} error={error} data={data}>
|
<AsyncRenderer loading={loading} error={error} data={data}>
|
||||||
|
@ -3,14 +3,10 @@ import { useDataProvider } from '@vegaprotocol/react-helpers';
|
|||||||
import type { Position } from './positions-data-providers';
|
import type { Position } from './positions-data-providers';
|
||||||
import { positionsMetricsDataProvider as dataProvider } from './positions-data-providers';
|
import { positionsMetricsDataProvider as dataProvider } from './positions-data-providers';
|
||||||
|
|
||||||
interface Props {
|
|
||||||
partyId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getSymbols = (positions: Position[]) =>
|
const getSymbols = (positions: Position[]) =>
|
||||||
Array.from(new Set(positions.map((position) => position.assetSymbol))).sort();
|
Array.from(new Set(positions.map((position) => position.assetSymbol))).sort();
|
||||||
|
|
||||||
export const usePositionsAssets = ({ partyId }: Props) => {
|
export const usePositionsAssets = (partyId: string) => {
|
||||||
const variables = useMemo(() => ({ partyId }), [partyId]);
|
const variables = useMemo(() => ({ partyId }), [partyId]);
|
||||||
const assetSymbols = useRef<string[] | undefined>();
|
const assetSymbols = useRef<string[] | undefined>();
|
||||||
const update = useCallback(({ data }: { data: Position[] | null }) => {
|
const update = useCallback(({ data }: { data: Position[] | null }) => {
|
||||||
|
@ -8,12 +8,6 @@ import { positionsMetricsDataProvider as dataProvider } from './positions-data-p
|
|||||||
import filter from 'lodash/filter';
|
import filter from 'lodash/filter';
|
||||||
import { t, toBigNum, useDataProvider } from '@vegaprotocol/react-helpers';
|
import { t, toBigNum, useDataProvider } from '@vegaprotocol/react-helpers';
|
||||||
|
|
||||||
interface Props {
|
|
||||||
partyId: string;
|
|
||||||
assetSymbol?: string;
|
|
||||||
gridRef: RefObject<AgGridReact>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getSummaryRow = (positions: Position[]) => {
|
const getSummaryRow = (positions: Position[]) => {
|
||||||
const summaryRow = {
|
const summaryRow = {
|
||||||
notional: new BigNumber(0),
|
notional: new BigNumber(0),
|
||||||
@ -41,7 +35,11 @@ const getSummaryRow = (positions: Position[]) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const usePositionsData = ({ partyId, assetSymbol, gridRef }: Props) => {
|
export const usePositionsData = (
|
||||||
|
partyId: string,
|
||||||
|
gridRef: RefObject<AgGridReact>,
|
||||||
|
assetSymbol?: string
|
||||||
|
) => {
|
||||||
const variables = useMemo(() => ({ partyId }), [partyId]);
|
const variables = useMemo(() => ({ partyId }), [partyId]);
|
||||||
const dataRef = useRef<Position[] | null>(null);
|
const dataRef = useRef<Position[] | null>(null);
|
||||||
const update = useCallback(
|
const update = useCallback(
|
||||||
@ -61,11 +59,8 @@ export const usePositionsData = ({ partyId, assetSymbol, gridRef }: Props) => {
|
|||||||
variables,
|
variables,
|
||||||
});
|
});
|
||||||
dataRef.current = assetSymbol ? filter(data, { assetSymbol }) : data;
|
dataRef.current = assetSymbol ? filter(data, { assetSymbol }) : data;
|
||||||
const getRows = async ({
|
const getRows = useCallback(
|
||||||
successCallback,
|
async ({ successCallback, startRow, endRow }: GetRowsParams) => {
|
||||||
startRow,
|
|
||||||
endRow,
|
|
||||||
}: GetRowsParams) => {
|
|
||||||
const rowsThisBlock = dataRef.current
|
const rowsThisBlock = dataRef.current
|
||||||
? dataRef.current.slice(startRow, endRow)
|
? dataRef.current.slice(startRow, endRow)
|
||||||
: [];
|
: [];
|
||||||
@ -76,7 +71,9 @@ export const usePositionsData = ({ partyId, assetSymbol, gridRef }: Props) => {
|
|||||||
getSummaryRow(rowsThisBlock),
|
getSummaryRow(rowsThisBlock),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
[gridRef]
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
data,
|
data,
|
||||||
error,
|
error,
|
||||||
|
Loading…
Reference in New Issue
Block a user