From ef70d97ad3fb84573f1c63ca1305a1d4441d9646 Mon Sep 17 00:00:00 2001 From: Norbi <37236152+KatunaNorbert@users.noreply.github.com> Date: Mon, 11 Oct 2021 14:55:23 +0300 Subject: [PATCH] Improve Pool Transactions page data fetching (#902) * use elastic search to get all ddo's at once * fix get ddo's list function and get names in one query * reorder ddo list based on did list order * remove inPurgatory filter * fix broken aquarius query * remove getAssetsFromDidList function and use retrieveDDOListByDIDs * fetch list of ddos * use RegExp * fix broken query on empty did or chainId list --- .../molecules/PoolTransactions/index.tsx | 24 ++++++++++++------- src/utils/aquarius.ts | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/components/molecules/PoolTransactions/index.tsx b/src/components/molecules/PoolTransactions/index.tsx index 2ba87f53f..19068d829 100644 --- a/src/components/molecules/PoolTransactions/index.tsx +++ b/src/components/molecules/PoolTransactions/index.tsx @@ -9,7 +9,7 @@ import web3 from 'web3' import { fetchDataForMultipleChains } from '../../../utils/subgraph' import { useSiteMetadata } from '../../../hooks/useSiteMetadata' import NetworkName from '../../atoms/NetworkName' -import { retrieveDDO } from '../../../utils/aquarius' +import { retrieveDDOListByDIDs } from '../../../utils/aquarius' import axios, { CancelToken } from 'axios' import Title from './Title' import styles from './index.module.css' @@ -164,19 +164,27 @@ export default function PoolTransactions({ if (!data) return const poolTransactions: PoolTransaction[] = [] + const didList: string[] = [] for (let i = 0; i < data.length; i++) { const { datatokenAddress } = data[i].poolAddress const did = web3.utils .toChecksumAddress(datatokenAddress) .replace('0x', 'did:op:') - const ddo = await retrieveDDO(did, cancelToken) - ddo && - poolTransactions.push({ - ...data[i], - networkId: ddo?.chainId, - ddo - }) + didList.push(did) + } + if (didList.length === 0) return + const ddoList = await retrieveDDOListByDIDs( + didList, + chainIds, + cancelToken + ) + for (let i = 0; i < data.length; i++) { + poolTransactions.push({ + ...data[i], + networkId: ddoList[i]?.chainId, + ddo: ddoList[i] + }) } const sortedTransactions = poolTransactions.sort( (a, b) => b.timestamp - a.timestamp diff --git a/src/utils/aquarius.ts b/src/utils/aquarius.ts index c2b739be6..af5c3cc3d 100644 --- a/src/utils/aquarius.ts +++ b/src/utils/aquarius.ts @@ -243,6 +243,7 @@ export async function retrieveDDOListByDIDs( cancelToken: CancelToken ): Promise { try { + if (didList?.length === 0 || chainIds?.length === 0) return [] const orderedDDOListByDIDList: DDO[] = [] const query = { size: didList.length,