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) { for (const asset of assets) {
if (chainAssetLists[asset.chainId]) { if (chainAssetLists[asset.chainId]) {
chainAssetLists[asset.chainId].push( chainAssetLists[asset.chainId].push(
asset?.services[0].datatokenAddress.toLowerCase() asset.services[0].datatokenAddress.toLowerCase()
) )
} else { } else {
chainAssetLists[asset.chainId] = [] chainAssetLists[asset.chainId] = []
chainAssetLists[asset.chainId].push( 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[], chainIds: number[],
cancelToken: CancelToken cancelToken: CancelToken
): Promise<Asset[]> { ): Promise<Asset[]> {
if (didList?.length === 0 || chainIds?.length === 0) return []
try { try {
if (didList?.length === 0 || chainIds?.length === 0) return []
const orderedDDOListByDIDList: Asset[] = [] const orderedDDOListByDIDList: Asset[] = []
const baseQueryparams = { const baseQueryparams = {
chainIds, chainIds,
@ -190,9 +191,10 @@ export async function retrieveDDOListByDIDs(
} as BaseQueryParams } as BaseQueryParams
const query = generateBaseQuery(baseQueryparams) const query = generateBaseQuery(baseQueryparams)
const result = await queryMetadata(query, cancelToken) const result = await queryMetadata(query, cancelToken)
didList.forEach((did: string) => { didList.forEach((did: string) => {
const ddo = result.results.find((ddo: Asset) => ddo.id === did) const ddo = result.results.find((ddo: Asset) => ddo.id === did)
orderedDDOListByDIDList.push(ddo) if (ddo) orderedDDOListByDIDList.push(ddo)
}) })
return orderedDDOListByDIDList return orderedDDOListByDIDList
} catch (error) { } catch (error) {

View File

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