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:
parent
fcc1e440fd
commit
809429b728
@ -222,12 +222,6 @@ function getAccessDetailsFromTokenPrice(
|
|||||||
return accessDetails
|
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
|
* This will be used to get price including feed before ordering
|
||||||
* @param {AssetExtended} asset
|
* @param {AssetExtended} asset
|
||||||
@ -235,9 +229,9 @@ function getValidUntilTime() {
|
|||||||
*/
|
*/
|
||||||
export async function getOrderPriceAndFees(
|
export async function getOrderPriceAndFees(
|
||||||
asset: AssetExtended,
|
asset: AssetExtended,
|
||||||
|
accountId?: string,
|
||||||
computeEnv: string = null,
|
computeEnv: string = null,
|
||||||
computeValidUntil: number = null,
|
computeValidUntil: number = null
|
||||||
accountId?: string
|
|
||||||
): Promise<OrderPriceAndFees> {
|
): Promise<OrderPriceAndFees> {
|
||||||
const orderPriceAndFee = {
|
const orderPriceAndFee = {
|
||||||
price: '0',
|
price: '0',
|
||||||
|
@ -117,9 +117,19 @@ export async function isOrderable(
|
|||||||
return true
|
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()
|
const mytime = new Date()
|
||||||
mytime.setMinutes(mytime.getMinutes() + 19)
|
mytime.setMinutes(mytime.getMinutes() + Math.floor(minValue / 60))
|
||||||
return Math.floor(mytime.getTime() / 1000)
|
return Math.floor(mytime.getTime() / 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,7 +410,9 @@ export async function createTrustedAlgorithmList(
|
|||||||
containerSectionChecksum: getHash(
|
containerSectionChecksum: getHash(
|
||||||
JSON.stringify(selectedAlgorithm.metadata.algorithm.container)
|
JSON.stringify(selectedAlgorithm.metadata.algorithm.container)
|
||||||
),
|
),
|
||||||
filesChecksum: getHash(selectedAlgorithm.services[0].files)
|
filesChecksum: getHash(
|
||||||
|
JSON.stringify(selectedAlgorithm.services[0].files)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
trustedAlgorithms.push(trustedAlgorithm)
|
trustedAlgorithms.push(trustedAlgorithm)
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,6 @@ import { getOceanConfig } from './ocean'
|
|||||||
import { TransactionReceipt } from 'web3-eth'
|
import { TransactionReceipt } from 'web3-eth'
|
||||||
import { getSiteMetadata } from './siteConfig'
|
import { getSiteMetadata } from './siteConfig'
|
||||||
import { OrderPriceAndFees } from 'src/@types/Price'
|
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
|
* For pool you need to buy the datatoken beforehand, this always assumes you want to order the first service
|
||||||
* @param web3
|
* @param web3
|
||||||
|
@ -147,13 +147,16 @@ export default function Compute({
|
|||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return
|
if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return
|
||||||
const validUntil = getValidUntilTime()
|
|
||||||
const computeEnv = await getComputeEnviroment(asset)
|
const computeEnv = await getComputeEnviroment(asset)
|
||||||
|
const validUntil = getValidUntilTime(
|
||||||
|
computeEnv.maxJobDuration,
|
||||||
|
asset?.services[0]?.timeout
|
||||||
|
)
|
||||||
const orderPriceAndFees = await getOrderPriceAndFees(
|
const orderPriceAndFees = await getOrderPriceAndFees(
|
||||||
asset,
|
asset,
|
||||||
|
ZERO_ADDRESS,
|
||||||
computeEnv.id,
|
computeEnv.id,
|
||||||
validUntil,
|
validUntil
|
||||||
ZERO_ADDRESS
|
|
||||||
)
|
)
|
||||||
setOrderPriceAndFees(orderPriceAndFees)
|
setOrderPriceAndFees(orderPriceAndFees)
|
||||||
}
|
}
|
||||||
@ -173,13 +176,16 @@ export default function Compute({
|
|||||||
async function init() {
|
async function init() {
|
||||||
if (selectedAlgorithmAsset?.accessDetails?.addressOrId === ZERO_ADDRESS)
|
if (selectedAlgorithmAsset?.accessDetails?.addressOrId === ZERO_ADDRESS)
|
||||||
return
|
return
|
||||||
const validUntil = getValidUntilTime()
|
|
||||||
const computeEnv = await getComputeEnviroment(selectedAlgorithmAsset)
|
const computeEnv = await getComputeEnviroment(selectedAlgorithmAsset)
|
||||||
|
const validUntil = getValidUntilTime(
|
||||||
|
computeEnv.maxJobDuration,
|
||||||
|
selectedAlgorithmAsset?.services[0]?.timeout
|
||||||
|
)
|
||||||
const orderPriceAndFees = await getOrderPriceAndFees(
|
const orderPriceAndFees = await getOrderPriceAndFees(
|
||||||
selectedAlgorithmAsset,
|
selectedAlgorithmAsset,
|
||||||
|
ZERO_ADDRESS,
|
||||||
computeEnv.id,
|
computeEnv.id,
|
||||||
validUntil,
|
validUntil
|
||||||
ZERO_ADDRESS
|
|
||||||
)
|
)
|
||||||
setOrderAlgorithmPriceAndFees(orderPriceAndFees)
|
setOrderAlgorithmPriceAndFees(orderPriceAndFees)
|
||||||
}
|
}
|
||||||
@ -237,9 +243,12 @@ export default function Compute({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const validUntil = getValidUntilTime()
|
|
||||||
const computeEnv = await getComputeEnviroment(asset)
|
const computeEnv = await getComputeEnviroment(asset)
|
||||||
|
const validUntil = getValidUntilTime(
|
||||||
|
computeEnv.maxJobDuration,
|
||||||
|
asset.services[0].timeout,
|
||||||
|
selectedAlgorithmAsset.services[0].timeout
|
||||||
|
)
|
||||||
let datasetOrderTx
|
let datasetOrderTx
|
||||||
if (!isOwned) {
|
if (!isOwned) {
|
||||||
try {
|
try {
|
||||||
|
@ -76,12 +76,7 @@ export default function Download({
|
|||||||
if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return
|
if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
setStatusText('Calculating price including fees.')
|
setStatusText('Calculating price including fees.')
|
||||||
const orderPriceAndFees = await getOrderPriceAndFees(
|
const orderPriceAndFees = await getOrderPriceAndFees(asset, ZERO_ADDRESS)
|
||||||
asset,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
ZERO_ADDRESS
|
|
||||||
)
|
|
||||||
setOrderPriceAndFees(orderPriceAndFees)
|
setOrderPriceAndFees(orderPriceAndFees)
|
||||||
|
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user