1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-14 17:24:51 +01:00

fix compute history duplication (#530)

* check provider compute address

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* remove console

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* lock file

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* lib update, lock file fix

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2021-04-16 15:23:09 +03:00 committed by GitHub
parent afca6cfdd3
commit 545be24429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 332 additions and 783 deletions

1055
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,7 @@
"@coingecko/cryptoformat": "^0.4.2",
"@loadable/component": "^5.14.1",
"@oceanprotocol/art": "^3.0.0",
"@oceanprotocol/lib": "0.14.1",
"@oceanprotocol/lib": "0.14.3",
"@oceanprotocol/typographies": "^0.1.0",
"@portis/web3": "^3.0.3",
"@sindresorhus/slugify": "^1.0.0",

View File

@ -2,7 +2,7 @@ import React, { ReactElement, useEffect, useState } from 'react'
import web3 from 'web3'
import Time from '../../../atoms/Time'
import { Link } from 'gatsby'
import { DDO, Logger, Service, ServiceCompute } from '@oceanprotocol/lib'
import { DDO, Logger, Service, Provider } from '@oceanprotocol/lib'
import { ComputeJobMetaData } from '../../../../@types/ComputeJobMetaData'
import Dotdotdot from 'react-dotdotdot'
import Table from '../../../atoms/Table'
@ -14,6 +14,7 @@ import axios, { CancelToken } from 'axios'
import { ComputeOrders } from '../../../../@types/apollo/ComputeOrders'
import Details from './Details'
import styles from './index.module.css'
import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/Compute'
const getComputeOrders = gql`
query ComputeOrders($user: String!) {
@ -119,7 +120,6 @@ export default function ComputeJobs(): ReactElement {
for (let i = 0; i < data.tokenOrders.length; i++) {
dtList.push(data.tokenOrders[i].datatokenId.address)
}
const queryDtList = JSON.stringify(dtList)
.replace(/,/g, ' ')
.replace(/"/g, '')
@ -132,8 +132,8 @@ export default function ComputeJobs(): ReactElement {
config.metadataCacheUri,
source.token
)
const providers: ServiceCompute[] = []
const providers: Provider[] = []
const serviceEndpoints: string[] = []
for (let i = 0; i < data.tokenOrders.length; i++) {
try {
const did = web3.utils
@ -152,29 +152,46 @@ export default function ComputeJobs(): ReactElement {
const { serviceEndpoint } = service
const wasProviderQueried =
providers.filter((x) => x.serviceEndpoint === serviceEndpoint)
.length > 0
serviceEndpoints.filter((x) => x === serviceEndpoint).length > 0
if (wasProviderQueried) continue
providers.push(service as ServiceCompute)
// eslint-disable-next-line no-empty
serviceEndpoints.push(serviceEndpoint)
} catch (err) {
Logger.error(err.message)
Logger.error(err)
}
}
try {
for (let i = 0; i < serviceEndpoints.length; i++) {
const instanceConfig = {
config,
web3: config.web3Provider,
logger: Logger,
ocean: ocean
}
const provider = await Provider.getInstance(instanceConfig)
await provider.setBaseUrl(serviceEndpoints[i])
const hasSameCompute =
providers.filter(
(x) => x.computeAddress === provider.computeAddress
).length > 0
if (!hasSameCompute) providers.push(provider)
}
} catch (err) {
Logger.error(err)
}
for (let i = 0; i < providers.length; i++) {
const computeJob = await ocean.compute.status(
const providerComputeJobs = (await providers[i].computeStatus(
'',
account,
undefined,
undefined,
providers[i],
undefined,
undefined,
false
)
computeJob.sort((a, b) => {
)) as ComputeJob[]
// means the provider uri is not good, so we ignore it and move on
if (!providerComputeJobs) continue
providerComputeJobs.sort((a, b) => {
if (a.dateCreated > b.dateCreated) {
return -1
}
@ -183,10 +200,11 @@ export default function ComputeJobs(): ReactElement {
}
return 0
})
for (let j = 0; j < computeJob.length; j++) {
const job = computeJob[j]
const ddo = assets.filter((x) => x.id === job.inputDID[0])[0]
for (let j = 0; j < providerComputeJobs.length; j++) {
const job = providerComputeJobs[j]
const did = job.inputDID[0]
const ddo = assets.filter((x) => x.id === did)[0]
if (!ddo) continue
const serviceMetadata = ddo.service.filter(
@ -203,7 +221,7 @@ export default function ComputeJobs(): ReactElement {
}
setJobs(computeJobs)
} catch (error) {
Logger.error(error.message)
Logger.log(error.message)
} finally {
setIsLoading(false)
}