1
0
mirror of https://github.com/oceanprotocol/react.git synced 2025-02-14 21:10:38 +01:00

added isLoading to compute and log error

This commit is contained in:
mihaisc 2020-05-14 16:04:20 +03:00
parent 879f818590
commit defbde1e6f
2 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import { useState } from 'react' import { useState } from 'react'
import { DID, MetaDataAlgorithm } from '@oceanprotocol/squid' import { DID, MetaDataAlgorithm, Logger } from '@oceanprotocol/squid'
import { useOcean } from '../../providers' import { useOcean } from '../../providers'
import { ComputeValue } from './ComputeOptions' import { ComputeValue } from './ComputeOptions'
import { feedback } from './../../utils' import { feedback } from './../../utils'
@ -12,6 +12,7 @@ interface UseCompute {
computeStep?: number computeStep?: number
computeStepText?: string computeStepText?: string
computeError?: string computeError?: string
isLoading: boolean
} }
// TODO: customize for compute // TODO: customize for compute
@ -35,6 +36,7 @@ function useCompute(): UseCompute {
const [computeStep, setComputeStep] = useState<number | undefined>() const [computeStep, setComputeStep] = useState<number | undefined>()
const [computeStepText, setComputeStepText] = useState<string | undefined>() const [computeStepText, setComputeStepText] = useState<string | undefined>()
const [computeError, setComputeError] = useState<string | undefined>() const [computeError, setComputeError] = useState<string | undefined>()
const [isLoading, setIsLoading] = useState(false)
async function compute( async function compute(
did: DID | string, did: DID | string,
@ -46,6 +48,7 @@ function useCompute(): UseCompute {
setComputeError(undefined) setComputeError(undefined)
try { try {
setIsLoading(true)
const computeOutput = { const computeOutput = {
publishAlgorithmLog: false, publishAlgorithmLog: false,
publishOutput: false, publishOutput: false,
@ -76,13 +79,15 @@ function useCompute(): UseCompute {
computeOutput computeOutput
) )
} catch (error) { } catch (error) {
Logger.log(error)
setComputeError(error.message) setComputeError(error.message)
} finally { } finally {
setComputeStep(undefined) setComputeStep(undefined)
setIsLoading(false)
} }
} }
return { compute, computeStep, computeStepText, computeError } return { compute, computeStep, computeStepText, computeError, isLoading }
} }
export { useCompute, UseCompute } export { useCompute, UseCompute }

View File

@ -51,7 +51,6 @@ function useConsume(): UseConsume {
setConsumeStepText(consumeFeedback[4]) setConsumeStepText(consumeFeedback[4])
await ocean.assets.consume(agreementId, did as string, account, '') await ocean.assets.consume(agreementId, did as string, account, '')
} catch (error) { } catch (error) {
console.log(error)
setConsumeError(error.message) setConsumeError(error.message)
} finally { } finally {
setConsumeStep(undefined) setConsumeStep(undefined)