fix: order positions by market name instead of updatedAt (#1902)

This commit is contained in:
Bartłomiej Głownia 2022-10-28 17:14:29 +02:00 committed by GitHub
parent f5ea0563b3
commit 13a77d1583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -234,7 +234,7 @@ export const positionsDataProvider = makeDataProvider<
subscriptionData.positions,
});
const upgradeMarginsConection = (
const upgradeMarginsConnection = (
marketId: string,
margins: MarginsQuery['party'] | null
) => {
@ -270,7 +270,7 @@ export const rejoinPositionData = (
updatedAt: node.updatedAt,
market:
marketsData?.find((market) => market.id === node.market.id) || null,
margins: upgradeMarginsConection(node.market.id, margins),
margins: upgradeMarginsConnection(node.market.id, margins),
};
});
}
@ -291,7 +291,7 @@ export const positionsMetricsDataProvider = makeDerivedDataProvider<
const positionsData = rejoinPositionData(positions, marketsData, margins);
return sortBy(
getMetrics(positionsData, accounts as Account[] | null),
'updatedAt'
).reverse();
'marketName'
);
}
);

View File

@ -1,3 +1,4 @@
import isEqual from 'lodash/isEqual';
import { useCallback, useMemo, useRef } from 'react';
import type { RefObject } from 'react';
import { BigNumber } from 'bignumber.js';
@ -41,6 +42,7 @@ export const usePositionsData = (
assetSymbol?: string
) => {
const variables = useMemo(() => ({ partyId }), [partyId]);
const summaryRow = useRef<ReturnType<typeof getSummaryRow>>();
const dataRef = useRef<Position[] | null>(null);
const update = useCallback(
({ data }: { data: Position[] | null }) => {
@ -66,9 +68,11 @@ export const usePositionsData = (
const lastRow = dataRef.current?.length ?? -1;
successCallback(rowsThisBlock, lastRow);
if (gridRef.current?.api) {
gridRef.current.api.setPinnedBottomRowData([
getSummaryRow(rowsThisBlock),
]);
const updatedSummaryRow = getSummaryRow(rowsThisBlock);
if (!isEqual(updatedSummaryRow, summaryRow.current)) {
summaryRow.current = updatedSummaryRow;
gridRef.current.api.setPinnedBottomRowData([updatedSummaryRow]);
}
}
},
[gridRef]