mirror of
https://github.com/oceanprotocol/react.git
synced 2025-02-14 21:10:38 +01:00
add ComputeItem, getComputeItems
This commit is contained in:
parent
e2b24ff567
commit
252dc530a8
5
src/hooks/useSearch/ComputeItem.ts
Normal file
5
src/hooks/useSearch/ComputeItem.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { DDO, ComputeJob } from '@oceanprotocol/squid'
|
||||||
|
export interface ComputeItem {
|
||||||
|
job: ComputeJob
|
||||||
|
ddo: DDO
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
export * from './useSearch'
|
export * from './useSearch'
|
||||||
|
export * from './ComputeItem'
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Logger, DDO } from '@oceanprotocol/squid'
|
import { Logger, DDO, ComputeJob } from '@oceanprotocol/squid'
|
||||||
import { useOcean } from '../../providers'
|
import { useOcean } from '../../providers'
|
||||||
import {
|
import {
|
||||||
SearchQuery,
|
SearchQuery,
|
||||||
Aquarius,
|
Aquarius,
|
||||||
QueryResult
|
QueryResult
|
||||||
} from '@oceanprotocol/squid/dist/node/aquarius/Aquarius'
|
} from '@oceanprotocol/squid/dist/node/aquarius/Aquarius'
|
||||||
|
import { ComputeItem } from './ComputeItem'
|
||||||
|
|
||||||
// TODO searchText,
|
// TODO searchText,
|
||||||
interface UseSearch {
|
interface UseSearch {
|
||||||
searchWithQuery: (query: SearchQuery) => Promise<QueryResult>
|
searchWithQuery: (query: SearchQuery) => Promise<QueryResult>
|
||||||
getPublishedList: (page: number, offset: number) => Promise<QueryResult>
|
getPublishedList: (page: number, offset: number) => Promise<QueryResult>
|
||||||
getConsumedList: () => Promise<DDO[] | undefined>
|
getConsumedList: () => Promise<DDO[] | undefined>
|
||||||
|
getComputeItems: () => Promise<ComputeItem[]>
|
||||||
searchError?: string
|
searchError?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +79,37 @@ function useSearch(): UseSearch {
|
|||||||
return consumedItems
|
return consumedItems
|
||||||
}
|
}
|
||||||
|
|
||||||
return { searchWithQuery, getPublishedList, getConsumedList, searchError }
|
async function getComputeItems(): Promise<ComputeItem[]> {
|
||||||
|
const jobList = await ocean.compute.status(account)
|
||||||
|
return Promise.all(
|
||||||
|
jobList.map(async (job) => {
|
||||||
|
if (!job) return
|
||||||
|
const { did } = await ocean.keeper.agreementStoreManager.getAgreement(
|
||||||
|
job.agreementId
|
||||||
|
)
|
||||||
|
|
||||||
|
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 { job, ddo }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
searchWithQuery,
|
||||||
|
getPublishedList,
|
||||||
|
getConsumedList,
|
||||||
|
getComputeItems,
|
||||||
|
searchError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { useSearch, UseSearch }
|
export { useSearch, UseSearch }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user