From defbde1e6fee73d28412e08a357235d90f409f8b Mon Sep 17 00:00:00 2001 From: mihaisc Date: Thu, 14 May 2020 16:04:20 +0300 Subject: [PATCH] added isLoading to compute and log error --- src/hooks/useCompute/useCompute.ts | 9 +++++++-- src/hooks/useConsume/useConsume.ts | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hooks/useCompute/useCompute.ts b/src/hooks/useCompute/useCompute.ts index 93ac616..24080e2 100644 --- a/src/hooks/useCompute/useCompute.ts +++ b/src/hooks/useCompute/useCompute.ts @@ -1,5 +1,5 @@ import { useState } from 'react' -import { DID, MetaDataAlgorithm } from '@oceanprotocol/squid' +import { DID, MetaDataAlgorithm, Logger } from '@oceanprotocol/squid' import { useOcean } from '../../providers' import { ComputeValue } from './ComputeOptions' import { feedback } from './../../utils' @@ -12,6 +12,7 @@ interface UseCompute { computeStep?: number computeStepText?: string computeError?: string + isLoading: boolean } // TODO: customize for compute @@ -35,6 +36,7 @@ function useCompute(): UseCompute { const [computeStep, setComputeStep] = useState() const [computeStepText, setComputeStepText] = useState() const [computeError, setComputeError] = useState() + const [isLoading, setIsLoading] = useState(false) async function compute( did: DID | string, @@ -46,6 +48,7 @@ function useCompute(): UseCompute { setComputeError(undefined) try { + setIsLoading(true) const computeOutput = { publishAlgorithmLog: false, publishOutput: false, @@ -76,13 +79,15 @@ function useCompute(): UseCompute { computeOutput ) } catch (error) { + Logger.log(error) setComputeError(error.message) } finally { setComputeStep(undefined) + setIsLoading(false) } } - return { compute, computeStep, computeStepText, computeError } + return { compute, computeStep, computeStepText, computeError, isLoading } } export { useCompute, UseCompute } diff --git a/src/hooks/useConsume/useConsume.ts b/src/hooks/useConsume/useConsume.ts index d1efb9b..5e68a90 100644 --- a/src/hooks/useConsume/useConsume.ts +++ b/src/hooks/useConsume/useConsume.ts @@ -51,7 +51,6 @@ function useConsume(): UseConsume { setConsumeStepText(consumeFeedback[4]) await ocean.assets.consume(agreementId, did as string, account, '') } catch (error) { - console.log(error) setConsumeError(error.message) } finally { setConsumeStep(undefined)