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(
|
export async function getOrderPriceAndFees(
|
||||||
asset: AssetExtended,
|
asset: AssetExtended,
|
||||||
|
computeEnv: string = null,
|
||||||
|
computeValidUntil: number = null,
|
||||||
accountId?: string
|
accountId?: string
|
||||||
): Promise<OrderPriceAndFees> {
|
): Promise<OrderPriceAndFees> {
|
||||||
const orderPriceAndFee = {
|
const orderPriceAndFee = {
|
||||||
@ -257,16 +259,6 @@ export async function getOrderPriceAndFees(
|
|||||||
// fetch consume market order fee
|
// fetch consume market order fee
|
||||||
orderPriceAndFee.consumeMarketOrderFee = appConfig.consumeMarketOrderFee
|
orderPriceAndFee.consumeMarketOrderFee = appConfig.consumeMarketOrderFee
|
||||||
// fetch provider fee
|
// 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(
|
const initializeData = await ProviderInstance.initialize(
|
||||||
asset.id,
|
asset.id,
|
||||||
@ -276,7 +268,7 @@ export async function getOrderPriceAndFees(
|
|||||||
asset.services[0].serviceEndpoint,
|
asset.services[0].serviceEndpoint,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
computeEnviroment,
|
computeEnv,
|
||||||
computeValidUntil
|
computeValidUntil
|
||||||
)
|
)
|
||||||
orderPriceAndFee.providerFee = initializeData.providerFee
|
orderPriceAndFee.providerFee = initializeData.providerFee
|
||||||
|
@ -6,7 +6,9 @@ import {
|
|||||||
LoggerInstance,
|
LoggerInstance,
|
||||||
ComputeAlgorithm,
|
ComputeAlgorithm,
|
||||||
DDO,
|
DDO,
|
||||||
Service
|
Service,
|
||||||
|
ProviderInstance,
|
||||||
|
ComputeEnvironment
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
import { CancelToken } from 'axios'
|
import { CancelToken } from 'axios'
|
||||||
import { gql } from 'urql'
|
import { gql } from 'urql'
|
||||||
@ -116,6 +118,27 @@ export async function isOrderable(
|
|||||||
return true
|
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(
|
export function getQuerryString(
|
||||||
trustedAlgorithmList: PublisherTrustedAlgorithm[],
|
trustedAlgorithmList: PublisherTrustedAlgorithm[],
|
||||||
chainId?: number
|
chainId?: number
|
||||||
|
@ -23,29 +23,24 @@ function getValidUntilTime() {
|
|||||||
* @param web3
|
* @param web3
|
||||||
* @param asset
|
* @param asset
|
||||||
* @param accountId
|
* @param accountId
|
||||||
|
* @param computeEnv
|
||||||
|
* @param computeValidUntil
|
||||||
|
* @param computeConsumerAddress
|
||||||
* @returns {TransactionReceipt} receipt of the order
|
* @returns {TransactionReceipt} receipt of the order
|
||||||
*/
|
*/
|
||||||
export async function order(
|
export async function order(
|
||||||
web3: Web3,
|
web3: Web3,
|
||||||
asset: AssetExtended,
|
asset: AssetExtended,
|
||||||
orderPriceAndFees: OrderPriceAndFees,
|
orderPriceAndFees: OrderPriceAndFees,
|
||||||
accountId: string
|
accountId: string,
|
||||||
|
computeEnv: string = null,
|
||||||
|
computeValidUntil: number = null,
|
||||||
|
computeConsumerAddress?: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
const datatoken = new Datatoken(web3)
|
const datatoken = new Datatoken(web3)
|
||||||
const config = getOceanConfig(asset.chainId)
|
const config = getOceanConfig(asset.chainId)
|
||||||
const { appConfig } = getSiteMetadata()
|
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(
|
const initializeData = await ProviderInstance.initialize(
|
||||||
asset.id,
|
asset.id,
|
||||||
asset.services[0].id,
|
asset.services[0].id,
|
||||||
@ -54,12 +49,12 @@ export async function order(
|
|||||||
asset.services[0].serviceEndpoint,
|
asset.services[0].serviceEndpoint,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
computeEnviroment,
|
computeEnv,
|
||||||
computeValidUntil
|
computeValidUntil
|
||||||
)
|
)
|
||||||
|
|
||||||
const orderParams = {
|
const orderParams = {
|
||||||
consumer: accountId,
|
consumer: computeConsumerAddress || accountId,
|
||||||
serviceIndex: 0,
|
serviceIndex: 0,
|
||||||
_providerFee: initializeData.providerFee,
|
_providerFee: initializeData.providerFee,
|
||||||
_consumeMarketFee: {
|
_consumeMarketFee: {
|
||||||
@ -102,7 +97,7 @@ export async function order(
|
|||||||
const tx = await datatoken.startOrder(
|
const tx = await datatoken.startOrder(
|
||||||
asset.accessDetails.datatoken.address,
|
asset.accessDetails.datatoken.address,
|
||||||
accountId,
|
accountId,
|
||||||
accountId,
|
computeConsumerAddress || accountId,
|
||||||
0,
|
0,
|
||||||
initializeData.providerFee
|
initializeData.providerFee
|
||||||
)
|
)
|
||||||
|
@ -43,7 +43,10 @@ import {
|
|||||||
isOrderable,
|
isOrderable,
|
||||||
getAlgorithmAssetSelectionList,
|
getAlgorithmAssetSelectionList,
|
||||||
getAlgorithmsForAsset,
|
getAlgorithmsForAsset,
|
||||||
getQuerryString
|
getQuerryString,
|
||||||
|
getValidUntilTime,
|
||||||
|
getComputeEnviromen,
|
||||||
|
getComputeEnviroment
|
||||||
} from '@utils/compute'
|
} from '@utils/compute'
|
||||||
import AssetSelection, {
|
import AssetSelection, {
|
||||||
AssetSelectionAsset
|
AssetSelectionAsset
|
||||||
@ -172,8 +175,14 @@ 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 orderPriceAndFees = await getOrderPriceAndFees(asset, ZERO_ADDRESS)
|
const computeEnv = await getComputeEnviroment(asset)
|
||||||
|
const orderPriceAndFees = await getOrderPriceAndFees(
|
||||||
|
asset,
|
||||||
|
computeEnv.id,
|
||||||
|
validUntil,
|
||||||
|
ZERO_ADDRESS
|
||||||
|
)
|
||||||
setOrderPriceAndFees(orderPriceAndFees)
|
setOrderPriceAndFees(orderPriceAndFees)
|
||||||
}
|
}
|
||||||
init()
|
init()
|
||||||
@ -192,9 +201,13 @@ 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 orderPriceAndFees = await getOrderPriceAndFees(
|
const orderPriceAndFees = await getOrderPriceAndFees(
|
||||||
selectedAlgorithmAsset,
|
selectedAlgorithmAsset,
|
||||||
|
computeEnv.id,
|
||||||
|
validUntil,
|
||||||
ZERO_ADDRESS
|
ZERO_ADDRESS
|
||||||
)
|
)
|
||||||
setOrderAlgorithmPriceAndFees(orderPriceAndFees)
|
setOrderAlgorithmPriceAndFees(orderPriceAndFees)
|
||||||
|
@ -76,7 +76,12 @@ 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(asset, ZERO_ADDRESS)
|
const orderPriceAndFees = await getOrderPriceAndFees(
|
||||||
|
asset,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
ZERO_ADDRESS
|
||||||
|
)
|
||||||
setOrderPriceAndFees(orderPriceAndFees)
|
setOrderPriceAndFees(orderPriceAndFees)
|
||||||
|
|
||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user