fix: change way how summary row is updated to avoid rerender (#1910)
This commit is contained in:
parent
9a20721970
commit
1862ebbc6c
@ -130,7 +130,6 @@ const getAssetAccountAggregation = (
|
||||
accountList: Account[],
|
||||
assetId: string
|
||||
): AccountFields => {
|
||||
console.log(accountList);
|
||||
const accounts = accountList.filter((a) => a.asset.id === assetId);
|
||||
const available = getTotalBalance(
|
||||
accounts.filter((a) => a.type === AccountType.ACCOUNT_TYPE_GENERAL)
|
||||
|
@ -1,4 +1,3 @@
|
||||
import isEqual from 'lodash/isEqual';
|
||||
import { useCallback, useMemo, useRef } from 'react';
|
||||
import type { RefObject } from 'react';
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
@ -9,7 +8,7 @@ import { positionsMetricsDataProvider as dataProvider } from './positions-data-p
|
||||
import filter from 'lodash/filter';
|
||||
import { t, toBigNum, useDataProvider } from '@vegaprotocol/react-helpers';
|
||||
|
||||
const getSummaryRow = (positions: Position[]) => {
|
||||
const getSummaryRowData = (positions: Position[]) => {
|
||||
const summaryRow = {
|
||||
notional: new BigNumber(0),
|
||||
realisedPNL: BigInt(0),
|
||||
@ -42,7 +41,6 @@ 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 }) => {
|
||||
@ -68,10 +66,17 @@ export const usePositionsData = (
|
||||
const lastRow = dataRef.current?.length ?? -1;
|
||||
successCallback(rowsThisBlock, lastRow);
|
||||
if (gridRef.current?.api) {
|
||||
const updatedSummaryRow = getSummaryRow(rowsThisBlock);
|
||||
if (!isEqual(updatedSummaryRow, summaryRow.current)) {
|
||||
summaryRow.current = updatedSummaryRow;
|
||||
gridRef.current.api.setPinnedBottomRowData([updatedSummaryRow]);
|
||||
const summaryRowNode = gridRef.current.api.getPinnedBottomRow(0);
|
||||
if (summaryRowNode && dataRef.current) {
|
||||
summaryRowNode.data = getSummaryRowData(dataRef.current);
|
||||
gridRef.current.api.refreshCells({
|
||||
force: true,
|
||||
rowNodes: [summaryRowNode],
|
||||
});
|
||||
} else {
|
||||
gridRef.current.api.setPinnedBottomRowData(
|
||||
dataRef.current ? [getSummaryRowData(dataRef.current)] : []
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user