1
0
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:
Norbi 2021-07-07 09:45:20 +03:00 committed by GitHub
parent 3798d80a4d
commit 4e0bc09f8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 119 additions and 120 deletions

View File

@ -127,6 +127,7 @@ const queryLatest = {
offset: 9, offset: 9,
query: { query: {
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
query_string: { query: `-isInPurgatory:true` } query_string: { query: `-isInPurgatory:true` }
}, },
sort: { created: -1 } sort: { created: -1 }
@ -141,11 +142,7 @@ function Component() {
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
async function init() { async function init() {
const result = await queryMetadata( const result = await queryMetadata(query, source.token)
query,
appConfig.metadataCacheUri,
source.token
)
setResult(result) setResult(result)
} }
init() init()

View File

@ -5,21 +5,20 @@ import { ReactComponent as Compute } from '../../images/compute.svg'
import { ReactComponent as Download } from '../../images/download.svg' import { ReactComponent as Download } from '../../images/download.svg'
import { ReactComponent as Lock } from '../../images/lock.svg' import { ReactComponent as Lock } from '../../images/lock.svg'
import NetworkName from './NetworkName' import NetworkName from './NetworkName'
import { useOcean } from '../../providers/Ocean'
const cx = classNames.bind(styles) const cx = classNames.bind(styles)
export default function AssetType({ export default function AssetType({
type, type,
accessType, accessType,
className className,
chainId
}: { }: {
type: string type: string
accessType: string accessType: string
chainId: number
className?: string className?: string
}): ReactElement { }): ReactElement {
const { config } = useOcean()
const styleClasses = cx({ const styleClasses = cx({
[className]: className [className]: className
}) })
@ -37,12 +36,8 @@ export default function AssetType({
{type === 'dataset' ? 'data set' : 'algorithm'} {type === 'dataset' ? 'data set' : 'algorithm'}
</div> </div>
{/* TODO: networkId needs to come from the multinetwork DDO for each asset */} {/* TODO: networkId needs to come from the multinetwork DDO for each asset */}
{(config?.networkId || 1) && ( {chainId && (
<NetworkName <NetworkName networkId={chainId} className={styles.network} minimal />
networkId={config?.networkId || 1}
className={styles.network}
minimal
/>
)} )}
</div> </div>
) )

View File

@ -30,11 +30,7 @@ export default function AssetListTitle({
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
async function getAssetName() { async function getAssetName() {
const title = await getAssetsNames( const title = await getAssetsNames([did], source.token)
[did],
appConfig.metadataCacheUri,
source.token
)
setAssetTitle(title[did]) setAssetTitle(title[did])
} }

View File

@ -11,7 +11,7 @@ import { useOcean } from '../../providers/Ocean'
import styles from './AssetTeaser.module.css' import styles from './AssetTeaser.module.css'
declare type AssetTeaserProps = { declare type AssetTeaserProps = {
ddo: DDO ddo: any
price: BestPrice price: BestPrice
} }
@ -42,6 +42,7 @@ const AssetTeaser: React.FC<AssetTeaserProps> = ({
type={type} type={type}
accessType={accessType} accessType={accessType}
className={styles.typeDetails} className={styles.typeDetails}
chainId={ddo.chainId}
/> />
<div className={styles.content}> <div className={styles.content}>

View File

@ -6,13 +6,16 @@ import { useOcean } from '../../providers/Ocean'
import Price from '../atoms/Price' import Price from '../atoms/Price'
import Tooltip from '../atoms/Tooltip' import Tooltip from '../atoms/Tooltip'
import AssetTitle from './AssetListTitle' import AssetTitle from './AssetListTitle'
import { queryMetadata } from '../../utils/aquarius' import {
queryMetadata,
transformChainIdsListToQuery
} from '../../utils/aquarius'
import axios, { CancelToken } from 'axios' import axios, { CancelToken } from 'axios'
import { useSiteMetadata } from '../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../hooks/useSiteMetadata'
async function getAssetsBookmarked( async function getAssetsBookmarked(
bookmarks: string[], bookmarks: string[],
metadataCacheUri: string, chainIds: number[],
cancelToken: CancelToken cancelToken: CancelToken
) { ) {
const searchDids = JSON.stringify(bookmarks) const searchDids = JSON.stringify(bookmarks)
@ -27,7 +30,9 @@ async function getAssetsBookmarked(
offset: 100, offset: 100,
query: { query: {
query_string: { query_string: {
query: searchDids, query: `(${searchDids}) AND (${transformChainIdsListToQuery(
chainIds
)})`,
fields: ['dataToken'], fields: ['dataToken'],
default_operator: 'OR' default_operator: 'OR'
} }
@ -36,11 +41,7 @@ async function getAssetsBookmarked(
} }
try { try {
const result = await queryMetadata( const result = await queryMetadata(queryBookmarks, cancelToken)
queryBookmarks,
metadataCacheUri,
cancelToken
)
return result return result
} catch (error) { } catch (error) {
@ -84,6 +85,7 @@ export default function Bookmarks(): ReactElement {
const [pinned, setPinned] = useState<DDO[]>() const [pinned, setPinned] = useState<DDO[]>()
const [isLoading, setIsLoading] = useState<boolean>() const [isLoading, setIsLoading] = useState<boolean>()
const { chainIds } = useUserPreferences()
useEffect(() => { useEffect(() => {
if (!appConfig.metadataCacheUri || bookmarks === []) return if (!appConfig.metadataCacheUri || bookmarks === []) return
@ -101,7 +103,7 @@ export default function Bookmarks(): ReactElement {
try { try {
const resultPinned = await getAssetsBookmarked( const resultPinned = await getAssetsBookmarked(
bookmarks, bookmarks,
appConfig.metadataCacheUri, chainIds,
source.token source.token
) )
setPinned(resultPinned?.results) setPinned(resultPinned?.results)
@ -116,7 +118,7 @@ export default function Bookmarks(): ReactElement {
return () => { return () => {
source.cancel() source.cancel()
} }
}, [bookmarks, appConfig.metadataCacheUri]) }, [bookmarks, chainIds])
return ( return (
<Table <Table

View File

@ -16,6 +16,7 @@ import {
import web3 from 'web3' import web3 from 'web3'
import { useWeb3 } from '../../providers/Web3' import { useWeb3 } from '../../providers/Web3'
import { getOceanConfig } from '../../utils/ocean'
const txHistoryQueryByPool = gql` const txHistoryQueryByPool = gql`
query TransactionHistoryByPool($user: String, $pool: String) { query TransactionHistoryByPool($user: String, $pool: String) {

View File

@ -38,6 +38,7 @@ import { secondsToString } from '../../../../utils/metadata'
import { AssetSelectionAsset } from '../../../molecules/FormFields/AssetSelection' import { AssetSelectionAsset } from '../../../molecules/FormFields/AssetSelection'
import AlgorithmDatasetsListForCompute from '../../AssetContent/AlgorithmDatasetsListForCompute' import AlgorithmDatasetsListForCompute from '../../AssetContent/AlgorithmDatasetsListForCompute'
import { getPreviousOrders, getPrice } from '../../../../utils/subgraph' import { getPreviousOrders, getPrice } from '../../../../utils/subgraph'
import { chainIds } from '../../../../../app.config'
const SuccessAction = () => ( const SuccessAction = () => (
<Button style="text" to="/history?defaultTab=ComputeJobs" size="small"> <Button style="text" to="/history?defaultTab=ComputeJobs" size="small">
@ -153,7 +154,6 @@ export default function Compute({
getQuerryString( getQuerryString(
computeService.attributes.main.privacy.publisherTrustedAlgorithms computeService.attributes.main.privacy.publisherTrustedAlgorithms
), ),
appConfig.metadataCacheUri,
source.token source.token
) )
setDdoAlgorithmList(gueryResults.results) setDdoAlgorithmList(gueryResults.results)
@ -161,7 +161,6 @@ export default function Compute({
algorithmSelectionList = await transformDDOToAssetSelection( algorithmSelectionList = await transformDDOToAssetSelection(
datasetComputeService?.serviceEndpoint, datasetComputeService?.serviceEndpoint,
gueryResults.results, gueryResults.results,
appConfig.metadataCacheUri,
[] []
) )
} }

View File

@ -17,6 +17,7 @@ import { ComputePrivacyForm } from '../../../../models/FormEditComputeDataset'
import { publisherTrustedAlgorithm as PublisherTrustedAlgorithm } from '@oceanprotocol/lib' import { publisherTrustedAlgorithm as PublisherTrustedAlgorithm } from '@oceanprotocol/lib'
import axios from 'axios' import axios from 'axios'
import { useSiteMetadata } from '../../../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../../../hooks/useSiteMetadata'
import { chainIds } from '../../../../../app.config'
export default function FormEditComputeDataset({ export default function FormEditComputeDataset({
data, data,
@ -51,16 +52,11 @@ export default function FormEditComputeDataset({
}, },
sort: { created: -1 } sort: { created: -1 }
} }
const querryResult = await queryMetadata( const querryResult = await queryMetadata(query, source.token)
query,
appConfig.metadataCacheUri,
source.token
)
const datasetComputeService = ddo.findServiceByType('compute') const datasetComputeService = ddo.findServiceByType('compute')
const algorithmSelectionList = await transformDDOToAssetSelection( const algorithmSelectionList = await transformDDOToAssetSelection(
datasetComputeService?.serviceEndpoint, datasetComputeService?.serviceEndpoint,
querryResult.results, querryResult.results,
appConfig.metadataCacheUri,
publisherTrustedAlgorithms publisherTrustedAlgorithms
) )
return algorithmSelectionList return algorithmSelectionList

View File

@ -20,6 +20,7 @@ export default function MetaMain(): ReactElement {
<AssetType <AssetType
type={type} type={type}
accessType={accessType} accessType={accessType}
chainId={ddo.chainId}
className={styles.assetType} className={styles.assetType}
/> />
<ExplorerLink <ExplorerLink

View File

@ -50,11 +50,7 @@ function DetailsAssets({ job }: { job: ComputeJobMetaData }) {
async function getAlgoMetadata() { async function getAlgoMetadata() {
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
const ddo = await retrieveDDO( const ddo = await retrieveDDO(job.algoDID, source.token)
job.algoDID,
appConfig.metadataCacheUri,
source.token
)
setAlgoDtSymbol(ddo.dataTokenInfo.symbol) setAlgoDtSymbol(ddo.dataTokenInfo.symbol)
const { attributes } = ddo.findServiceByType('metadata') const { attributes } = ddo.findServiceByType('metadata')

View File

@ -10,7 +10,10 @@ import Button from '../../../atoms/Button'
import { useOcean } from '../../../../providers/Ocean' import { useOcean } from '../../../../providers/Ocean'
import { gql, useQuery } from '@apollo/client' import { gql, useQuery } from '@apollo/client'
import { useWeb3 } from '../../../../providers/Web3' import { useWeb3 } from '../../../../providers/Web3'
import { queryMetadata } from '../../../../utils/aquarius' import {
queryMetadata,
transformChainIdsListToQuery
} from '../../../../utils/aquarius'
import axios, { CancelToken } from 'axios' import axios, { CancelToken } from 'axios'
import { ComputeOrders } from '../../../../@types/apollo/ComputeOrders' import { ComputeOrders } from '../../../../@types/apollo/ComputeOrders'
import Details from './Details' 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 { ReactComponent as Refresh } from '../../../../images/refresh.svg'
import styles from './index.module.css' import styles from './index.module.css'
import { useSiteMetadata } from '../../../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../../../hooks/useSiteMetadata'
import { useUserPreferences } from '../../../../providers/UserPreferences'
const getComputeOrders = gql` const getComputeOrders = gql`
query ComputeOrders($user: String!) { query ComputeOrders($user: String!) {
@ -84,31 +88,35 @@ const columns = [
async function getAssetMetadata( async function getAssetMetadata(
queryDtList: string, queryDtList: string,
metadataCacheUri: string, cancelToken: CancelToken,
cancelToken: CancelToken chainIds: number[]
): Promise<DDO[]> { ): Promise<DDO[]> {
const queryDid = { const queryDid = {
page: 1, page: 1,
offset: 100, offset: 100,
query: { query: {
query_string: { 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'] fields: ['dataToken']
} }
} }
} }
const result = await queryMetadata(queryDid, metadataCacheUri, cancelToken) const result = await queryMetadata(queryDid, cancelToken)
return result.results return result.results
} }
export default function ComputeJobs(): ReactElement { export default function ComputeJobs(): ReactElement {
const { appConfig } = useSiteMetadata()
const { ocean, account, config } = useOcean() const { ocean, account, config } = useOcean()
const { accountId } = useWeb3() const { accountId } = useWeb3()
const [isLoading, setIsLoading] = useState(true) const [isLoading, setIsLoading] = useState(true)
const [jobs, setJobs] = useState<ComputeJobMetaData[]>([]) const [jobs, setJobs] = useState<ComputeJobMetaData[]>([])
const { chainIds } = useUserPreferences()
const { data, refetch } = useQuery<ComputeOrders>(getComputeOrders, { const { data, refetch } = useQuery<ComputeOrders>(getComputeOrders, {
variables: { variables: {
user: accountId?.toLowerCase() user: accountId?.toLowerCase()
@ -116,8 +124,7 @@ export default function ComputeJobs(): ReactElement {
}) })
async function getJobs() { async function getJobs() {
if (!ocean || !account) return if (!accountId) return
setIsLoading(true) setIsLoading(true)
await refetch() await refetch()
@ -133,11 +140,7 @@ export default function ComputeJobs(): ReactElement {
try { try {
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
const assets = await getAssetMetadata( const assets = await getAssetMetadata(queryDtList, source.token, chainIds)
queryDtList,
appConfig.metadataCacheUri,
source.token
)
const providers: Provider[] = [] const providers: Provider[] = []
const serviceEndpoints: string[] = [] const serviceEndpoints: string[] = []
for (let i = 0; i < data.tokenOrders.length; i++) { for (let i = 0; i < data.tokenOrders.length; i++) {
@ -239,12 +242,12 @@ export default function ComputeJobs(): ReactElement {
} }
useEffect(() => { useEffect(() => {
if (data === undefined || !appConfig.metadataCacheUri) { if (data === undefined || !chainIds) {
setIsLoading(false) setIsLoading(false)
return return
} }
getJobs() getJobs()
}, [ocean, account, data, appConfig.metadataCacheUri]) }, [ocean, account, data, chainIds])
return ( return (
<> <>

View File

@ -76,11 +76,7 @@ export default function ComputeDownloads(): ReactElement {
const did = web3.utils const did = web3.utils
.toChecksumAddress(data.tokenOrders[i].datatokenId.address) .toChecksumAddress(data.tokenOrders[i].datatokenId.address)
.replace('0x', 'did:op:') .replace('0x', 'did:op:')
const ddo = await retrieveDDO( const ddo = await retrieveDDO(did, source.token)
did,
appConfig.metadataCacheUri,
source.token
)
if (ddo.service[1].type === 'access') { if (ddo.service[1].type === 'access') {
filteredOrders.push({ filteredOrders.push({
did: did, did: did,

View File

@ -3,7 +3,10 @@ import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/Metadata
import React, { ReactElement, useEffect, useState } from 'react' import React, { ReactElement, useEffect, useState } from 'react'
import AssetList from '../../organisms/AssetList' import AssetList from '../../organisms/AssetList'
import axios from 'axios' import axios from 'axios'
import { queryMetadata } from '../../../utils/aquarius' import {
queryMetadata,
transformChainIdsListToQuery
} from '../../../utils/aquarius'
import { useWeb3 } from '../../../providers/Web3' import { useWeb3 } from '../../../providers/Web3'
import { useSiteMetadata } from '../../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
import { useUserPreferences } from '../../../providers/UserPreferences' import { useUserPreferences } from '../../../providers/UserPreferences'
@ -27,7 +30,9 @@ export default function PublishedList(): ReactElement {
offset: 9, offset: 9,
query: { query: {
query_string: { query_string: {
query: `(publicKey.owner:${accountId})` query: `(publicKey.owner:${accountId}) AND (${transformChainIdsListToQuery(
chainIds
)})`
} }
}, },
sort: { created: -1 } sort: { created: -1 }
@ -36,11 +41,7 @@ export default function PublishedList(): ReactElement {
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
queryResult || setIsLoading(true) queryResult || setIsLoading(true)
const result = await queryMetadata( const result = await queryMetadata(queryPublishedAssets, source.token)
queryPublishedAssets,
appConfig.metadataCacheUri,
source.token
)
setQueryResult(result) setQueryResult(result)
} catch (error) { } catch (error) {
Logger.error(error.message) Logger.error(error.message)

View File

@ -10,7 +10,10 @@ import Container from '../atoms/Container'
import Button from '../atoms/Button' import Button from '../atoms/Button'
import Bookmarks from '../molecules/Bookmarks' import Bookmarks from '../molecules/Bookmarks'
import axios from 'axios' import axios from 'axios'
import { queryMetadata } from '../../utils/aquarius' import {
queryMetadata,
transformChainIdsListToQuery
} from '../../utils/aquarius'
import Permission from '../organisms/Permission' import Permission from '../organisms/Permission'
import { getHighestLiquidityDIDs } from '../../utils/subgraph' import { getHighestLiquidityDIDs } from '../../utils/subgraph'
import { DDO, Logger } from '@oceanprotocol/lib' import { DDO, Logger } from '@oceanprotocol/lib'
@ -28,7 +31,9 @@ async function getQueryHighest(
offset: 15, offset: 15,
query: { query: {
query_string: { query_string: {
query: `(${dids}) AND -isInPurgatory:true`, query: `(${dids}) AND (${transformChainIdsListToQuery(
chainIds
)}) AND -isInPurgatory:true`,
fields: ['dataToken'] fields: ['dataToken']
} }
} }
@ -44,7 +49,9 @@ function getQueryLatest(chainIds: number[]): SearchQuery {
offset: 9, offset: 9,
query: { query: {
query_string: { query_string: {
query: `-isInPurgatory:true` query: `(${transformChainIdsListToQuery(
chainIds
)}) AND -isInPurgatory:true `
} }
}, },
sort: { created: -1 } sort: { created: -1 }
@ -72,6 +79,7 @@ function SectionQueryResult({
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
const [result, setResult] = useState<QueryResult>() const [result, setResult] = useState<QueryResult>()
const [loading, setLoading] = useState<boolean>() const [loading, setLoading] = useState<boolean>()
const { chainIds } = useUserPreferences()
useEffect(() => { useEffect(() => {
if (!appConfig.metadataCacheUri) return if (!appConfig.metadataCacheUri) return
@ -80,11 +88,7 @@ function SectionQueryResult({
async function init() { async function init() {
try { try {
setLoading(true) setLoading(true)
const result = await queryMetadata( const result = await queryMetadata(query, source.token)
query,
appConfig.metadataCacheUri,
source.token
)
if (queryData && result.totalResults > 0 && result.totalResults <= 15) { if (queryData && result.totalResults > 0 && result.totalResults <= 15) {
const searchDIDs = queryData.split(' ') const searchDIDs = queryData.split(' ')
const sortedAssets = sortElements(result.results, searchDIDs) const sortedAssets = sortElements(result.results, searchDIDs)

View File

@ -10,6 +10,7 @@ import { getResults } from './utils'
import { navigate } from 'gatsby' import { navigate } from 'gatsby'
import { updateQueryStringParameter } from '../../../utils' import { updateQueryStringParameter } from '../../../utils'
import { useSiteMetadata } from '../../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../../hooks/useSiteMetadata'
import { useUserPreferences } from '../../../providers/UserPreferences'
export default function SearchPage({ export default function SearchPage({
location, location,
@ -21,6 +22,7 @@ export default function SearchPage({
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
const parsed = queryString.parse(location.search) const parsed = queryString.parse(location.search)
const { text, owner, tags, page, sort, sortOrder, serviceType } = parsed const { text, owner, tags, page, sort, sortOrder, serviceType } = parsed
const { chainIds } = useUserPreferences()
const [queryResult, setQueryResult] = useState<QueryResult>() const [queryResult, setQueryResult] = useState<QueryResult>()
const [loading, setLoading] = useState<boolean>() const [loading, setLoading] = useState<boolean>()
const [service, setServiceType] = useState<string>(serviceType as string) const [service, setServiceType] = useState<string>(serviceType as string)
@ -34,7 +36,11 @@ export default function SearchPage({
async function initSearch() { async function initSearch() {
setLoading(true) setLoading(true)
setTotalResults(undefined) setTotalResults(undefined)
const queryResult = await getResults(parsed, appConfig.metadataCacheUri) const queryResult = await getResults(
parsed,
appConfig.metadataCacheUri,
chainIds
)
setQueryResult(queryResult) setQueryResult(queryResult)
setTotalResults(queryResult.totalResults) setTotalResults(queryResult.totalResults)
setLoading(false) setLoading(false)
@ -48,7 +54,8 @@ export default function SearchPage({
page, page,
serviceType, serviceType,
sortOrder, sortOrder,
appConfig.metadataCacheUri appConfig.metadataCacheUri,
chainIds
]) ])
function setPage(page: number) { function setPage(page: number) {

View File

@ -1,6 +1,11 @@
import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache' import { QueryResult } from '@oceanprotocol/lib/dist/node/metadatacache/MetadataCache'
import { MetadataCache, Logger } from '@oceanprotocol/lib' import { MetadataCache, Logger } from '@oceanprotocol/lib'
import {
queryMetadata,
transformChainIdsListToQuery
} from '../../../utils/aquarius'
import queryString from 'query-string' import queryString from 'query-string'
import axios from 'axios'
export const SortTermOptions = { export const SortTermOptions = {
Created: 'created', Created: 'created',
@ -46,6 +51,7 @@ function getSortType(sortParam: string): string {
} }
export function getSearchQuery( export function getSearchQuery(
chainIds: number[],
text?: string, text?: string,
owner?: string, owner?: string,
tags?: string, tags?: string,
@ -137,6 +143,11 @@ export function getSearchQuery(
] ]
} }
}, },
{
query_string: {
query: `${transformChainIdsListToQuery(chainIds)}`
}
},
{ {
term: { term: {
isInPurgatory: false isInPurgatory: false
@ -163,7 +174,8 @@ export async function getResults(
sortOrder?: string sortOrder?: string
serviceType?: string serviceType?: string
}, },
metadataCacheUri: string metadataCacheUri: string,
chainIds: number[]
): Promise<QueryResult> { ): Promise<QueryResult> {
const { const {
text, text,
@ -176,9 +188,9 @@ export async function getResults(
sortOrder, sortOrder,
serviceType serviceType
} = params } = params
const metadataCache = new MetadataCache(metadataCacheUri, Logger)
const searchQuery = getSearchQuery( const searchQuery = getSearchQuery(
chainIds,
text, text,
owner, owner,
tags, tags,
@ -189,7 +201,9 @@ export async function getResults(
sortOrder, sortOrder,
serviceType 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 return queryResult
} }

View File

@ -14,14 +14,13 @@ import axios, { CancelToken } from 'axios'
import { retrieveDDO } from '../utils/aquarius' import { retrieveDDO } from '../utils/aquarius'
import { getPrice } from '../utils/subgraph' import { getPrice } from '../utils/subgraph'
import { MetadataMarket } from '../@types/MetaData' import { MetadataMarket } from '../@types/MetaData'
import { DDO_TEMPORARY } from './Ocean'
import { useWeb3 } from './Web3' import { useWeb3 } from './Web3'
import { useSiteMetadata } from '../hooks/useSiteMetadata' import { useSiteMetadata } from '../hooks/useSiteMetadata'
interface AssetProviderValue { interface AssetProviderValue {
isInPurgatory: boolean isInPurgatory: boolean
purgatoryData: PurgatoryData purgatoryData: PurgatoryData
ddo: DDO ddo: any
did: string did: string
metadata: MetadataMarket metadata: MetadataMarket
title: string title: string
@ -51,7 +50,7 @@ function AssetProvider({
const { networkId } = useWeb3() const { networkId } = useWeb3()
const [isInPurgatory, setIsInPurgatory] = useState(false) const [isInPurgatory, setIsInPurgatory] = useState(false)
const [purgatoryData, setPurgatoryData] = useState<PurgatoryData>() const [purgatoryData, setPurgatoryData] = useState<PurgatoryData>()
const [ddo, setDDO] = useState<DDO>() const [ddo, setDDO] = useState<any>()
const [did, setDID] = useState<string>() const [did, setDID] = useState<string>()
const [metadata, setMetadata] = useState<MetadataMarket>() const [metadata, setMetadata] = useState<MetadataMarket>()
const [title, setTitle] = useState<string>() const [title, setTitle] = useState<string>()
@ -65,11 +64,7 @@ function AssetProvider({
const fetchDdo = async (token?: CancelToken) => { const fetchDdo = async (token?: CancelToken) => {
Logger.log('[asset] Init asset, get DDO') Logger.log('[asset] Init asset, get DDO')
setLoading(true) setLoading(true)
const ddo = await retrieveDDO( const ddo = await retrieveDDO(asset as string, token)
asset as string,
appConfig.metadataCacheUri,
token
)
if (!ddo) { if (!ddo) {
setError( 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 if (!ddo) return
setLoading(true) setLoading(true)
const returnedPrice = await getPrice(ddo) const returnedPrice = await getPrice(ddo)
@ -155,7 +150,7 @@ function AssetProvider({
if (!networkId || !ddo) return if (!networkId || !ddo) return
// TODO: remove typing once present in ocean.js' DDO typing // 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) setIsAssetNetwork(isAssetNetwork)
}, [networkId, ddo]) }, [networkId, ddo])

View File

@ -28,11 +28,6 @@ interface OceanProviderValue {
const OceanContext = createContext({} as 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 { function OceanProvider({ children }: { children: ReactNode }): ReactElement {
const { web3, accountId } = useWeb3() const { web3, accountId } = useWeb3()
const { ddo } = useAsset() const { ddo } = useAsset()
@ -71,13 +66,13 @@ function OceanProvider({ children }: { children: ReactNode }): ReactElement {
// ----------------------------------- // -----------------------------------
useEffect(() => { useEffect(() => {
// TODO: remove DDO typing once ocean.js has it // TODO: remove DDO typing once ocean.js has it
if (!(ddo as DDO_TEMPORARY)?.chainId) return if (!ddo?.chainId) return
const config = { const config = {
...getOceanConfig((ddo as DDO_TEMPORARY)?.chainId), ...getOceanConfig(ddo?.chainId),
// add local dev values // add local dev values
...((ddo as DDO_TEMPORARY)?.chainId === 8996 && { ...(ddo?.chainId === 8996 && {
...getDevelopmentConfig() ...getDevelopmentConfig()
}) })
} }

View File

@ -12,7 +12,6 @@ import {
import { AssetSelectionAsset } from '../components/molecules/FormFields/AssetSelection' import { AssetSelectionAsset } from '../components/molecules/FormFields/AssetSelection'
import { PriceList, getAssetsPriceList } from './subgraph' import { PriceList, getAssetsPriceList } from './subgraph'
import axios, { CancelToken, AxiosResponse } from 'axios' import axios, { CancelToken, AxiosResponse } from 'axios'
import { DDO_TEMPORARY } from '../providers/Ocean'
function getQueryForAlgorithmDatasets(algorithmDid: string) { function getQueryForAlgorithmDatasets(algorithmDid: string) {
return { 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( export async function queryMetadata(
query: SearchQuery, query: SearchQuery,
metadataCacheUri: string,
cancelToken: CancelToken cancelToken: CancelToken
): Promise<QueryResult> { ): Promise<any> {
try { try {
const response: AxiosResponse<QueryResult> = await axios.post( const response: AxiosResponse<any> = await axios.post(
`${metadataCacheUri}/api/v1/aquarius/assets/ddo/query`, `https://multiaqua.oceanprotocol.com/api/v1/aquarius/assets/ddo/query`,
{ ...query, cancelToken } { ...query, cancelToken }
) )
if (!response || response.status !== 200 || !response.data) return if (!response || response.status !== 200 || !response.data) return
return transformQueryResult(response.data) return transformQueryResult(response.data)
} catch (error) { } catch (error) {
if (axios.isCancel(error)) { if (axios.isCancel(error)) {
@ -74,19 +80,17 @@ export async function queryMetadata(
export async function retrieveDDO( export async function retrieveDDO(
did: string | DID, did: string | DID,
metadataCacheUri: string,
cancelToken: CancelToken cancelToken: CancelToken
): Promise<DDO_TEMPORARY> { ): Promise<DDO> {
try { try {
const response: AxiosResponse<DDO> = await axios.get( 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 } { cancelToken }
) )
if (!response || response.status !== 200 || !response.data) return 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 }
const data = { ...response.data, chainId: 1 } return new DDO(data)
return new DDO(data) as DDO_TEMPORARY
} catch (error) { } catch (error) {
if (axios.isCancel(error)) { if (axios.isCancel(error)) {
Logger.log(error.message) Logger.log(error.message)
@ -98,12 +102,11 @@ export async function retrieveDDO(
export async function getAssetsNames( export async function getAssetsNames(
didList: string[] | DID[], didList: string[] | DID[],
metadataCacheUri: string,
cancelToken: CancelToken cancelToken: CancelToken
): Promise<Record<string, string>> { ): Promise<Record<string, string>> {
try { try {
const response: AxiosResponse<Record<string, string>> = await axios.post( 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, didList,
cancelToken cancelToken
@ -123,7 +126,6 @@ export async function getAssetsNames(
export async function transformDDOToAssetSelection( export async function transformDDOToAssetSelection(
datasetProviderEndpoint: string, datasetProviderEndpoint: string,
ddoList: DDO[], ddoList: DDO[],
metadataCacheUri: string,
selectedAlgorithms?: PublisherTrustedAlgorithm[] selectedAlgorithms?: PublisherTrustedAlgorithm[]
): Promise<AssetSelectionAsset[]> { ): Promise<AssetSelectionAsset[]> {
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
@ -138,7 +140,7 @@ export async function transformDDOToAssetSelection(
algoComputeService?.serviceEndpoint && algoComputeService?.serviceEndpoint &&
(didProviderEndpointMap[ddo.id] = 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[] = [] const algorithmList: AssetSelectionAsset[] = []
didList?.forEach((did: string) => { didList?.forEach((did: string) => {
if ( if (
@ -180,7 +182,6 @@ export async function getAlgorithmDatasetsForCompute(
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
const computeDatasets = await queryMetadata( const computeDatasets = await queryMetadata(
getQueryForAlgorithmDatasets(algorithmId), getQueryForAlgorithmDatasets(algorithmId),
metadataCacheUri,
source.token source.token
) )
const computeDatasetsForCurrentAlgorithm: DDO[] = [] const computeDatasetsForCurrentAlgorithm: DDO[] = []
@ -198,7 +199,6 @@ export async function getAlgorithmDatasetsForCompute(
const datasets = await transformDDOToAssetSelection( const datasets = await transformDDOToAssetSelection(
datasetProviderUri, datasetProviderUri,
computeDatasetsForCurrentAlgorithm, computeDatasetsForCurrentAlgorithm,
metadataCacheUri,
[] []
) )
return datasets return datasets