1
0
mirror of https://github.com/oceanprotocol/react.git synced 2024-12-23 01:29:49 +01:00

usePreviousOrder

This commit is contained in:
alexcos20 2020-10-23 02:02:25 -07:00
parent f9d55343da
commit d9f8be5ca5
2 changed files with 60 additions and 54 deletions

View File

@ -56,47 +56,49 @@ 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)
const userOwnedTokens = await ocean.accounts.getTokenBalance(
dataTokenAddress,
account
)
if (parseFloat(userOwnedTokens) < 1) {
setComputeError('Not enough datatokens')
} else {
rawAlgorithmMeta.container = computeContainer
rawAlgorithmMeta.rawcode = algorithmRawCode
const output = {}
Logger.log(
'compute order',
accountId,
did,
computeService,
rawAlgorithmMeta,
marketFeeAddress
rawAlgorithmMeta.container = computeContainer
rawAlgorithmMeta.rawcode = algorithmRawCode
const output = {}
if (!orderId) {
const userOwnedTokens = await ocean.accounts.getTokenBalance(
dataTokenAddress,
account
)
const tokenTransfer = await ocean.compute.order(
accountId,
did,
computeService.index,
undefined,
rawAlgorithmMeta,
marketFeeAddress
)
setStep(1)
setStep(2)
if (parseFloat(userOwnedTokens) < 1) {
setComputeError('Not enough datatokens')
} else {
Logger.log(
'compute order',
accountId,
did,
computeService,
rawAlgorithmMeta,
marketFeeAddress
)
orderId = await ocean.compute.order(
accountId,
did,
computeService.index,
undefined,
rawAlgorithmMeta,
marketFeeAddress
)
setStep(1)
}
}
setStep(2)
if (orderId) {
const response = await ocean.compute.start(
did,
tokenTransfer,
orderId,
dataTokenAddress,
account,
undefined,

View File

@ -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,34 +42,37 @@ function useConsume(): UseConsume {
try {
setStep(0)
const userOwnedTokens = await ocean.accounts.getTokenBalance(
dataTokenAddress,
account
)
if (parseFloat(userOwnedTokens) < 1) {
setConsumeError('Not enough datatokens')
} else {
setStep(1)
ocean.datatokens.generateDtName()
const tokenTransfer = await ocean.assets.order(
did as string,
serviceType,
accountId,
undefined,
marketFeeAddress
if (!orderId) {
// if we don't have a previous valid order, get one
const userOwnedTokens = await ocean.accounts.getTokenBalance(
dataTokenAddress,
account
)
Logger.log('order created', tokenTransfer)
setStep(2)
setStep(3)
if (parseFloat(userOwnedTokens) < 1) {
setConsumeError('Not enough datatokens')
} else {
setStep(1)
orderId = await ocean.assets.order(
did as string,
serviceType,
accountId,
undefined,
marketFeeAddress
)
Logger.log('order created', orderId)
setStep(2)
}
}
setStep(3)
if (orderId)
await ocean.assets.download(
did as string,
tokenTransfer,
orderId,
dataTokenAddress,
account,
''
)
setStep(4)
}
setStep(4)
} catch (error) {
setConsumeError(error.message)
Logger.error(error)