From 176bbd0ebd8650dffae320d79629c1d703f66d72 Mon Sep 17 00:00:00 2001 From: sophian Date: Mon, 23 Oct 2023 17:57:41 -0400 Subject: [PATCH] Improve load time --- centrifuge-app/src/utils/usePools.ts | 14 ++++---------- centrifuge-js/src/modules/pools.ts | 21 +++++++++------------ 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/centrifuge-app/src/utils/usePools.ts b/centrifuge-app/src/utils/usePools.ts index 6fef787ab1..21e33a2fef 100644 --- a/centrifuge-app/src/utils/usePools.ts +++ b/centrifuge-app/src/utils/usePools.ts @@ -1,10 +1,4 @@ -import Centrifuge, { - BorrowerTransaction, - InvestorTransactionType, - Loan, - Pool, - PoolMetadata, -} from '@centrifuge/centrifuge-js' +import Centrifuge, { BorrowerTransaction, Loan, Pool, PoolMetadata } from '@centrifuge/centrifuge-js' import { useCentrifugeConsts, useCentrifugeQuery, useWallet } from '@centrifuge/centrifuge-react' import BN from 'bn.js' import { useEffect, useMemo } from 'react' @@ -58,10 +52,10 @@ export function useMonthlyPoolStates(poolId: string, from?: Date, to?: Date) { return result } -export function useTransactionsByAddress(address?: string, count?: number, txTypes?: InvestorTransactionType[]) { +export function useTransactionsByAddress(address?: string) { const [result] = useCentrifugeQuery( - ['txByAddress', count, address, txTypes], - (cent) => cent.pools.getTransactionsByAddress([address!, count, txTypes]), + ['txByAddress', address], + (cent) => cent.pools.getTransactionsByAddress([address!]), { enabled: !!address, } diff --git a/centrifuge-js/src/modules/pools.ts b/centrifuge-js/src/modules/pools.ts index 8b454e7a4f..8a277054c1 100644 --- a/centrifuge-js/src/modules/pools.ts +++ b/centrifuge-js/src/modules/pools.ts @@ -2004,7 +2004,7 @@ export function getPoolsModule(inst: Centrifuge) { } function getTransactionsByAddress(args: [address: string, count?: number, txTypes?: InvestorTransactionType[]]) { - const [address, count, txTypes] = args + const [address] = args const $query = inst.getSubqueryObservable<{ investorTransactions: { nodes: SubqueryInvestorTransaction[] } @@ -2036,9 +2036,9 @@ export function getPoolsModule(inst: Centrifuge) { switchMap((data) => { const poolIds = new Set(data?.investorTransactions.nodes.map((e) => e.poolId)) ?? [] const $poolCurrencies = Array.from(poolIds).map((poolId) => getPoolCurrency([poolId])) - return combineLatest([$query, ...$poolCurrencies]).pipe( - map(([data, ...currencies]) => { - return data?.investorTransactions.nodes.map((tx) => { + return combineLatest($poolCurrencies).pipe( + map((currencies) => { + const txs = data?.investorTransactions.nodes.map((tx) => { const currencyIndex = Array.from(poolIds).indexOf(tx.poolId) const poolCurrency = currencies[currencyIndex] return { @@ -2049,15 +2049,12 @@ export function getPoolsModule(inst: Centrifuge) { trancheId: tx.trancheId.split('-')[1], } }) + return { + investorTransactions: txs || [], + } }) ) - }), - map((investorTransactions) => ({ - investorTransactions: - investorTransactions - ?.filter((tx) => (txTypes ? txTypes?.includes(tx.type) : tx)) - .slice(0, count || investorTransactions.length) ?? [], - })) + }) ) } @@ -2808,7 +2805,7 @@ export function getPoolsModule(inst: Centrifuge) { const update = updateData.toPrimitive() as any if (!update?.changes) return null const { changes, submittedAt } = update - + return { changes: { tranches: changes.tranches.noChange === null ? null : changes.tranches.newValue,