1
0
mirror of https://github.com/oceanprotocol/react.git synced 2024-11-26 20:39:02 +01:00
This commit is contained in:
mihaisc 2020-07-15 15:56:35 +03:00
parent 37de32c479
commit 3dc0cf4792

View File

@ -27,22 +27,24 @@ function useConsume(): UseConsume {
const [consumeStepText, setConsumeStepText] = useState<string | undefined>() const [consumeStepText, setConsumeStepText] = useState<string | undefined>()
const [consumeError, setConsumeError] = useState<string | undefined>() const [consumeError, setConsumeError] = useState<string | undefined>()
function setStep(index: number) {
setConsumeStep(index)
setConsumeStepText(consumeFeedback[index])
}
async function consume(did: string, serviceType: ServiceType): Promise<void> { async function consume(did: string, serviceType: ServiceType): Promise<void> {
if (!ocean || !account) return if (!ocean || !account) return
setIsLoading(true) setIsLoading(true)
setConsumeError(undefined) setConsumeError(undefined)
try { try {
setConsumeStep(0) setStep(0)
setConsumeStepText(consumeFeedback[0])
const ddo = await ocean.metadatastore.retrieveDDO(did) const ddo = await ocean.metadatastore.retrieveDDO(did)
Logger.log('ddo retrieved', ddo) Logger.log('ddo retrieved', ddo)
setConsumeStep(1) setStep(1)
setConsumeStepText(consumeFeedback[1])
const order = await ocean.assets.order(did, serviceType, accountId) const order = await ocean.assets.order(did, serviceType, accountId)
Logger.log('order created', order) Logger.log('order created', order)
setConsumeStep(2) setStep(2)
setConsumeStepText(consumeFeedback[2])
const res = JSON.parse(order) const res = JSON.parse(order)
Logger.log('order parsed', res) Logger.log('order parsed', res)
const tokenTransfer = await ocean.datatokens.transfer( const tokenTransfer = await ocean.datatokens.transfer(
@ -52,8 +54,7 @@ function useConsume(): UseConsume {
res.from res.from
) )
Logger.log('token transfered', tokenTransfer) Logger.log('token transfered', tokenTransfer)
setConsumeStep(3) setStep(3)
setConsumeStepText(consumeFeedback[3])
await ocean.assets.download( await ocean.assets.download(
did, did,
(tokenTransfer as any).transactionHash, (tokenTransfer as any).transactionHash,
@ -62,12 +63,12 @@ function useConsume(): UseConsume {
'' ''
) )
setConsumeStep(4) setStep(4)
setConsumeStepText(consumeFeedback[4])
} catch (error) { } catch (error) {
setConsumeError(error.message) setConsumeError(error.message)
} finally { } finally {
setConsumeStep(undefined) setConsumeStep(undefined)
setConsumeStepText(undefined)
setIsLoading(false) setIsLoading(false)
} }
} }