From 1862ebbc6c547092f5fc622235967e459f572f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Mon, 31 Oct 2022 21:57:26 +0100 Subject: [PATCH] fix: change way how summary row is updated to avoid rerender (#1910) --- .../src/lib/accounts-data-provider.ts | 1 - libs/positions/src/lib/use-positions-data.tsx | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libs/accounts/src/lib/accounts-data-provider.ts b/libs/accounts/src/lib/accounts-data-provider.ts index ab3fbf7f9..792ef411c 100644 --- a/libs/accounts/src/lib/accounts-data-provider.ts +++ b/libs/accounts/src/lib/accounts-data-provider.ts @@ -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) diff --git a/libs/positions/src/lib/use-positions-data.tsx b/libs/positions/src/lib/use-positions-data.tsx index 28d76312b..3f6b6496b 100644 --- a/libs/positions/src/lib/use-positions-data.tsx +++ b/libs/positions/src/lib/use-positions-data.tsx @@ -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>(); const dataRef = useRef(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)] : [] + ); } } },