1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00

update compute resources valid until logic

This commit is contained in:
Bogdan Fazakas 2022-03-04 01:07:00 +02:00
parent fcc1e440fd
commit 809429b728
5 changed files with 35 additions and 32 deletions

View File

@ -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<OrderPriceAndFees> {
const orderPriceAndFee = {
price: '0',

View File

@ -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)
}

View File

@ -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

View File

@ -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 {

View File

@ -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)