mirror of
https://github.com/oceanprotocol/market.git
synced 2024-11-15 01:34:57 +01:00
Merge pull request #409 from oceanprotocol/feature/optimize-did-fetching-in-tables
optimize did fetching in tables
This commit is contained in:
commit
5c4c13452f
@ -2,7 +2,7 @@ import { DDO } from '@oceanprotocol/lib'
|
|||||||
import { useOcean } from '@oceanprotocol/react'
|
import { useOcean } from '@oceanprotocol/react'
|
||||||
import { Link } from 'gatsby'
|
import { Link } from 'gatsby'
|
||||||
import React, { ReactElement, useEffect, useState } from 'react'
|
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 styles from './AssetListTitle.module.css'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
@ -28,15 +28,16 @@ export default function AssetListTitle({
|
|||||||
|
|
||||||
const source = axios.CancelToken.source()
|
const source = axios.CancelToken.source()
|
||||||
|
|
||||||
async function getDDO() {
|
async function getAssetName() {
|
||||||
const ddo = await retrieveDDO(did, config.metadataCacheUri, source.token)
|
const title = await getAssetsNames(
|
||||||
|
[did],
|
||||||
if (!ddo) return
|
config.metadataCacheUri,
|
||||||
const { attributes } = ddo.findServiceByType('metadata')
|
source.token
|
||||||
setAssetTitle(attributes.main.name)
|
)
|
||||||
|
setAssetTitle(title[did])
|
||||||
}
|
}
|
||||||
|
|
||||||
!ddo && did && getDDO()
|
!ddo && did && getAssetName()
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
console.log('canceled?')
|
console.log('canceled?')
|
||||||
|
@ -73,3 +73,27 @@ export async function retrieveDDO(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getAssetsNames(
|
||||||
|
didList: string[] | DID[],
|
||||||
|
metadataCacheUri: string,
|
||||||
|
cancelToken: CancelToken
|
||||||
|
): Promise<Record<string, string>> {
|
||||||
|
try {
|
||||||
|
const response: AxiosResponse<Record<string, string>> = 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user