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

fix prices

This commit is contained in:
Bogdan Fazakas 2022-03-02 16:42:50 +02:00
parent b50c46e1f4
commit 6a449eadcb
4 changed files with 28 additions and 20 deletions

View File

@ -91,7 +91,6 @@ export async function isOrderable(
algorithmDDO: Asset | DDO algorithmDDO: Asset | DDO
): Promise<boolean> { ): Promise<boolean> {
const datasetService: Service = getServiceById(asset, serviceId) const datasetService: Service = getServiceById(asset, serviceId)
console.log('datasetService', datasetService)
if (!datasetService) return false if (!datasetService) return false
if (datasetService.type === 'compute') { if (datasetService.type === 'compute') {
if (algorithm.meta) { if (algorithm.meta) {
@ -155,7 +154,6 @@ export function getQuerryString(
} as BaseQueryParams } as BaseQueryParams
const query = generateBaseQuery(baseParams) const query = generateBaseQuery(baseParams)
console.log('querry', query)
return query return query
} }
@ -164,14 +162,12 @@ export async function getAlgorithmsForAsset(
token: CancelToken token: CancelToken
): Promise<Asset[]> { ): Promise<Asset[]> {
const computeService: Service = getServiceByName(asset, 'compute') const computeService: Service = getServiceByName(asset, 'compute')
console.log('computeService: ', computeService)
let algorithms: Asset[] let algorithms: Asset[]
if ( if (
!computeService.compute || !computeService.compute ||
!computeService.compute.publisherTrustedAlgorithms || !computeService.compute.publisherTrustedAlgorithms ||
computeService.compute.publisherTrustedAlgorithms.length === 0 computeService.compute.publisherTrustedAlgorithms.length === 0
) { ) {
console.log('computeService: []')
algorithms = [] algorithms = []
} else { } else {
const gueryResults = await queryMetadata( const gueryResults = await queryMetadata(
@ -181,7 +177,6 @@ export async function getAlgorithmsForAsset(
), ),
token token
) )
console.log('gueryResults: ', gueryResults)
algorithms = gueryResults?.results algorithms = gueryResults?.results
} }
return algorithms return algorithms

View File

@ -113,8 +113,6 @@ export async function setNftMetadata(
[] []
) )
console.log('[setNftMetadata] est Gas set metadata --', estGasSetMetadata)
const setMetadataTx = await nft.setMetadata( const setMetadataTx = await nft.setMetadata(
asset.nftAddress, asset.nftAddress,
accountId, accountId,

View File

@ -46,7 +46,6 @@ export default function FilesInput(props: InputProps): ReactElement {
props.value.length > 0 && props.value.length > 0 &&
typeof props.value[0] === 'string' typeof props.value[0] === 'string'
) { ) {
console.log('loadFileInfo eff')
loadFileInfo(props.value[0].toString()) loadFileInfo(props.value[0].toString())
} }
}, [loadFileInfo, props]) }, [loadFileInfo, props])

View File

@ -128,13 +128,16 @@ export default function Compute({
!isAlgoConsumablePrice) !isAlgoConsumablePrice)
async function checkAssetDTBalance(asset: DDO) { async function checkAssetDTBalance(asset: DDO) {
console.log('checkAssetDTBalance asset ', asset)
if (!asset?.services[0].datatokenAddress) return
const datatokenInstance = new Datatoken(web3) const datatokenInstance = new Datatoken(web3)
const AssetDtBalance = await datatokenInstance.balance( const dtBalance = await datatokenInstance.balance(
asset?.services[0].datatokenAddress, asset?.services[0].datatokenAddress,
accountId accountId
) )
setAlgorithmDTBalance(new Decimal(AssetDtBalance).toString()) setAlgorithmDTBalance(new Decimal(dtBalance).toString())
setHasAlgoAssetDatatoken(Number(AssetDtBalance) >= 1) console.log('dtBalance ', dtBalance)
setHasAlgoAssetDatatoken(Number(dtBalance) >= 1)
} }
async function getAlgorithmList(): Promise<AssetSelectionAsset[]> { async function getAlgorithmList(): Promise<AssetSelectionAsset[]> {
@ -166,7 +169,7 @@ export default function Compute({
} }
useEffect(() => { useEffect(() => {
if (!asset?.accessDetails && !accountId) return if (!asset?.accessDetails || !accountId) return
setIsConsumablePrice(asset?.accessDetails?.isPurchasable) setIsConsumablePrice(asset?.accessDetails?.isPurchasable)
setIsOwned(asset?.accessDetails?.isOwned) setIsOwned(asset?.accessDetails?.isOwned)
@ -176,19 +179,21 @@ export default function Compute({
if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return if (asset?.accessDetails?.addressOrId === ZERO_ADDRESS) return
const validUntil = getValidUntilTime() const validUntil = getValidUntilTime()
const computeEnv = await getComputeEnviroment(asset) const computeEnv = await getComputeEnviroment(asset)
console.log('asset compute env', computeEnv)
const orderPriceAndFees = await getOrderPriceAndFees( const orderPriceAndFees = await getOrderPriceAndFees(
asset, asset,
computeEnv.id, computeEnv.id,
validUntil, validUntil,
ZERO_ADDRESS ZERO_ADDRESS
) )
console.log('asset orderPriceAndFees', orderPriceAndFees)
setOrderPriceAndFees(orderPriceAndFees) setOrderPriceAndFees(orderPriceAndFees)
} }
init() init()
}, [asset?.accessDetails]) }, [asset?.accessDetails])
useEffect(() => { useEffect(() => {
if (!selectedAlgorithmAsset?.accessDetails && !accountId) return if (!selectedAlgorithmAsset?.accessDetails || !accountId) return
checkAssetDTBalance(selectedAlgorithmAsset) checkAssetDTBalance(selectedAlgorithmAsset)
setIsConsumablePrice(selectedAlgorithmAsset?.accessDetails?.isPurchasable) setIsConsumablePrice(selectedAlgorithmAsset?.accessDetails?.isPurchasable)
@ -202,7 +207,6 @@ export default function Compute({
return return
const validUntil = getValidUntilTime() const validUntil = getValidUntilTime()
const computeEnv = await getComputeEnviroment(selectedAlgorithmAsset) const computeEnv = await getComputeEnviroment(selectedAlgorithmAsset)
const orderPriceAndFees = await getOrderPriceAndFees( const orderPriceAndFees = await getOrderPriceAndFees(
selectedAlgorithmAsset, selectedAlgorithmAsset,
computeEnv.id, computeEnv.id,
@ -268,6 +272,7 @@ export default function Compute({
const validUntil = getValidUntilTime() const validUntil = getValidUntilTime()
const computeEnv = await getComputeEnviroment(asset) const computeEnv = await getComputeEnviroment(asset)
let datasetOrderTx
if (!isOwned) { if (!isOwned) {
try { try {
if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') { if (!hasDatatoken && asset?.accessDetails.type === 'dynamic') {
@ -293,19 +298,26 @@ export default function Compute({
validUntil, validUntil,
computeEnv.consumerAddress computeEnv.consumerAddress
) )
if (!orderTx) {
toast.error('Failed to order dataset asset!')
return
}
LoggerInstance.log( LoggerInstance.log(
'[compute] Order dataset: ', '[compute] Order dataset: ',
orderTx.transactionHash orderTx.transactionHash
) )
setIsOwned(true) setIsOwned(true)
setValidOrderTx(orderTx.transactionHash) setValidOrderTx(orderTx.transactionHash)
datasetOrderTx = orderTx.transactionHash
} catch (e) { } catch (e) {
LoggerInstance.log(e.message) LoggerInstance.log(e.message)
} }
} else { } else {
datasetOrderTx = validOrderTx
LoggerInstance.log('[compute] Dataset owned txId:', validOrderTx) LoggerInstance.log('[compute] Dataset owned txId:', validOrderTx)
} }
let algorithmOrderTx
if (!isAlgorithmOwned) { if (!isAlgorithmOwned) {
try { try {
if ( if (
@ -317,7 +329,6 @@ export default function Compute({
accountId, accountId,
web3 web3
) )
LoggerInstance.log('[compute] Buy algorithm dt from pool: ', tx) LoggerInstance.log('[compute] Buy algorithm dt from pool: ', tx)
if (!tx) { if (!tx) {
toast.error('Failed to buy datatoken from pool!') toast.error('Failed to buy datatoken from pool!')
@ -337,17 +348,22 @@ export default function Compute({
validUntil, validUntil,
computeEnv.consumerAddress computeEnv.consumerAddress
) )
if (!orderTx) {
toast.error('Failed to order algorithm asset!')
return
}
LoggerInstance.log( LoggerInstance.log(
'[compute] Order dataset: ', '[compute] Order algorithm: ',
orderTx.transactionHash orderTx.transactionHash
) )
setIsAlgorithmOwned(true) setIsAlgorithmOwned(true)
setValidAlgorithmOrderTx(orderTx.transactionHash) setValidAlgorithmOrderTx(orderTx.transactionHash)
algorithmOrderTx = orderTx.transactionHash
} catch (e) { } catch (e) {
LoggerInstance.log(e.message) LoggerInstance.log(e.message)
} }
} else { } else {
algorithmOrderTx = validAlgorithmOrderTx
LoggerInstance.log( LoggerInstance.log(
'[compute] Algorithm owned txId:', '[compute] Algorithm owned txId:',
validAlgorithmOrderTx validAlgorithmOrderTx
@ -358,9 +374,9 @@ export default function Compute({
const computeAsset: ComputeAsset = { const computeAsset: ComputeAsset = {
documentId: asset.id, documentId: asset.id,
serviceId: asset.services[0].id, serviceId: asset.services[0].id,
transferTxId: validOrderTx transferTxId: datasetOrderTx
} }
computeAlgorithm.transferTxId = validAlgorithmOrderTx computeAlgorithm.transferTxId = algorithmOrderTx
const output: ComputeOutput = { const output: ComputeOutput = {
publishAlgorithmLog: true, publishAlgorithmLog: true,
publishOutput: true publishOutput: true
@ -369,7 +385,7 @@ export default function Compute({
asset.services[0].serviceEndpoint, asset.services[0].serviceEndpoint,
web3, web3,
accountId, accountId,
'env1', computeEnv.id,
computeAsset, computeAsset,
computeAlgorithm, computeAlgorithm,
newAbortController(), newAbortController(),