diff --git a/src/@utils/accessDetailsAndPricing.ts b/src/@utils/accessDetailsAndPricing.ts index 7ee6bcf34..45dd7ec6b 100644 --- a/src/@utils/accessDetailsAndPricing.ts +++ b/src/@utils/accessDetailsAndPricing.ts @@ -222,12 +222,6 @@ function getAccessDetailsFromTokenPrice( return accessDetails } -function getValidUntilTime() { - const mytime = new Date() - mytime.setMinutes(mytime.getMinutes() + 19) - return Math.floor(mytime.getTime() / 1000) -} - /** * This will be used to get price including feed before ordering * @param {AssetExtended} asset @@ -235,9 +229,9 @@ function getValidUntilTime() { */ export async function getOrderPriceAndFees( asset: AssetExtended, + accountId?: string, computeEnv: string = null, - computeValidUntil: number = null, - accountId?: string + computeValidUntil: number = null ): Promise { const orderPriceAndFee = { price: '0', diff --git a/src/@utils/compute.ts b/src/@utils/compute.ts index dc617f6f9..541d82bfc 100644 --- a/src/@utils/compute.ts +++ b/src/@utils/compute.ts @@ -117,9 +117,19 @@ export async function isOrderable( return true } -export function getValidUntilTime() { +export function getValidUntilTime( + computeEnvMaxJobDuration: number, + datasetTimeout?: number, + algorithmTimeout?: number +) { + const inputValues = [] + computeEnvMaxJobDuration && inputValues.push(computeEnvMaxJobDuration * 60) + datasetTimeout && inputValues.push(datasetTimeout) + algorithmTimeout && inputValues.push(algorithmTimeout) + + const minValue = Math.min(...inputValues) const mytime = new Date() - mytime.setMinutes(mytime.getMinutes() + 19) + mytime.setMinutes(mytime.getMinutes() + Math.floor(minValue / 60)) return Math.floor(mytime.getTime() / 1000) } @@ -400,7 +410,9 @@ export async function createTrustedAlgorithmList( containerSectionChecksum: getHash( JSON.stringify(selectedAlgorithm.metadata.algorithm.container) ), - filesChecksum: getHash(selectedAlgorithm.services[0].files) + filesChecksum: getHash( + JSON.stringify(selectedAlgorithm.services[0].files) + ) } trustedAlgorithms.push(trustedAlgorithm) } diff --git a/src/@utils/order.ts b/src/@utils/order.ts index e62f5ef4f..107783190 100644 --- a/src/@utils/order.ts +++ b/src/@utils/order.ts @@ -11,13 +11,6 @@ import { getOceanConfig } from './ocean' import { TransactionReceipt } from 'web3-eth' import { getSiteMetadata } from './siteConfig' import { OrderPriceAndFees } from 'src/@types/Price' - -function getValidUntilTime() { - const mytime = new Date() - mytime.setMinutes(mytime.getMinutes() + 19) - return Math.floor(mytime.getTime() / 1000) -} - /** * For pool you need to buy the datatoken beforehand, this always assumes you want to order the first service * @param web3 diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index eb94d3a6f..12c49bb4b 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -147,13 +147,16 @@ export default function Compute({ async function init() { if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return - const validUntil = getValidUntilTime() const computeEnv = await getComputeEnviroment(asset) + const validUntil = getValidUntilTime( + computeEnv.maxJobDuration, + asset?.services[0]?.timeout + ) const orderPriceAndFees = await getOrderPriceAndFees( asset, + ZERO_ADDRESS, computeEnv.id, - validUntil, - ZERO_ADDRESS + validUntil ) setOrderPriceAndFees(orderPriceAndFees) } @@ -173,13 +176,16 @@ export default function Compute({ async function init() { if (selectedAlgorithmAsset?.accessDetails?.addressOrId === ZERO_ADDRESS) return - const validUntil = getValidUntilTime() const computeEnv = await getComputeEnviroment(selectedAlgorithmAsset) + const validUntil = getValidUntilTime( + computeEnv.maxJobDuration, + selectedAlgorithmAsset?.services[0]?.timeout + ) const orderPriceAndFees = await getOrderPriceAndFees( selectedAlgorithmAsset, + ZERO_ADDRESS, computeEnv.id, - validUntil, - ZERO_ADDRESS + validUntil ) setOrderAlgorithmPriceAndFees(orderPriceAndFees) } @@ -237,9 +243,12 @@ export default function Compute({ return } - const validUntil = getValidUntilTime() const computeEnv = await getComputeEnviroment(asset) - + const validUntil = getValidUntilTime( + computeEnv.maxJobDuration, + asset.services[0].timeout, + selectedAlgorithmAsset.services[0].timeout + ) let datasetOrderTx if (!isOwned) { try { diff --git a/src/components/Asset/AssetActions/Download.tsx b/src/components/Asset/AssetActions/Download.tsx index dab916b2a..fd023aaa6 100644 --- a/src/components/Asset/AssetActions/Download.tsx +++ b/src/components/Asset/AssetActions/Download.tsx @@ -76,12 +76,7 @@ export default function Download({ if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return setIsLoading(true) setStatusText('Calculating price including fees.') - const orderPriceAndFees = await getOrderPriceAndFees( - asset, - null, - null, - ZERO_ADDRESS - ) + const orderPriceAndFees = await getOrderPriceAndFees(asset, ZERO_ADDRESS) setOrderPriceAndFees(orderPriceAndFees) setIsLoading(false)