mirror of
https://github.com/oceanprotocol/react.git
synced 2024-11-22 17:50:15 +01:00
Merge pull request #159 from oceanprotocol/feature/usePreviousValidOrder
usePreviousOrder
This commit is contained in:
commit
6d68bf1db7
@ -56,16 +56,18 @@ function useCompute(): UseCompute {
|
||||
dataTokenAddress: string,
|
||||
algorithmRawCode: string,
|
||||
computeContainer: ComputeValue,
|
||||
marketFeeAddress?: string
|
||||
marketFeeAddress?: string,
|
||||
orderId?: string
|
||||
): Promise<ComputeJob | void> {
|
||||
if (!ocean || !account) return
|
||||
|
||||
setComputeError(undefined)
|
||||
|
||||
try {
|
||||
setIsLoading(true)
|
||||
setStep(0)
|
||||
|
||||
rawAlgorithmMeta.container = computeContainer
|
||||
rawAlgorithmMeta.rawcode = algorithmRawCode
|
||||
const output = {}
|
||||
if (!orderId) {
|
||||
const userOwnedTokens = await ocean.accounts.getTokenBalance(
|
||||
dataTokenAddress,
|
||||
account
|
||||
@ -73,9 +75,6 @@ function useCompute(): UseCompute {
|
||||
if (parseFloat(userOwnedTokens) < 1) {
|
||||
setComputeError('Not enough datatokens')
|
||||
} else {
|
||||
rawAlgorithmMeta.container = computeContainer
|
||||
rawAlgorithmMeta.rawcode = algorithmRawCode
|
||||
const output = {}
|
||||
Logger.log(
|
||||
'compute order',
|
||||
accountId,
|
||||
@ -84,7 +83,7 @@ function useCompute(): UseCompute {
|
||||
rawAlgorithmMeta,
|
||||
marketFeeAddress
|
||||
)
|
||||
const tokenTransfer = await ocean.compute.order(
|
||||
orderId = await ocean.compute.order(
|
||||
accountId,
|
||||
did,
|
||||
computeService.index,
|
||||
@ -93,10 +92,13 @@ function useCompute(): UseCompute {
|
||||
marketFeeAddress
|
||||
)
|
||||
setStep(1)
|
||||
}
|
||||
}
|
||||
setStep(2)
|
||||
if (orderId) {
|
||||
const response = await ocean.compute.start(
|
||||
did,
|
||||
tokenTransfer,
|
||||
orderId,
|
||||
dataTokenAddress,
|
||||
account,
|
||||
undefined,
|
||||
|
@ -32,7 +32,8 @@ function useConsume(): UseConsume {
|
||||
did: DID | string,
|
||||
dataTokenAddress: string,
|
||||
serviceType: ServiceType = 'access',
|
||||
marketFeeAddress: string
|
||||
marketFeeAddress: string,
|
||||
orderId?: string
|
||||
): Promise<void> {
|
||||
if (!ocean || !account || !accountId) return
|
||||
|
||||
@ -41,6 +42,8 @@ function useConsume(): UseConsume {
|
||||
|
||||
try {
|
||||
setStep(0)
|
||||
if (!orderId) {
|
||||
// if we don't have a previous valid order, get one
|
||||
const userOwnedTokens = await ocean.accounts.getTokenBalance(
|
||||
dataTokenAddress,
|
||||
account
|
||||
@ -49,26 +52,27 @@ function useConsume(): UseConsume {
|
||||
setConsumeError('Not enough datatokens')
|
||||
} else {
|
||||
setStep(1)
|
||||
ocean.datatokens.generateDtName()
|
||||
const tokenTransfer = await ocean.assets.order(
|
||||
orderId = await ocean.assets.order(
|
||||
did as string,
|
||||
serviceType,
|
||||
accountId,
|
||||
undefined,
|
||||
marketFeeAddress
|
||||
)
|
||||
Logger.log('order created', tokenTransfer)
|
||||
Logger.log('order created', orderId)
|
||||
setStep(2)
|
||||
}
|
||||
}
|
||||
setStep(3)
|
||||
if (orderId)
|
||||
await ocean.assets.download(
|
||||
did as string,
|
||||
tokenTransfer,
|
||||
orderId,
|
||||
dataTokenAddress,
|
||||
account,
|
||||
''
|
||||
)
|
||||
setStep(4)
|
||||
}
|
||||
} catch (error) {
|
||||
setConsumeError(error.message)
|
||||
Logger.error(error)
|
||||
|
Loading…
Reference in New Issue
Block a user