diff --git a/src/components/molecules/AssetListTitle.tsx b/src/components/molecules/AssetListTitle.tsx index 3eec652ed..935c7e0d4 100644 --- a/src/components/molecules/AssetListTitle.tsx +++ b/src/components/molecules/AssetListTitle.tsx @@ -2,7 +2,7 @@ import { DDO } from '@oceanprotocol/lib' import { useOcean } from '@oceanprotocol/react' import { Link } from 'gatsby' import React, { ReactElement, useEffect, useState } from 'react' -import { retrieveDDO } from '../../utils/aquarius' +import { retrieveDDO, getAssetsNames } from '../../utils/aquarius' import styles from './AssetListTitle.module.css' import axios from 'axios' @@ -28,15 +28,15 @@ export default function AssetListTitle({ const source = axios.CancelToken.source() - async function getDDO() { - const ddo = await retrieveDDO(did, config.metadataCacheUri, source.token) - - if (!ddo) return - const { attributes } = ddo.findServiceByType('metadata') - setAssetTitle(attributes.main.name) + async function getAssetName() { + getAssetsNames([did], config.metadataCacheUri, source.token).then( + (resp) => { + setAssetTitle(resp[did]) + } + ) } - !ddo && did && getDDO() + !ddo && did && getAssetName() return () => { console.log('canceled?') diff --git a/src/utils/aquarius.ts b/src/utils/aquarius.ts index a11657a7e..0e88a7949 100644 --- a/src/utils/aquarius.ts +++ b/src/utils/aquarius.ts @@ -73,3 +73,27 @@ export async function retrieveDDO( } } } + +export async function getAssetsNames( + didList: string[] | DID[], + metadataCacheUri: string, + cancelToken: CancelToken +): Promise> { + try { + const response: AxiosResponse> = await axios.post( + `${metadataCacheUri}/api/v1/aquarius/assets/names`, + { + didList, + cancelToken + } + ) + if (!response || response.status !== 200 || !response.data) return + return response.data + } catch (error) { + if (axios.isCancel(error)) { + Logger.log(error.message) + } else { + Logger.error(error.message) + } + } +}