mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
added getConsumedList
This commit is contained in:
parent
259f95655f
commit
ff93d688b4
@ -1,5 +1,5 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Logger } from '@oceanprotocol/squid'
|
import { Logger, DDO } from '@oceanprotocol/squid'
|
||||||
import { useOcean } from '../../providers'
|
import { useOcean } from '../../providers'
|
||||||
import {
|
import {
|
||||||
SearchQuery,
|
SearchQuery,
|
||||||
@ -7,19 +7,20 @@ import {
|
|||||||
QueryResult
|
QueryResult
|
||||||
} from '@oceanprotocol/squid/dist/node/aquarius/Aquarius'
|
} from '@oceanprotocol/squid/dist/node/aquarius/Aquarius'
|
||||||
|
|
||||||
// TODO searchText
|
// TODO searchText,
|
||||||
interface UseSearch {
|
interface UseSearch {
|
||||||
searchWithQuery: (query: SearchQuery) => Promise<QueryResult>
|
searchWithQuery: (query: SearchQuery) => Promise<QueryResult>
|
||||||
getPublishedList: (
|
getPublishedList: (
|
||||||
account: string,
|
|
||||||
page: number,
|
page: number,
|
||||||
offset: number
|
offset: number
|
||||||
) => Promise<QueryResult>
|
) => Promise<QueryResult>
|
||||||
|
getConsumedList: () => Promise<(DDO[] | undefined)>
|
||||||
searchError?: string
|
searchError?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function useSearch(): UseSearch {
|
function useSearch(): UseSearch {
|
||||||
const { ocean, account, config } = useOcean()
|
// should we call the useOcean hook in useSearch or in each function?
|
||||||
|
const { ocean, account, config, accountId } = useOcean()
|
||||||
const [searchError, setSearchError] = useState<string | undefined>()
|
const [searchError, setSearchError] = useState<string | undefined>()
|
||||||
|
|
||||||
async function searchWithQuery(query: SearchQuery): Promise<QueryResult> {
|
async function searchWithQuery(query: SearchQuery): Promise<QueryResult> {
|
||||||
@ -36,7 +37,6 @@ function useSearch(): UseSearch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getPublishedList(
|
async function getPublishedList(
|
||||||
account: string,
|
|
||||||
page: number,
|
page: number,
|
||||||
offset: number
|
offset: number
|
||||||
): Promise<QueryResult> {
|
): Promise<QueryResult> {
|
||||||
@ -49,7 +49,7 @@ function useSearch(): UseSearch {
|
|||||||
page,
|
page,
|
||||||
offset,
|
offset,
|
||||||
query: {
|
query: {
|
||||||
'publicKey.owner': [account]
|
'publicKey.owner': [accountId]
|
||||||
},
|
},
|
||||||
sort: {
|
sort: {
|
||||||
created: -1
|
created: -1
|
||||||
@ -62,7 +62,25 @@ function useSearch(): UseSearch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { searchWithQuery, getPublishedList, searchError }
|
async function getConsumedList() : Promise<(DDO []| undefined)>{
|
||||||
|
const consumed = await ocean.assets.consumerAssets(accountId)
|
||||||
|
const consumedItems = await Promise.all(
|
||||||
|
consumed.map(async (did) => {
|
||||||
|
const ddo = await ocean.assets.resolve(did)
|
||||||
|
if (ddo) {
|
||||||
|
// Since we are getting assets from chain there might be
|
||||||
|
// assets from other marketplaces. So return only those assets
|
||||||
|
// whose serviceEndpoint contains the configured Aquarius URI.
|
||||||
|
const { serviceEndpoint } = ddo.findServiceByType('metadata')
|
||||||
|
if (serviceEndpoint?.includes(config.aquariusUri)) return ddo
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
return consumedItems
|
||||||
|
}
|
||||||
|
|
||||||
|
return { searchWithQuery, getPublishedList,getConsumedList, searchError }
|
||||||
}
|
}
|
||||||
|
|
||||||
export { useSearch, UseSearch }
|
export { useSearch, UseSearch }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user