1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

bookmark fixes (#1127)

This commit is contained in:
Matthias Kretschmann 2022-02-18 11:46:34 +00:00 committed by GitHub
parent c038570cdd
commit 3a424bc44c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 32 deletions

View File

@ -334,12 +334,12 @@ export async function getAccessDetailsForAssets(
for (const asset of assets) {
if (chainAssetLists[asset.chainId]) {
chainAssetLists[asset.chainId].push(
asset?.services[0].datatokenAddress.toLowerCase()
asset.services[0].datatokenAddress.toLowerCase()
)
} else {
chainAssetLists[asset.chainId] = []
chainAssetLists[asset.chainId].push(
asset?.services[0].datatokenAddress.toLowerCase()
asset.services[0].datatokenAddress.toLowerCase()
)
}
}

View File

@ -180,8 +180,9 @@ export async function retrieveDDOListByDIDs(
chainIds: number[],
cancelToken: CancelToken
): Promise<Asset[]> {
try {
if (didList?.length === 0 || chainIds?.length === 0) return []
try {
const orderedDDOListByDIDList: Asset[] = []
const baseQueryparams = {
chainIds,
@ -190,9 +191,10 @@ export async function retrieveDDOListByDIDs(
} as BaseQueryParams
const query = generateBaseQuery(baseQueryparams)
const result = await queryMetadata(query, cancelToken)
didList.forEach((did: string) => {
const ddo = result.results.find((ddo: Asset) => ddo.id === did)
orderedDDOListByDIDList.push(ddo)
if (ddo) orderedDDOListByDIDList.push(ddo)
})
return orderedDDOListByDIDList
} catch (error) {

View File

@ -1,12 +1,11 @@
import { useUserPreferences } from '@context/UserPreferences'
import React, { ReactElement, useEffect, useState, useCallback } from 'react'
import React, { ReactElement, useEffect, useState } from 'react'
import Table from '@shared/atoms/Table'
import { LoggerInstance } from '@oceanprotocol/lib'
import Price from '@shared/Price'
import Tooltip from '@shared/atoms/Tooltip'
import AssetTitle from '@shared/AssetList/AssetListTitle'
import { retrieveDDOListByDIDs } from '@utils/aquarius'
import { CancelToken } from 'axios'
import { useSiteMetadata } from '@hooks/useSiteMetadata'
import { useCancelToken } from '@hooks/useCancelToken'
import { AssetExtended } from 'src/@types/AssetExtended'
@ -53,26 +52,6 @@ export default function Bookmarks(): ReactElement {
const { chainIds } = useUserPreferences()
const newCancelToken = useCancelToken()
const getAssetsBookmarked = useCallback(
async (
bookmarks: string[],
chainIds: number[],
cancelToken: CancelToken
) => {
try {
const result = await retrieveDDOListByDIDs(
bookmarks,
chainIds,
cancelToken
)
return result
} catch (error) {
LoggerInstance.error(error.message)
}
},
[]
)
useEffect(() => {
if (!appConfig?.metadataCacheUri || bookmarks === []) return
@ -85,29 +64,30 @@ export default function Bookmarks(): ReactElement {
setIsLoading(true)
try {
const resultPinned = await getAssetsBookmarked(
const result = await retrieveDDOListByDIDs(
bookmarks,
chainIds,
newCancelToken()
)
if (!result?.length) return
const pinnedAssets: AssetExtended[] = await getAccessDetailsForAssets(
resultPinned,
result,
accountId
)
setPinned(pinnedAssets)
} catch (error) {
LoggerInstance.error(error.message)
}
LoggerInstance.error(`Bookmarks error:`, error.message)
} finally {
setIsLoading(false)
}
}
init()
}, [
appConfig?.metadataCacheUri,
bookmarks,
chainIds,
accountId,
getAssetsBookmarked,
newCancelToken
])