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[],
|
accountList: Account[],
|
||||||
assetId: string
|
assetId: string
|
||||||
): AccountFields => {
|
): AccountFields => {
|
||||||
console.log(accountList);
|
|
||||||
const accounts = accountList.filter((a) => a.asset.id === assetId);
|
const accounts = accountList.filter((a) => a.asset.id === assetId);
|
||||||
const available = getTotalBalance(
|
const available = getTotalBalance(
|
||||||
accounts.filter((a) => a.type === AccountType.ACCOUNT_TYPE_GENERAL)
|
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 { useCallback, useMemo, useRef } from 'react';
|
||||||
import type { RefObject } from 'react';
|
import type { RefObject } from 'react';
|
||||||
import { BigNumber } from 'bignumber.js';
|
import { BigNumber } from 'bignumber.js';
|
||||||
@ -9,7 +8,7 @@ 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';
|
||||||
|
|
||||||
const getSummaryRow = (positions: Position[]) => {
|
const getSummaryRowData = (positions: Position[]) => {
|
||||||
const summaryRow = {
|
const summaryRow = {
|
||||||
notional: new BigNumber(0),
|
notional: new BigNumber(0),
|
||||||
realisedPNL: BigInt(0),
|
realisedPNL: BigInt(0),
|
||||||
@ -42,7 +41,6 @@ export const usePositionsData = (
|
|||||||
assetSymbol?: string
|
assetSymbol?: string
|
||||||
) => {
|
) => {
|
||||||
const variables = useMemo(() => ({ partyId }), [partyId]);
|
const variables = useMemo(() => ({ partyId }), [partyId]);
|
||||||
const summaryRow = useRef<ReturnType<typeof getSummaryRow>>();
|
|
||||||
const dataRef = useRef<Position[] | null>(null);
|
const dataRef = useRef<Position[] | null>(null);
|
||||||
const update = useCallback(
|
const update = useCallback(
|
||||||
({ data }: { data: Position[] | null }) => {
|
({ data }: { data: Position[] | null }) => {
|
||||||
@ -68,10 +66,17 @@ export const usePositionsData = (
|
|||||||
const lastRow = dataRef.current?.length ?? -1;
|
const lastRow = dataRef.current?.length ?? -1;
|
||||||
successCallback(rowsThisBlock, lastRow);
|
successCallback(rowsThisBlock, lastRow);
|
||||||
if (gridRef.current?.api) {
|
if (gridRef.current?.api) {
|
||||||
const updatedSummaryRow = getSummaryRow(rowsThisBlock);
|
const summaryRowNode = gridRef.current.api.getPinnedBottomRow(0);
|
||||||
if (!isEqual(updatedSummaryRow, summaryRow.current)) {
|
if (summaryRowNode && dataRef.current) {
|
||||||
summaryRow.current = updatedSummaryRow;
|
summaryRowNode.data = getSummaryRowData(dataRef.current);
|
||||||
gridRef.current.api.setPinnedBottomRowData([updatedSummaryRow]);
|
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