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:
parent
c038570cdd
commit
3a424bc44c
@ -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()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user