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,
|
dataTokenAddress: string,
|
||||||
algorithmRawCode: string,
|
algorithmRawCode: string,
|
||||||
computeContainer: ComputeValue,
|
computeContainer: ComputeValue,
|
||||||
marketFeeAddress?: string
|
marketFeeAddress?: string,
|
||||||
|
orderId?: string
|
||||||
): Promise<ComputeJob | void> {
|
): Promise<ComputeJob | void> {
|
||||||
if (!ocean || !account) return
|
if (!ocean || !account) return
|
||||||
|
|
||||||
setComputeError(undefined)
|
setComputeError(undefined)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
setStep(0)
|
setStep(0)
|
||||||
|
rawAlgorithmMeta.container = computeContainer
|
||||||
|
rawAlgorithmMeta.rawcode = algorithmRawCode
|
||||||
|
const output = {}
|
||||||
|
if (!orderId) {
|
||||||
const userOwnedTokens = await ocean.accounts.getTokenBalance(
|
const userOwnedTokens = await ocean.accounts.getTokenBalance(
|
||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
account
|
account
|
||||||
@ -73,9 +75,6 @@ function useCompute(): UseCompute {
|
|||||||
if (parseFloat(userOwnedTokens) < 1) {
|
if (parseFloat(userOwnedTokens) < 1) {
|
||||||
setComputeError('Not enough datatokens')
|
setComputeError('Not enough datatokens')
|
||||||
} else {
|
} else {
|
||||||
rawAlgorithmMeta.container = computeContainer
|
|
||||||
rawAlgorithmMeta.rawcode = algorithmRawCode
|
|
||||||
const output = {}
|
|
||||||
Logger.log(
|
Logger.log(
|
||||||
'compute order',
|
'compute order',
|
||||||
accountId,
|
accountId,
|
||||||
@ -84,7 +83,7 @@ function useCompute(): UseCompute {
|
|||||||
rawAlgorithmMeta,
|
rawAlgorithmMeta,
|
||||||
marketFeeAddress
|
marketFeeAddress
|
||||||
)
|
)
|
||||||
const tokenTransfer = await ocean.compute.order(
|
orderId = await ocean.compute.order(
|
||||||
accountId,
|
accountId,
|
||||||
did,
|
did,
|
||||||
computeService.index,
|
computeService.index,
|
||||||
@ -93,10 +92,13 @@ function useCompute(): UseCompute {
|
|||||||
marketFeeAddress
|
marketFeeAddress
|
||||||
)
|
)
|
||||||
setStep(1)
|
setStep(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
setStep(2)
|
setStep(2)
|
||||||
|
if (orderId) {
|
||||||
const response = await ocean.compute.start(
|
const response = await ocean.compute.start(
|
||||||
did,
|
did,
|
||||||
tokenTransfer,
|
orderId,
|
||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
account,
|
account,
|
||||||
undefined,
|
undefined,
|
||||||
|
@ -32,7 +32,8 @@ function useConsume(): UseConsume {
|
|||||||
did: DID | string,
|
did: DID | string,
|
||||||
dataTokenAddress: string,
|
dataTokenAddress: string,
|
||||||
serviceType: ServiceType = 'access',
|
serviceType: ServiceType = 'access',
|
||||||
marketFeeAddress: string
|
marketFeeAddress: string,
|
||||||
|
orderId?: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!ocean || !account || !accountId) return
|
if (!ocean || !account || !accountId) return
|
||||||
|
|
||||||
@ -41,6 +42,8 @@ function useConsume(): UseConsume {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
setStep(0)
|
setStep(0)
|
||||||
|
if (!orderId) {
|
||||||
|
// if we don't have a previous valid order, get one
|
||||||
const userOwnedTokens = await ocean.accounts.getTokenBalance(
|
const userOwnedTokens = await ocean.accounts.getTokenBalance(
|
||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
account
|
account
|
||||||
@ -49,26 +52,27 @@ function useConsume(): UseConsume {
|
|||||||
setConsumeError('Not enough datatokens')
|
setConsumeError('Not enough datatokens')
|
||||||
} else {
|
} else {
|
||||||
setStep(1)
|
setStep(1)
|
||||||
ocean.datatokens.generateDtName()
|
orderId = await ocean.assets.order(
|
||||||
const tokenTransfer = await ocean.assets.order(
|
|
||||||
did as string,
|
did as string,
|
||||||
serviceType,
|
serviceType,
|
||||||
accountId,
|
accountId,
|
||||||
undefined,
|
undefined,
|
||||||
marketFeeAddress
|
marketFeeAddress
|
||||||
)
|
)
|
||||||
Logger.log('order created', tokenTransfer)
|
Logger.log('order created', orderId)
|
||||||
setStep(2)
|
setStep(2)
|
||||||
|
}
|
||||||
|
}
|
||||||
setStep(3)
|
setStep(3)
|
||||||
|
if (orderId)
|
||||||
await ocean.assets.download(
|
await ocean.assets.download(
|
||||||
did as string,
|
did as string,
|
||||||
tokenTransfer,
|
orderId,
|
||||||
dataTokenAddress,
|
dataTokenAddress,
|
||||||
account,
|
account,
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
setStep(4)
|
setStep(4)
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setConsumeError(error.message)
|
setConsumeError(error.message)
|
||||||
Logger.error(error)
|
Logger.error(error)
|
||||||
|
Loading…
Reference in New Issue
Block a user