From ca2a0ec0d4ae360f85156727c4f5bd8e296aeb6f Mon Sep 17 00:00:00 2001 From: mihaisc Date: Wed, 27 May 2020 17:12:24 +0300 Subject: [PATCH] compute fix --- src/hooks/useCompute/useCompute.ts | 5 ++- src/hooks/useSearch/useSearch.ts | 52 ++++++++++++++++++------------ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/hooks/useCompute/useCompute.ts b/src/hooks/useCompute/useCompute.ts index 157e327..9f16e42 100644 --- a/src/hooks/useCompute/useCompute.ts +++ b/src/hooks/useCompute/useCompute.ts @@ -3,6 +3,7 @@ import { DID, MetaDataAlgorithm, Logger } from '@oceanprotocol/squid' import { useOcean } from '../../providers' import { ComputeValue } from './ComputeOptions' import { feedback } from './../../utils' +import { LoggerInstance } from '@oceanprotocol/squid/dist/node/utils/Logger' interface UseCompute { compute: ( did: DID | string, @@ -59,15 +60,13 @@ function useCompute(): UseCompute { owner: accountId, secretStoreUri: config.secretStoreUri } - Logger.debug('useCompute computeOutput', computeOutput) - const agreement = await ocean.compute .order(account, did as string) .next((step: number) => { setComputeStep(step) setComputeStepText(computeFeedback[step]) }) - Logger.debug('useCompute agreement', agreement) + rawAlgorithmMeta.container = computeContainer rawAlgorithmMeta.rawcode = algorithmRawCode setComputeStep(4) diff --git a/src/hooks/useSearch/useSearch.ts b/src/hooks/useSearch/useSearch.ts index f426545..7922608 100644 --- a/src/hooks/useSearch/useSearch.ts +++ b/src/hooks/useSearch/useSearch.ts @@ -65,13 +65,17 @@ function useSearch(): UseSearch { 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 + try { + 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 + } + } catch (err) { + Logger.error(err) } }) ) @@ -87,25 +91,33 @@ function useSearch(): UseSearch { const computeItems = await Promise.all( jobList.map(async (job) => { if (!job) return - const { did } = await ocean.keeper.agreementStoreManager.getAgreement( - job.agreementId - ) + try { + 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 } + const ddo = await ocean.assets.resolve(did) + if ( + did === + '0x0000000000000000000000000000000000000000000000000000000000000000' + ) + return + 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 } + } } + } catch (err) { + Logger.error(err) } }) ) const filteredComputeItems = computeItems.filter( - (value) => typeof value.ddo !== 'undefined' + (value) => value !== undefined && typeof value.ddo !== 'undefined' ) return filteredComputeItems }