mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
Adapt Aquarius queries to chainId (#667)
* wip * get latest assets from multiple networks * updated queryMetadata function in components * added new multinetwork aquarius api * Use ddo chainId for AssetType inside teaser * added chainId filter to queries from home page * put chainId query string in parenthesis * search filter by chainIds * updated getDoo and getAssetName functions * removed logs and fixed lint errors * updated get published assets query * adapted bookmarks aquarius call to multinetwork * removed temporary ddo Co-authored-by: Norbi <katunanorbert@gmai.com>
This commit is contained in:
parent
3798d80a4d
commit
4e0bc09f8c
@ -127,6 +127,7 @@ const queryLatest = {
|
||||
offset: 9,
|
||||
query: {
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
|
||||
|
||||
query_string: { query: `-isInPurgatory:true` }
|
||||
},
|
||||
sort: { created: -1 }
|
||||
@ -141,11 +142,7 @@ function Component() {
|
||||
const source = axios.CancelToken.source()
|
||||
|
||||
async function init() {
|
||||
const result = await queryMetadata(
|
||||
query,
|
||||
appConfig.metadataCacheUri,
|
||||
source.token
|
||||
)
|
||||
const result = await queryMetadata(query, source.token)
|
||||
setResult(result)
|
||||
}
|
||||
init()
|
||||
|
@ -5,21 +5,20 @@ import { ReactComponent as Compute } from '../../images/compute.svg'
|
||||
import { ReactComponent as Download } from '../../images/download.svg'
|
||||
import { ReactComponent as Lock } from '../../images/lock.svg'
|
||||
import NetworkName from './NetworkName'
|
||||
import { useOcean } from '../../providers/Ocean'
|
||||
|
||||
const cx = classNames.bind(styles)
|
||||
|
||||
export default function AssetType({
|
||||
type,
|
||||
accessType,
|
||||
className
|
||||
className,
|
||||
chainId
|
||||
}: {
|
||||
type: string
|
||||
accessType: string
|
||||
chainId: number
|
||||
className?: string
|
||||
}): ReactElement {
|
||||
const { config } = useOcean()
|
||||
|
||||
const styleClasses = cx({
|
||||
[className]: className
|
||||
})
|
||||
@ -37,12 +36,8 @@ export default function AssetType({
|
||||
{type === 'dataset' ? 'data set' : 'algorithm'}
|
||||
</div>
|
||||
{/* TODO: networkId needs to come from the multinetwork DDO for each asset */}
|
||||
{(config?.networkId || 1) && (
|
||||
<NetworkName
|
||||
networkId={config?.networkId || 1}
|
||||
className={styles.network}
|
||||
minimal
|
||||
/>
|
||||
{chainId && (
|
||||
<NetworkName networkId={chainId} className={styles.network} minimal />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
@ -30,11 +30,7 @@ export default function AssetListTitle({
|
||||
const source = axios.CancelToken.source()
|
||||
|
||||
async function getAssetName() {
|
||||
const title = await getAssetsNames(
|
||||
[did],
|
||||
appConfig.metadataCacheUri,
|
||||
source.token
|
||||
)
|
||||
const title = await getAssetsNames([did], source.token)
|
||||
setAssetTitle(title[did])
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import { useOcean } from '../../providers/Ocean'
|
||||
import styles from './AssetTeaser.module.css'
|
||||
|
||||
declare type AssetTeaserProps = {
|
||||
ddo: DDO
|
||||
ddo: any
|
||||
price: BestPrice
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ const AssetTeaser: React.FC<AssetTeaserProps> = ({
|
||||
type={type}
|
||||
accessType={accessType}
|
||||
className={styles.typeDetails}
|
||||
chainId={ddo.chainId}
|
||||
/>
|
||||
|
||||
<div className={styles.content}>
|
||||
|
@ -6,13 +6,16 @@ import { useOcean } from '../../providers/Ocean'
|
||||
import Price from '../atoms/Price'
|
||||
import Tooltip from '../atoms/Tooltip'
|
||||
import AssetTitle from './AssetListTitle'
|
||||
import { queryMetadata } from '../../utils/aquarius'
|
||||
import {
|
||||
queryMetadata,
|
||||
transformChainIdsListToQuery
|
||||
} from '../../utils/aquarius'
|
||||
import axios, { CancelToken } from 'axios'
|
||||
import { useSiteMetadata } from '../../hooks/useSiteMetadata'
|
||||
|
||||
async function getAssetsBookmarked(
|
||||
bookmarks: string[],
|
||||
metadataCacheUri: string,
|
||||
chainIds: number[],
|
||||
cancelToken: CancelToken
|
||||
) {
|
||||
const searchDids = JSON.stringify(bookmarks)
|
||||
@ -27,7 +30,9 @@ async function getAssetsBookmarked(
|
||||
offset: 100,
|
||||
query: {
|
||||
query_string: {
|
||||
query: searchDids,
|
||||
query: `(${searchDids}) AND (${transformChainIdsListToQuery(
|
||||
chainIds
|
||||
)})`,
|
||||
fields: ['dataToken'],
|
||||
default_operator: 'OR'
|
||||
}
|
||||
@ -36,11 +41,7 @@ async function getAssetsBookmarked(
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await queryMetadata(
|
||||
queryBookmarks,
|
||||
metadataCacheUri,
|
||||
cancelToken
|
||||
)
|
||||
const result = await queryMetadata(queryBookmarks, cancelToken)
|
||||
|
||||
return result
|
||||
} catch (error) {
|
||||
@ -84,6 +85,7 @@ export default function Bookmarks(): ReactElement {
|
||||
|
||||
const [pinned, setPinned] = useState<DDO[]>()
|
||||
const [isLoading, setIsLoading] = useState<boolean>()
|
||||
const { chainIds } = useUserPreferences()
|
||||
|
||||
useEffect(() => {
|
||||
if (!appConfig.metadataCacheUri || bookmarks === []) return
|
||||
@ -101,7 +103,7 @@ export default function Bookmarks(): ReactElement {
|
||||
try {
|
||||
const resultPinned = await getAssetsBookmarked(
|
||||
bookmarks,
|
||||
appConfig.metadataCacheUri,
|
||||
chainIds,
|
||||
source.token
|
||||
)
|
||||
setPinned(resultPinned?.results)
|
||||
@ -116,7 +118,7 @@ export default function Bookmarks(): ReactElement {
|
||||
return () => {
|
||||
source.cancel()
|
||||
}
|
||||
}, [bookmarks, appConfig.metadataCacheUri])
|
||||
}, [bookmarks, chainIds])
|
||||
|
||||
return (
|
||||
<Table
|
||||
|
@ -16,6 +16,7 @@ import {
|
||||
|
||||
import web3 from 'web3'
|
||||
import { useWeb3 } from '../../providers/Web3'
|
||||
import { getOceanConfig } from '../../utils/ocean'
|
||||
|
||||
const txHistoryQueryByPool = gql`
|
||||
query TransactionHistoryByPool($user: String, $pool: String) {
|
||||
|
@ -38,6 +38,7 @@ import { secondsToString } from '../../../../utils/metadata'
|
||||
import { AssetSelectionAsset } from '../../../molecules/FormFields/AssetSelection'
|
||||
import AlgorithmDatasetsListForCompute from '../../AssetContent/AlgorithmDatasetsListForCompute'
|
||||
import { getPreviousOrders, getPrice } from '../../../../utils/subgraph'
|
||||
import { chainIds } from '../../../../../app.config'
|
||||
|
||||
const SuccessAction = () => (
|
||||
<Button style="text" to="/history?defaultTab=ComputeJobs" size="small">
|
||||
@ -153,7 +154,6 @@ export default function Compute({
|
||||
getQuerryString(
|
||||
computeService.attributes.main.privacy.publisherTrustedAlgorithms
|
||||
),
|
||||
appConfig.metadataCacheUri,
|
||||
source.token
|
||||
)
|
||||
setDdoAlgorithmList(gueryResults.results)
|
||||
@ -161,7 +161,6 @@ export default function Compute({
|
||||
algorithmSelectionList = await transformDDOToAssetSelection(
|
||||
datasetComputeService?.serviceEndpoint,
|
||||
gueryResults.results,
|
||||
appConfig.metadataCacheUri,
|
||||
[]
|
||||
)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import { ComputePrivacyForm } from '../../../../models/FormEditComputeDataset'
|
||||
import { publisherTrustedAlgorithm as PublisherTrustedAlgorithm } from '@oceanprotocol/lib'
|
||||
import axios from 'axios'
|
||||
import { useSiteMetadata } from '../../../../hooks/useSiteMetadata'
|
||||
import { chainIds } from '../../../../../app.config'
|
||||
|
||||
export default function FormEditComputeDataset({
|
||||
data,
|
||||
@ -51,16 +52,11 @@ export default function FormEditComputeDataset({
|
||||
},
|
||||
sort: { created: -1 }
|
||||
}
|
||||
const querryResult = await queryMetadata(
|
||||
query,
|
||||
appConfig.metadataCacheUri,
|
||||
source.token
|
||||
)
|
||||
const querryResult = await queryMetadata(query, source.token)
|
||||
const datasetComputeService = ddo.findServiceByType('compute')
|
||||
const algorithmSelectionList = await transformDDOToAssetSelection(
|
||||
datasetComputeService?.serviceEndpoint,
|
||||
querryResult.results,
|
||||
appConfig.metadataCacheUri,
|
||||
publisherTrustedAlgorithms
|
||||
)
|
||||
return algorithmSelectionList
|
||||
|
@ -20,6 +20,7 @@ export default function MetaMain(): ReactElement {
|
||||
<AssetType
|
||||
type={type}
|
||||
accessType={accessType}
|
||||
chainId={ddo.chainId}
|
||||
className={styles.assetType}
|
||||
/>
|
||||
<ExplorerLink
|
||||
|
@ -50,11 +50,7 @@ function DetailsAssets({ job }: { job: ComputeJobMetaData }) {
|
||||
async function getAlgoMetadata() {
|
||||
const source = axios.CancelToken.source()
|
||||
|
||||
const ddo = await retrieveDDO(
|
||||
job.algoDID,
|
||||
appConfig.metadataCacheUri,
|
||||
source.token
|
||||
)
|
||||
const ddo = await retrieveDDO(job.algoDID, source.token)
|
||||
setAlgoDtSymbol(ddo.dataTokenInfo.symbol)
|
||||
|
||||
const { attributes } = ddo.findServiceByType('metadata')
|
||||
|
@ -10,7 +10,10 @@ import Button from '../../../atoms/Button'
|
||||
import { useOcean } from '../../../../providers/Ocean'
|
||||
import { gql, useQuery } from '@apollo/client'
|
||||
import { useWeb3 } from '../../../../providers/Web3'
|
||||
import { queryMetadata } from '../../../../utils/aquarius'
|
||||
import {
|
||||
queryMetadata,
|
||||
transformChainIdsListToQuery
|
||||
} from '../../../../utils/aquarius'
|
||||
import axios, { CancelToken } from 'axios'
|
||||
import { ComputeOrders } from '../../../../@types/apollo/ComputeOrders'
|
||||
import Details from './Details'
|
||||
@ -18,6 +21,7 @@ import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/Comput
|
||||
import { ReactComponent as Refresh } from '../../../../images/refresh.svg'
|
||||
import styles from './index.module.css'
|
||||
import { useSiteMetadata } from '../../../../hooks/useSiteMetadata'
|
||||
import { useUserPreferences } from '../../../../providers/UserPreferences'
|
||||
|
||||
const getComputeOrders = gql`
|
||||
query ComputeOrders($user: String!) {
|
||||
@ -84,31 +88,35 @@ const columns = [
|
||||
|
||||
async function getAssetMetadata(
|
||||
queryDtList: string,
|
||||
metadataCacheUri: string,
|
||||
cancelToken: CancelToken
|
||||
cancelToken: CancelToken,
|
||||
chainIds: number[]
|
||||
): Promise<DDO[]> {
|
||||
const queryDid = {
|
||||
page: 1,
|
||||
offset: 100,
|
||||
query: {
|
||||
query_string: {
|
||||
query: `(${queryDtList}) AND service.attributes.main.type:dataset AND service.type:compute`,
|
||||
query: `(${queryDtList}) (${transformChainIdsListToQuery(
|
||||
chainIds
|
||||
)}) AND (${transformChainIdsListToQuery(
|
||||
chainIds
|
||||
)}) AND service.attributes.main.type:dataset AND service.type:compute`,
|
||||
fields: ['dataToken']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const result = await queryMetadata(queryDid, metadataCacheUri, cancelToken)
|
||||
const result = await queryMetadata(queryDid, cancelToken)
|
||||
|
||||
return result.results
|
||||
}
|
||||
|
||||
export default function ComputeJobs(): ReactElement {
|
||||
const { appConfig } = useSiteMetadata()
|
||||
const { ocean, account, config } = useOcean()
|
||||
const { accountId } = useWeb3()
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [jobs, setJobs] = useState<ComputeJobMetaData[]>([])
|
||||
const { chainIds } = useUserPreferences()
|
||||
const { data, refetch } = useQuery<ComputeOrders>(getComputeOrders, {
|
||||
variables: {
|
||||
user: accountId?.toLowerCase()
|
||||
@ -116,8 +124,7 @@ export default function ComputeJobs(): ReactElement {
|
||||
})
|
||||
|
||||
async function getJobs() {
|
||||
if (!ocean || !account) return
|
||||
|
||||
if (!accountId) return
|
||||
setIsLoading(true)
|
||||
|
||||
await refetch()
|
||||
@ -133,11 +140,7 @@ export default function ComputeJobs(): ReactElement {
|
||||
|
||||
try {
|
||||
const source = axios.CancelToken.source()
|
||||
const assets = await getAssetMetadata(
|
||||
queryDtList,
|
||||
appConfig.metadataCacheUri,
|
||||
source.token
|
||||
)
|
||||
const assets = await getAssetMetadata(queryDtList, source.token, chainIds)
|
||||
const providers: Provider[] = []
|
||||
const serviceEndpoints: string[] = []
|
||||
for (let i = 0; i < data.tokenOrders.length; i++) {
|
||||
@ -239,12 +242,12 @@ export default function ComputeJobs(): ReactElement {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (data === undefined || !appConfig.metadataCacheUri) {
|
||||
if (data === undefined || !chainIds) {
|
||||
setIsLoading(false)
|
||||
return
|
||||
}
|
||||
getJobs()
|
||||
}, [ocean, account, data, appConfig.metadataCacheUri])
|
||||
}, [ocean, account, data, chainIds])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -76,11 +76,7 @@ export default function ComputeDownloads(): ReactElement {
|
||||
const did = web3.utils
|
||||
.toChecksumAddress(data.tokenOrders[i].datatokenId.address)
|
||||
.replace('0x', 'did:op:')
|
||||
const ddo = await retrieveDDO(
|
||||
did,
|
||||
appConfig.metadataCacheUri,
|
||||
source.token
|
||||
)
|
||||
const ddo = await retrieveDDO(did, source.token)
|
||||
if (ddo.service[1].type === 'access') {
|
||||
filteredOrders.push({
|
||||
did: did,
|
||||
|
@ -3,7 +3,10 @@ import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/Metadata
|
||||
import React, { ReactElement, useEffect, useState } from 'react'
|
||||
import AssetList from '../../organisms/AssetList'
|
||||
import axios from 'axios'
|
||||
import { queryMetadata } from '../../../utils/aquarius'
|
||||
import {
|
||||
queryMetadata,
|
||||
transformChainIdsListToQuery
|
||||
} from '../../../utils/aquarius'
|
||||
import { useWeb3 } from '../../../providers/Web3'
|
||||
import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
|
||||
import { useUserPreferences } from '../../../providers/UserPreferences'
|
||||
@ -27,7 +30,9 @@ export default function PublishedList(): ReactElement {
|
||||
offset: 9,
|
||||
query: {
|
||||
query_string: {
|
||||
query: `(publicKey.owner:${accountId})`
|
||||
query: `(publicKey.owner:${accountId}) AND (${transformChainIdsListToQuery(
|
||||
chainIds
|
||||
)})`
|
||||
}
|
||||
},
|
||||
sort: { created: -1 }
|
||||
@ -36,11 +41,7 @@ export default function PublishedList(): ReactElement {
|
||||
const source = axios.CancelToken.source()
|
||||
|
||||
queryResult || setIsLoading(true)
|
||||
const result = await queryMetadata(
|
||||
queryPublishedAssets,
|
||||
appConfig.metadataCacheUri,
|
||||
source.token
|
||||
)
|
||||
const result = await queryMetadata(queryPublishedAssets, source.token)
|
||||
setQueryResult(result)
|
||||
} catch (error) {
|
||||
Logger.error(error.message)
|
||||
|
@ -10,7 +10,10 @@ import Container from '../atoms/Container'
|
||||
import Button from '../atoms/Button'
|
||||
import Bookmarks from '../molecules/Bookmarks'
|
||||
import axios from 'axios'
|
||||
import { queryMetadata } from '../../utils/aquarius'
|
||||
import {
|
||||
queryMetadata,
|
||||
transformChainIdsListToQuery
|
||||
} from '../../utils/aquarius'
|
||||
import Permission from '../organisms/Permission'
|
||||
import { getHighestLiquidityDIDs } from '../../utils/subgraph'
|
||||
import { DDO, Logger } from '@oceanprotocol/lib'
|
||||
@ -28,7 +31,9 @@ async function getQueryHighest(
|
||||
offset: 15,
|
||||
query: {
|
||||
query_string: {
|
||||
query: `(${dids}) AND -isInPurgatory:true`,
|
||||
query: `(${dids}) AND (${transformChainIdsListToQuery(
|
||||
chainIds
|
||||
)}) AND -isInPurgatory:true`,
|
||||
fields: ['dataToken']
|
||||
}
|
||||
}
|
||||
@ -44,7 +49,9 @@ function getQueryLatest(chainIds: number[]): SearchQuery {
|
||||
offset: 9,
|
||||
query: {
|
||||
query_string: {
|
||||
query: `-isInPurgatory:true`
|
||||
query: `(${transformChainIdsListToQuery(
|
||||
chainIds
|
||||
)}) AND -isInPurgatory:true `
|
||||
}
|
||||
},
|
||||
sort: { created: -1 }
|
||||
@ -72,6 +79,7 @@ function SectionQueryResult({
|
||||
const { appConfig } = useSiteMetadata()
|
||||
const [result, setResult] = useState<QueryResult>()
|
||||
const [loading, setLoading] = useState<boolean>()
|
||||
const { chainIds } = useUserPreferences()
|
||||
|
||||
useEffect(() => {
|
||||
if (!appConfig.metadataCacheUri) return
|
||||
@ -80,11 +88,7 @@ function SectionQueryResult({
|
||||
async function init() {
|
||||
try {
|
||||
setLoading(true)
|
||||
const result = await queryMetadata(
|
||||
query,
|
||||
appConfig.metadataCacheUri,
|
||||
source.token
|
||||
)
|
||||
const result = await queryMetadata(query, source.token)
|
||||
if (queryData && result.totalResults > 0 && result.totalResults <= 15) {
|
||||
const searchDIDs = queryData.split(' ')
|
||||
const sortedAssets = sortElements(result.results, searchDIDs)
|
||||
|
@ -10,6 +10,7 @@ import { getResults } from './utils'
|
||||
import { navigate } from 'gatsby'
|
||||
import { updateQueryStringParameter } from '../../../utils'
|
||||
import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
|
||||
import { useUserPreferences } from '../../../providers/UserPreferences'
|
||||
|
||||
export default function SearchPage({
|
||||
location,
|
||||
@ -21,6 +22,7 @@ export default function SearchPage({
|
||||
const { appConfig } = useSiteMetadata()
|
||||
const parsed = queryString.parse(location.search)
|
||||
const { text, owner, tags, page, sort, sortOrder, serviceType } = parsed
|
||||
const { chainIds } = useUserPreferences()
|
||||
const [queryResult, setQueryResult] = useState<QueryResult>()
|
||||
const [loading, setLoading] = useState<boolean>()
|
||||
const [service, setServiceType] = useState<string>(serviceType as string)
|
||||
@ -34,7 +36,11 @@ export default function SearchPage({
|
||||
async function initSearch() {
|
||||
setLoading(true)
|
||||
setTotalResults(undefined)
|
||||
const queryResult = await getResults(parsed, appConfig.metadataCacheUri)
|
||||
const queryResult = await getResults(
|
||||
parsed,
|
||||
appConfig.metadataCacheUri,
|
||||
chainIds
|
||||
)
|
||||
setQueryResult(queryResult)
|
||||
setTotalResults(queryResult.totalResults)
|
||||
setLoading(false)
|
||||
@ -48,7 +54,8 @@ export default function SearchPage({
|
||||
page,
|
||||
serviceType,
|
||||
sortOrder,
|
||||
appConfig.metadataCacheUri
|
||||
appConfig.metadataCacheUri,
|
||||
chainIds
|
||||
])
|
||||
|
||||
function setPage(page: number) {
|
||||
|
@ -1,6 +1,11 @@
|
||||
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache'
|
||||
import { MetadataCache, Logger } from '@oceanprotocol/lib'
|
||||
import {
|
||||
queryMetadata,
|
||||
transformChainIdsListToQuery
|
||||
} from '../../../utils/aquarius'
|
||||
import queryString from 'query-string'
|
||||
import axios from 'axios'
|
||||
|
||||
export const SortTermOptions = {
|
||||
Created: 'created',
|
||||
@ -46,6 +51,7 @@ function getSortType(sortParam: string): string {
|
||||
}
|
||||
|
||||
export function getSearchQuery(
|
||||
chainIds: number[],
|
||||
text?: string,
|
||||
owner?: string,
|
||||
tags?: string,
|
||||
@ -137,6 +143,11 @@ export function getSearchQuery(
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
query_string: {
|
||||
query: `${transformChainIdsListToQuery(chainIds)}`
|
||||
}
|
||||
},
|
||||
{
|
||||
term: {
|
||||
isInPurgatory: false
|
||||
@ -163,7 +174,8 @@ export async function getResults(
|
||||
sortOrder?: string
|
||||
serviceType?: string
|
||||
},
|
||||
metadataCacheUri: string
|
||||
metadataCacheUri: string,
|
||||
chainIds: number[]
|
||||
): Promise<QueryResult> {
|
||||
const {
|
||||
text,
|
||||
@ -176,9 +188,9 @@ export async function getResults(
|
||||
sortOrder,
|
||||
serviceType
|
||||
} = params
|
||||
const metadataCache = new MetadataCache(metadataCacheUri, Logger)
|
||||
|
||||
const searchQuery = getSearchQuery(
|
||||
chainIds,
|
||||
text,
|
||||
owner,
|
||||
tags,
|
||||
@ -189,7 +201,9 @@ export async function getResults(
|
||||
sortOrder,
|
||||
serviceType
|
||||
)
|
||||
const queryResult = await metadataCache.queryMetadata(searchQuery)
|
||||
const source = axios.CancelToken.source()
|
||||
// const queryResult = await metadataCache.queryMetadata(searchQuery)
|
||||
const queryResult = await queryMetadata(searchQuery, source.token)
|
||||
return queryResult
|
||||
}
|
||||
|
||||
|
@ -14,14 +14,13 @@ import axios, { CancelToken } from 'axios'
|
||||
import { retrieveDDO } from '../utils/aquarius'
|
||||
import { getPrice } from '../utils/subgraph'
|
||||
import { MetadataMarket } from '../@types/MetaData'
|
||||
import { DDO_TEMPORARY } from './Ocean'
|
||||
import { useWeb3 } from './Web3'
|
||||
import { useSiteMetadata } from '../hooks/useSiteMetadata'
|
||||
|
||||
interface AssetProviderValue {
|
||||
isInPurgatory: boolean
|
||||
purgatoryData: PurgatoryData
|
||||
ddo: DDO
|
||||
ddo: any
|
||||
did: string
|
||||
metadata: MetadataMarket
|
||||
title: string
|
||||
@ -51,7 +50,7 @@ function AssetProvider({
|
||||
const { networkId } = useWeb3()
|
||||
const [isInPurgatory, setIsInPurgatory] = useState(false)
|
||||
const [purgatoryData, setPurgatoryData] = useState<PurgatoryData>()
|
||||
const [ddo, setDDO] = useState<DDO>()
|
||||
const [ddo, setDDO] = useState<any>()
|
||||
const [did, setDID] = useState<string>()
|
||||
const [metadata, setMetadata] = useState<MetadataMarket>()
|
||||
const [title, setTitle] = useState<string>()
|
||||
@ -65,11 +64,7 @@ function AssetProvider({
|
||||
const fetchDdo = async (token?: CancelToken) => {
|
||||
Logger.log('[asset] Init asset, get DDO')
|
||||
setLoading(true)
|
||||
const ddo = await retrieveDDO(
|
||||
asset as string,
|
||||
appConfig.metadataCacheUri,
|
||||
token
|
||||
)
|
||||
const ddo = await retrieveDDO(asset as string, token)
|
||||
|
||||
if (!ddo) {
|
||||
setError(
|
||||
@ -126,7 +121,7 @@ function AssetProvider({
|
||||
}
|
||||
}, [])
|
||||
|
||||
const initMetadata = useCallback(async (ddo: DDO): Promise<void> => {
|
||||
const initMetadata = useCallback(async (ddo: any): Promise<void> => {
|
||||
if (!ddo) return
|
||||
setLoading(true)
|
||||
const returnedPrice = await getPrice(ddo)
|
||||
@ -155,7 +150,7 @@ function AssetProvider({
|
||||
if (!networkId || !ddo) return
|
||||
|
||||
// TODO: remove typing once present in ocean.js' DDO typing
|
||||
const isAssetNetwork = networkId === (ddo as DDO_TEMPORARY).chainId
|
||||
const isAssetNetwork = networkId === ddo?.chainId
|
||||
setIsAssetNetwork(isAssetNetwork)
|
||||
}, [networkId, ddo])
|
||||
|
||||
|
@ -28,11 +28,6 @@ interface OceanProviderValue {
|
||||
|
||||
const OceanContext = createContext({} as OceanProviderValue)
|
||||
|
||||
// TODO: remove temporary typing once ddo.chainId is present in ocean.js
|
||||
export interface DDO_TEMPORARY extends DDO {
|
||||
chainId: number
|
||||
}
|
||||
|
||||
function OceanProvider({ children }: { children: ReactNode }): ReactElement {
|
||||
const { web3, accountId } = useWeb3()
|
||||
const { ddo } = useAsset()
|
||||
@ -71,13 +66,13 @@ function OceanProvider({ children }: { children: ReactNode }): ReactElement {
|
||||
// -----------------------------------
|
||||
useEffect(() => {
|
||||
// TODO: remove DDO typing once ocean.js has it
|
||||
if (!(ddo as DDO_TEMPORARY)?.chainId) return
|
||||
if (!ddo?.chainId) return
|
||||
|
||||
const config = {
|
||||
...getOceanConfig((ddo as DDO_TEMPORARY)?.chainId),
|
||||
...getOceanConfig(ddo?.chainId),
|
||||
|
||||
// add local dev values
|
||||
...((ddo as DDO_TEMPORARY)?.chainId === 8996 && {
|
||||
...(ddo?.chainId === 8996 && {
|
||||
...getDevelopmentConfig()
|
||||
})
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import {
|
||||
import { AssetSelectionAsset } from '../components/molecules/FormFields/AssetSelection'
|
||||
import { PriceList, getAssetsPriceList } from './subgraph'
|
||||
import axios, { CancelToken, AxiosResponse } from 'axios'
|
||||
import { DDO_TEMPORARY } from '../providers/Ocean'
|
||||
|
||||
function getQueryForAlgorithmDatasets(algorithmDid: string) {
|
||||
return {
|
||||
@ -50,18 +49,25 @@ export function transformQueryResult(
|
||||
}
|
||||
}
|
||||
|
||||
export function transformChainIdsListToQuery(chainIds: number[]) {
|
||||
let chainQuery = ''
|
||||
chainIds.forEach((chainId) => {
|
||||
chainQuery += `chainId:${chainId} OR `
|
||||
})
|
||||
chainQuery = chainQuery.slice(0, chainQuery.length - 4)
|
||||
return chainQuery
|
||||
}
|
||||
|
||||
export async function queryMetadata(
|
||||
query: SearchQuery,
|
||||
metadataCacheUri: string,
|
||||
cancelToken: CancelToken
|
||||
): Promise<QueryResult> {
|
||||
): Promise<any> {
|
||||
try {
|
||||
const response: AxiosResponse<QueryResult> = await axios.post(
|
||||
`${metadataCacheUri}/api/v1/aquarius/assets/ddo/query`,
|
||||
const response: AxiosResponse<any> = await axios.post(
|
||||
`https://multiaqua.oceanprotocol.com/api/v1/aquarius/assets/ddo/query`,
|
||||
{ ...query, cancelToken }
|
||||
)
|
||||
if (!response || response.status !== 200 || !response.data) return
|
||||
|
||||
return transformQueryResult(response.data)
|
||||
} catch (error) {
|
||||
if (axios.isCancel(error)) {
|
||||
@ -74,19 +80,17 @@ export async function queryMetadata(
|
||||
|
||||
export async function retrieveDDO(
|
||||
did: string | DID,
|
||||
metadataCacheUri: string,
|
||||
cancelToken: CancelToken
|
||||
): Promise<DDO_TEMPORARY> {
|
||||
): Promise<DDO> {
|
||||
try {
|
||||
const response: AxiosResponse<DDO> = await axios.get(
|
||||
`${metadataCacheUri}/api/v1/aquarius/assets/ddo/${did}`,
|
||||
`https://multiaqua.oceanprotocol.com/api/v1/aquarius/assets/ddo/${did}`,
|
||||
{ cancelToken }
|
||||
)
|
||||
if (!response || response.status !== 200 || !response.data) return
|
||||
|
||||
// TODO: remove hacking in chainId in DDO response once Aquarius gives us that
|
||||
const data = { ...response.data, chainId: 1 }
|
||||
return new DDO(data) as DDO_TEMPORARY
|
||||
const data = { ...response.data }
|
||||
return new DDO(data)
|
||||
} catch (error) {
|
||||
if (axios.isCancel(error)) {
|
||||
Logger.log(error.message)
|
||||
@ -98,12 +102,11 @@ export async function retrieveDDO(
|
||||
|
||||
export async function getAssetsNames(
|
||||
didList: string[] | DID[],
|
||||
metadataCacheUri: string,
|
||||
cancelToken: CancelToken
|
||||
): Promise<Record<string, string>> {
|
||||
try {
|
||||
const response: AxiosResponse<Record<string, string>> = await axios.post(
|
||||
`${metadataCacheUri}/api/v1/aquarius/assets/names`,
|
||||
`https://multiaqua.oceanprotocol.com/api/v1/aquarius/assets/names`,
|
||||
{
|
||||
didList,
|
||||
cancelToken
|
||||
@ -123,7 +126,6 @@ export async function getAssetsNames(
|
||||
export async function transformDDOToAssetSelection(
|
||||
datasetProviderEndpoint: string,
|
||||
ddoList: DDO[],
|
||||
metadataCacheUri: string,
|
||||
selectedAlgorithms?: PublisherTrustedAlgorithm[]
|
||||
): Promise<AssetSelectionAsset[]> {
|
||||
const source = axios.CancelToken.source()
|
||||
@ -138,7 +140,7 @@ export async function transformDDOToAssetSelection(
|
||||
algoComputeService?.serviceEndpoint &&
|
||||
(didProviderEndpointMap[ddo.id] = algoComputeService?.serviceEndpoint)
|
||||
}
|
||||
const ddoNames = await getAssetsNames(didList, metadataCacheUri, source.token)
|
||||
const ddoNames = await getAssetsNames(didList, source.token)
|
||||
const algorithmList: AssetSelectionAsset[] = []
|
||||
didList?.forEach((did: string) => {
|
||||
if (
|
||||
@ -180,7 +182,6 @@ export async function getAlgorithmDatasetsForCompute(
|
||||
const source = axios.CancelToken.source()
|
||||
const computeDatasets = await queryMetadata(
|
||||
getQueryForAlgorithmDatasets(algorithmId),
|
||||
metadataCacheUri,
|
||||
source.token
|
||||
)
|
||||
const computeDatasetsForCurrentAlgorithm: DDO[] = []
|
||||
@ -198,7 +199,6 @@ export async function getAlgorithmDatasetsForCompute(
|
||||
const datasets = await transformDDOToAssetSelection(
|
||||
datasetProviderUri,
|
||||
computeDatasetsForCurrentAlgorithm,
|
||||
metadataCacheUri,
|
||||
[]
|
||||
)
|
||||
return datasets
|
||||
|
Loading…
Reference in New Issue
Block a user