Skip to content

Commit

Permalink
Improve load time
Browse files Browse the repository at this point in the history
  • Loading branch information
sophialittlejohn committed Oct 23, 2023
1 parent f445227 commit 176bbd0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
14 changes: 4 additions & 10 deletions centrifuge-app/src/utils/usePools.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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,
}
Expand Down
21 changes: 9 additions & 12 deletions centrifuge-js/src/modules/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] }
Expand Down Expand Up @@ -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 {
Expand All @@ -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) ?? [],
}))
})
)
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 176bbd0

Please sign in to comment.