Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

Commit

Permalink
added isLoading to compute and log error
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaisc committed May 14, 2020
1 parent 879f818 commit defbde1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/hooks/useCompute/useCompute.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -12,6 +12,7 @@ interface UseCompute {
computeStep?: number
computeStepText?: string
computeError?: string
isLoading: boolean
}

// TODO: customize for compute
Expand All @@ -35,6 +36,7 @@ function useCompute(): UseCompute {
const [computeStep, setComputeStep] = useState<number | undefined>()
const [computeStepText, setComputeStepText] = useState<string | undefined>()
const [computeError, setComputeError] = useState<string | undefined>()
const [isLoading, setIsLoading] = useState(false)

async function compute(
did: DID | string,
Expand All @@ -46,6 +48,7 @@ function useCompute(): UseCompute {
setComputeError(undefined)

try {
setIsLoading(true)
const computeOutput = {
publishAlgorithmLog: false,
publishOutput: false,
Expand Down Expand Up @@ -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 }
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useConsume/useConsume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit defbde1

Please sign in to comment.