From be21be9559839387b9e1ef7cb876fd9f4d781a9a Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Fri, 13 May 2022 10:27:41 +0300 Subject: [PATCH] order fixes --- package-lock.json | 2 - src/@utils/order.ts | 41 +++++++++++++------ src/@utils/provider.ts | 9 ++-- .../Asset/AssetActions/Compute/index.tsx | 18 +++++--- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7c7477ffb..dd201b87c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41998,7 +41998,6 @@ "cross-fetch": "^3.1.5", "crypto-js": "^4.1.1", "decimal.js": "^10.3.1", - "web3": "^1.7.3", "web3-core": "^1.7.1", "web3-eth-contract": "^1.7.1" } @@ -42050,7 +42049,6 @@ "integrity": "sha512-rmVKYEsKzurfRU0xJz+iHelbi1LGlihIWZ7Qvmb/CBz1EkhL7nOkW4SVXmG2dA5Ce0si2gr88i6q4eBOMRNJ1w==", "dev": true, "requires": { - "@oclif/config": "^1.18.2", "@oclif/errors": "^1.3.5", "@oclif/help": "^1.0.1", "@oclif/parser": "^3.8.6", diff --git a/src/@utils/order.ts b/src/@utils/order.ts index 455d079a4..43ec467a0 100644 --- a/src/@utils/order.ts +++ b/src/@utils/order.ts @@ -135,6 +135,8 @@ export async function reuseOrder( validOrderTx: string, providerFees?: ProviderFees ): Promise { + LoggerInstance.log('[compute] reuseOrder', providerFees) + const datatoken = new Datatoken(web3) const initializeData = !providerFees && @@ -145,19 +147,26 @@ export async function reuseOrder( accountId, asset.services[0].serviceEndpoint )) + LoggerInstance.log('[compute] initializeData', initializeData) - const txApprove = await approve( - web3, - accountId, - providerFees.providerFeeToken || - initializeData.providerFee.providerFeeToken, - asset.accessDetails.datatoken.address, - providerFees.providerFeeAmount || - initializeData.providerFee.providerFeeAmount, - false - ) - if (!txApprove) { - return + if ( + providerFees?.providerFeeAmount || + initializeData.providerFee.providerFeeToken + ) { + const txApprove = await approve( + web3, + accountId, + providerFees.providerFeeToken || + initializeData.providerFee.providerFeeToken, + asset.accessDetails.datatoken.address, + providerFees.providerFeeAmount, + false + ) + + LoggerInstance.log('[compute] txApprove', txApprove) + if (!txApprove) { + return + } } const tx = await datatoken.reuseOrder( @@ -192,9 +201,16 @@ export async function handleComputeOrder( initializeData: ProviderComputeInitialize, computeConsumerAddress?: string ): Promise { + LoggerInstance.log('[compute] handleComputeOrder asset: ', asset) + LoggerInstance.log( + '[compute] handleComputeOrder orderPriceAndFees: ', + orderPriceAndFees + ) if (initializeData.validOrder && !initializeData.providerFee) { + LoggerInstance.log('[compute] Has valid order: ', initializeData.validOrder) return initializeData.validOrder } else if (initializeData.validOrder) { + LoggerInstance.log('[compute] Call reuse order', initializeData) const tx = await reuseOrder( web3, asset, @@ -204,6 +220,7 @@ export async function handleComputeOrder( ) return tx.transactionHash } else { + LoggerInstance.log('[compute] Call order', initializeData) if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') { const poolTx = await buyDtFromPool(asset?.accessDetails, accountId, web3) LoggerInstance.log('[compute] Buy dt from pool: ', poolTx) diff --git a/src/@utils/provider.ts b/src/@utils/provider.ts index c83793377..e13e2383c 100644 --- a/src/@utils/provider.ts +++ b/src/@utils/provider.ts @@ -8,7 +8,6 @@ import { ProviderComputeInitializeResults, ProviderInstance } from '@oceanprotocol/lib' -import { da } from 'date-fns/locale' import { AssetExtended } from 'src/@types/AssetExtended' import Web3 from 'web3' import { getValidUntilTime } from './compute' @@ -21,13 +20,13 @@ export async function initializeProviderForCompute( ): Promise { const computeAsset: ComputeAsset = { documentId: dataset.id, - serviceId: dataset.services[0].id, - transferTxId: dataset.accessDetails.validOrderTx + serviceId: dataset.services[0].id + // transferTxId: dataset.accessDetails.validOrderTx } const computeAlgo: ComputeAlgorithm = { documentId: algorithm.id, - serviceId: algorithm.services[0].id, - transferTxId: algorithm.accessDetails.validOrderTx + serviceId: algorithm.services[0].id + // transferTxId: algorithm.accessDetails.validOrderTx } const validUntil = getValidUntilTime( diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 74432b8fc..689e2cf57 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -133,6 +133,7 @@ export default function Compute({ accountId, computeEnv ) + console.log('initializedProvider == ', initializedProvider) setInitializedProviderResponse(initializedProvider) // setIsProviderFeeValid( // await checkComputeResourcesValidity( @@ -158,7 +159,9 @@ export default function Compute({ // setComputeValidUntil(validUntil) if ( asset?.accessDetails?.addressOrId !== ZERO_ADDRESS || - asset?.accessDetails?.type !== 'free' + asset?.accessDetails?.type !== 'free' || + (!initializedProvider.datasets[0].validOrder && + initializedProvider.datasets[0].providerFee) ) { setIsRequestingDataseOrderPrice(true) setComputeStatusText( @@ -190,6 +193,7 @@ export default function Compute({ poolParams, initializedProvider.datasets[0].providerFee ) + console.log('datasetPriceAndFees', datasetPriceAndFees) if (!datasetPriceAndFees) { setError('Error setting dataset price and fees!') toast.error('Error setting dataset price and fees!') @@ -201,7 +205,9 @@ export default function Compute({ if ( selectedAlgorithmAsset?.accessDetails?.addressOrId !== ZERO_ADDRESS || - selectedAlgorithmAsset?.accessDetails?.type !== 'free' + selectedAlgorithmAsset?.accessDetails?.type !== 'free' || + (!initializedProvider.algorithm.validOrder && + initializedProvider.algorithm.providerFee) ) { setIsRequestingAlgoOrderPrice(true) setComputeStatusText( @@ -239,6 +245,7 @@ export default function Compute({ algoPoolParams, initializedProvider.algorithm.providerFee ) + console.log('algorithmOrderPriceAndFees', algorithmOrderPriceAndFees) if (!algorithmOrderPriceAndFees) { setError('Error setting algorithm price and fees!') toast.error('Error setting algorithm price and fees!') @@ -331,6 +338,7 @@ export default function Compute({ initializedProviderResponse.datasets[0], computeEnv.consumerAddress ) + console.log('datasetOrderTx', datasetOrderTx) // if (isOwned) { // datasetOrderTx = validOrderTx // LoggerInstance.log('[compute] Dataset owned txId:', validOrderTx) @@ -392,13 +400,13 @@ export default function Compute({ const algorithmOrderTx = await handleComputeOrder( web3, selectedAlgorithmAsset, - datasetOrderPriceAndFees, + algoOrderPriceAndFees, accountId, - hasDatatoken, + hasAlgoAssetDatatoken, initializedProviderResponse.algorithm, computeEnv.consumerAddress ) - + console.log('algorithmOrderTx', algorithmOrderTx) // if (isAlgorithmOwned) { // algorithmOrderTx = validAlgorithmOrderTx // LoggerInstance.log(