mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
update order params
This commit is contained in:
parent
109b9dcbb9
commit
5790ffd122
@ -235,6 +235,8 @@ function getValidUntilTime() {
|
||||
*/
|
||||
export async function getOrderPriceAndFees(
|
||||
asset: AssetExtended,
|
||||
computeEnv: string = null,
|
||||
computeValidUntil: number = null,
|
||||
accountId?: string
|
||||
): Promise<OrderPriceAndFees> {
|
||||
const orderPriceAndFee = {
|
||||
@ -257,16 +259,6 @@ export async function getOrderPriceAndFees(
|
||||
// fetch consume market order fee
|
||||
orderPriceAndFee.consumeMarketOrderFee = appConfig.consumeMarketOrderFee
|
||||
// fetch provider fee
|
||||
const computeEnvs =
|
||||
asset.services[0].type === 'compute'
|
||||
? await ProviderInstance.getComputeEnvironments(
|
||||
asset.services[0].serviceEndpoint
|
||||
)
|
||||
: null
|
||||
const computeEnviroment =
|
||||
computeEnvs && computeEnvs[0] ? computeEnvs[0].id : null
|
||||
const computeValidUntil =
|
||||
asset.services[0].type === 'compute' ? getValidUntilTime() : null
|
||||
|
||||
const initializeData = await ProviderInstance.initialize(
|
||||
asset.id,
|
||||
@ -276,7 +268,7 @@ export async function getOrderPriceAndFees(
|
||||
asset.services[0].serviceEndpoint,
|
||||
null,
|
||||
null,
|
||||
computeEnviroment,
|
||||
computeEnv,
|
||||
computeValidUntil
|
||||
)
|
||||
orderPriceAndFee.providerFee = initializeData.providerFee
|
||||
|
@ -6,7 +6,9 @@ import {
|
||||
LoggerInstance,
|
||||
ComputeAlgorithm,
|
||||
DDO,
|
||||
Service
|
||||
Service,
|
||||
ProviderInstance,
|
||||
ComputeEnvironment
|
||||
} from '@oceanprotocol/lib'
|
||||
import { CancelToken } from 'axios'
|
||||
import { gql } from 'urql'
|
||||
@ -116,6 +118,27 @@ export async function isOrderable(
|
||||
return true
|
||||
}
|
||||
|
||||
export function getValidUntilTime() {
|
||||
const mytime = new Date()
|
||||
mytime.setMinutes(mytime.getMinutes() + 19)
|
||||
return Math.floor(mytime.getTime() / 1000)
|
||||
}
|
||||
|
||||
export async function getComputeEnviroment(
|
||||
asset: Asset
|
||||
): Promise<ComputeEnvironment> {
|
||||
if (asset?.services[0]?.type !== 'compute') return null
|
||||
try {
|
||||
const computeEnvs = await ProviderInstance.getComputeEnvironments(
|
||||
asset.services[0].serviceEndpoint
|
||||
)
|
||||
if (!computeEnvs[0]) return null
|
||||
return computeEnvs[0]
|
||||
} catch (e) {
|
||||
LoggerInstance.error('[compute] Fetch compute enviroment: ', e.message)
|
||||
}
|
||||
}
|
||||
|
||||
export function getQuerryString(
|
||||
trustedAlgorithmList: PublisherTrustedAlgorithm[],
|
||||
chainId?: number
|
||||
|
@ -23,29 +23,24 @@ function getValidUntilTime() {
|
||||
* @param web3
|
||||
* @param asset
|
||||
* @param accountId
|
||||
* @param computeEnv
|
||||
* @param computeValidUntil
|
||||
* @param computeConsumerAddress
|
||||
* @returns {TransactionReceipt} receipt of the order
|
||||
*/
|
||||
export async function order(
|
||||
web3: Web3,
|
||||
asset: AssetExtended,
|
||||
orderPriceAndFees: OrderPriceAndFees,
|
||||
accountId: string
|
||||
accountId: string,
|
||||
computeEnv: string = null,
|
||||
computeValidUntil: number = null,
|
||||
computeConsumerAddress?: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const datatoken = new Datatoken(web3)
|
||||
const config = getOceanConfig(asset.chainId)
|
||||
const { appConfig } = getSiteMetadata()
|
||||
|
||||
const computeEnvs =
|
||||
asset.services[0].type === 'compute'
|
||||
? await ProviderInstance.getComputeEnvironments(
|
||||
asset.services[0].serviceEndpoint
|
||||
)
|
||||
: null
|
||||
const computeEnviroment =
|
||||
computeEnvs && computeEnvs[0] ? computeEnvs[0].id : null
|
||||
const computeValidUntil =
|
||||
asset.services[0].type === 'compute' ? getValidUntilTime() : null
|
||||
|
||||
const initializeData = await ProviderInstance.initialize(
|
||||
asset.id,
|
||||
asset.services[0].id,
|
||||
@ -54,12 +49,12 @@ export async function order(
|
||||
asset.services[0].serviceEndpoint,
|
||||
null,
|
||||
null,
|
||||
computeEnviroment,
|
||||
computeEnv,
|
||||
computeValidUntil
|
||||
)
|
||||
|
||||
const orderParams = {
|
||||
consumer: accountId,
|
||||
consumer: computeConsumerAddress || accountId,
|
||||
serviceIndex: 0,
|
||||
_providerFee: initializeData.providerFee,
|
||||
_consumeMarketFee: {
|
||||
@ -102,7 +97,7 @@ export async function order(
|
||||
const tx = await datatoken.startOrder(
|
||||
asset.accessDetails.datatoken.address,
|
||||
accountId,
|
||||
accountId,
|
||||
computeConsumerAddress || accountId,
|
||||
0,
|
||||
initializeData.providerFee
|
||||
)
|
||||
|
@ -43,7 +43,10 @@ import {
|
||||
isOrderable,
|
||||
getAlgorithmAssetSelectionList,
|
||||
getAlgorithmsForAsset,
|
||||
getQuerryString
|
||||
getQuerryString,
|
||||
getValidUntilTime,
|
||||
getComputeEnviromen,
|
||||
getComputeEnviroment
|
||||
} from '@utils/compute'
|
||||
import AssetSelection, {
|
||||
AssetSelectionAsset
|
||||
@ -172,8 +175,14 @@ export default function Compute({
|
||||
|
||||
async function init() {
|
||||
if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return
|
||||
|
||||
const orderPriceAndFees = await getOrderPriceAndFees(asset, ZERO_ADDRESS)
|
||||
const validUntil = getValidUntilTime()
|
||||
const computeEnv = await getComputeEnviroment(asset)
|
||||
const orderPriceAndFees = await getOrderPriceAndFees(
|
||||
asset,
|
||||
computeEnv.id,
|
||||
validUntil,
|
||||
ZERO_ADDRESS
|
||||
)
|
||||
setOrderPriceAndFees(orderPriceAndFees)
|
||||
}
|
||||
init()
|
||||
@ -192,9 +201,13 @@ export default function Compute({
|
||||
async function init() {
|
||||
if (selectedAlgorithmAsset?.accessDetails?.addressOrId === ZERO_ADDRESS)
|
||||
return
|
||||
const validUntil = getValidUntilTime()
|
||||
const computeEnv = await getComputeEnviroment(selectedAlgorithmAsset)
|
||||
|
||||
const orderPriceAndFees = await getOrderPriceAndFees(
|
||||
selectedAlgorithmAsset,
|
||||
computeEnv.id,
|
||||
validUntil,
|
||||
ZERO_ADDRESS
|
||||
)
|
||||
setOrderAlgorithmPriceAndFees(orderPriceAndFees)
|
||||
|
@ -76,7 +76,12 @@ export default function Download({
|
||||
if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return
|
||||
setIsLoading(true)
|
||||
setStatusText('Calculating price including fees.')
|
||||
const orderPriceAndFees = await getOrderPriceAndFees(asset, ZERO_ADDRESS)
|
||||
const orderPriceAndFees = await getOrderPriceAndFees(
|
||||
asset,
|
||||
null,
|
||||
null,
|
||||
ZERO_ADDRESS
|
||||
)
|
||||
setOrderPriceAndFees(orderPriceAndFees)
|
||||
|
||||
setIsLoading(false)
|
||||
|
Loading…
Reference in New Issue
Block a user