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

* remove all DDO ocean.js imports

* move over as much as possible to new DDO structure

* DDO/Asset split-up

* use Asset typing instead of DDO almost everywhere

* more typings

* more DDO refactor

* ddo typings updates

* more DDO updates

* updates

* ddo updates
This commit is contained in:
Matthias Kretschmann 2021-11-11 07:51:13 +00:00 committed by GitHub
parent 0fb4e630c1
commit 3d4b30c00f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
60 changed files with 838 additions and 777 deletions

View File

@ -97,9 +97,9 @@
}, },
{ {
"name": "providerUri", "name": "providerUrl",
"label": "Custom Provider URL", "label": "Custom Provider URL",
"type": "providerUri", "type": "providerUrl",
"help": "Enter the URL for your custom provider or leave blank to use the default provider. [Learn more](https://github.com/oceanprotocol/provider/).", "help": "Enter the URL for your custom provider or leave blank to use the default provider. [Learn more](https://github.com/oceanprotocol/provider/).",
"placeholder": "e.g. https://provider.polygon.oceanprotocol.com/" "placeholder": "e.g. https://provider.polygon.oceanprotocol.com/"
} }

View File

@ -7,7 +7,7 @@ import React, {
useCallback, useCallback,
ReactNode ReactNode
} from 'react' } from 'react'
import { Logger, DDO, MetadataMain } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import { PurgatoryData } from '@oceanprotocol/lib/dist/node/ddo/interfaces/PurgatoryData' import { PurgatoryData } from '@oceanprotocol/lib/dist/node/ddo/interfaces/PurgatoryData'
import getAssetPurgatoryData from '@utils/purgatory' import getAssetPurgatoryData from '@utils/purgatory'
import { CancelToken } from 'axios' import { CancelToken } from 'axios'
@ -20,13 +20,10 @@ import { useCancelToken } from '@hooks/useCancelToken'
interface AssetProviderValue { interface AssetProviderValue {
isInPurgatory: boolean isInPurgatory: boolean
purgatoryData: PurgatoryData purgatoryData: PurgatoryData
ddo: DDO ddo: Asset
did: string
metadata: MetadataMarket
title: string title: string
owner: string owner: string
price: BestPrice price: BestPrice
type: MetadataMain['type']
error?: string error?: string
refreshInterval: number refreshInterval: number
isAssetNetwork: boolean isAssetNetwork: boolean
@ -42,7 +39,7 @@ function AssetProvider({
asset, asset,
children children
}: { }: {
asset: string | DDO asset: string | Asset
children: ReactNode children: ReactNode
}): ReactElement { }): ReactElement {
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
@ -50,17 +47,17 @@ function AssetProvider({
const { networkId } = useWeb3() const { networkId } = useWeb3()
const [isInPurgatory, setIsInPurgatory] = useState(false) const [isInPurgatory, setIsInPurgatory] = useState(false)
const [purgatoryData, setPurgatoryData] = useState<PurgatoryData>() const [purgatoryData, setPurgatoryData] = useState<PurgatoryData>()
const [ddo, setDDO] = useState<DDO>() const [ddo, setDDO] = useState<Asset>()
const [did, setDID] = useState<string>() const [did, setDID] = useState<string>()
const [metadata, setMetadata] = useState<MetadataMarket>()
const [title, setTitle] = useState<string>() const [title, setTitle] = useState<string>()
const [price, setPrice] = useState<BestPrice>() const [price, setPrice] = useState<BestPrice>()
const [owner, setOwner] = useState<string>() const [owner, setOwner] = useState<string>()
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
const [type, setType] = useState<MetadataMain['type']>()
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const [isAssetNetwork, setIsAssetNetwork] = useState<boolean>() const [isAssetNetwork, setIsAssetNetwork] = useState<boolean>()
const newCancelToken = useCancelToken() const newCancelToken = useCancelToken()
const fetchDdo = async (token?: CancelToken) => { const fetchDdo = async (token?: CancelToken) => {
Logger.log('[asset] Init asset, get DDO') Logger.log('[asset] Init asset, get DDO')
setLoading(true) setLoading(true)
@ -85,27 +82,6 @@ function AssetProvider({
setLoading(false) setLoading(false)
} }
//
// Get and set DDO based on passed DDO or DID
//
useEffect(() => {
if (!asset || !appConfig.metadataCacheUri) return
let isMounted = true
async function init() {
const ddo = await fetchDdo(newCancelToken())
if (!isMounted) return
Logger.debug('[asset] Got DDO', ddo)
setDDO(ddo)
setDID(asset as string)
}
init()
return () => {
isMounted = false
}
}, [asset, appConfig.metadataCacheUri])
const setPurgatory = useCallback(async (did: string): Promise<void> => { const setPurgatory = useCallback(async (did: string): Promise<void> => {
if (!did) return if (!did) return
@ -119,29 +95,41 @@ function AssetProvider({
} }
}, []) }, [])
const initMetadata = useCallback(async (ddo: DDO): Promise<void> => { //
// Get and set DDO based on passed DDO or DID
//
useEffect(() => {
if (!asset || !appConfig.metadataCacheUri) return
let isMounted = true
async function init() {
const ddo = await fetchDdo(newCancelToken())
if (!isMounted || !ddo) return
Logger.debug('[asset] Got DDO', ddo)
setDDO(ddo)
setDID(asset as string)
setTitle(ddo.metadata.name)
setOwner(ddo.nft.owner)
setIsInPurgatory(ddo.isInPurgatory === 'true')
await setPurgatory(ddo.id)
}
init()
return () => {
isMounted = false
}
}, [asset, appConfig.metadataCacheUri])
const initPrice = useCallback(async (ddo: Asset): Promise<void> => {
if (!ddo) return if (!ddo) return
setLoading(true)
const returnedPrice = await getPrice(ddo) const returnedPrice = await getPrice(ddo)
setPrice({ ...returnedPrice }) setPrice({ ...returnedPrice })
// Get metadata from DDO
const { attributes } = ddo.findServiceByType('metadata')
setMetadata(attributes as unknown as MetadataMarket)
setTitle(attributes?.main.name)
setType(attributes.main.type)
setOwner(ddo.publicKey[0].owner)
Logger.log('[asset] Got Metadata from DDO', attributes)
setIsInPurgatory(ddo.isInPurgatory === 'true')
await setPurgatory(ddo.id)
setLoading(false)
}, []) }, [])
useEffect(() => { useEffect(() => {
if (!ddo) return if (!ddo) return
initMetadata(ddo) initPrice(ddo)
}, [ddo, initMetadata]) }, [ddo, initPrice])
// Check user network against asset network // Check user network against asset network
useEffect(() => { useEffect(() => {
@ -157,11 +145,9 @@ function AssetProvider({
{ {
ddo, ddo,
did, did,
metadata,
title, title,
owner, owner,
price, price,
type,
error, error,
isInPurgatory, isInPurgatory,
purgatoryData, purgatoryData,

View File

@ -14,7 +14,7 @@ import {
} from '@utils/subgraph' } from '@utils/subgraph'
import { useUserPreferences } from './UserPreferences' import { useUserPreferences } from './UserPreferences'
import { PoolShares_poolShares as PoolShare } from '../@types/apollo/PoolShares' import { PoolShares_poolShares as PoolShare } from '../@types/apollo/PoolShares'
import { DDO, Logger } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import { getDownloadAssets, getPublishedAssets } from '@utils/aquarius' import { getDownloadAssets, getPublishedAssets } from '@utils/aquarius'
import { useSiteMetadata } from '@hooks/useSiteMetadata' import { useSiteMetadata } from '@hooks/useSiteMetadata'
import { accountTruncate } from '@utils/web3' import { accountTruncate } from '@utils/web3'
@ -27,7 +27,7 @@ interface ProfileProviderValue {
profile: Profile profile: Profile
poolShares: PoolShare[] poolShares: PoolShare[]
isPoolSharesLoading: boolean isPoolSharesLoading: boolean
assets: DDO[] assets: Asset[]
assetsTotal: number assetsTotal: number
isEthAddress: boolean isEthAddress: boolean
downloads: DownloadedAsset[] downloads: DownloadedAsset[]
@ -170,7 +170,7 @@ function ProfileProvider({
// //
// PUBLISHED ASSETS // PUBLISHED ASSETS
// //
const [assets, setAssets] = useState<DDO[]>() const [assets, setAssets] = useState<Asset[]>()
const [assetsTotal, setAssetsTotal] = useState(0) const [assetsTotal, setAssetsTotal] = useState(0)
// const [assetsWithPrices, setAssetsWithPrices] = useState<AssetListPrices[]>() // const [assetsWithPrices, setAssetsWithPrices] = useState<AssetListPrices[]>()

View File

@ -1,4 +1,4 @@
import { DDO, Logger } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import { useState } from 'react' import { useState } from 'react'
import { TransactionReceipt } from 'web3-core' import { TransactionReceipt } from 'web3-core'
import { Decimal } from 'decimal.js' import { Decimal } from 'decimal.js'
@ -14,17 +14,17 @@ import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3' import { useWeb3 } from '@context/Web3'
interface UsePricing { interface UsePricing {
getDTSymbol: (ddo: DDO) => Promise<string> getDTSymbol: (ddo: Asset) => Promise<string>
getDTName: (ddo: DDO) => Promise<string> getDTName: (ddo: Asset) => Promise<string>
createPricing: ( createPricing: (
priceOptions: PriceOptions, priceOptions: PriceOptions,
ddo: DDO ddo: Asset
) => Promise<TransactionReceipt | string | void> ) => Promise<TransactionReceipt | string | void>
mint: (tokensToMint: string, ddo: DDO) => Promise<TransactionReceipt | void> mint: (tokensToMint: string, ddo: Asset) => Promise<TransactionReceipt | void>
buyDT: ( buyDT: (
amountDataToken: number | string, amountDataToken: number | string,
price: BestPrice, price: BestPrice,
ddo: DDO ddo: Asset
) => Promise<TransactionReceipt | void> ) => Promise<TransactionReceipt | void>
pricingStep?: number pricingStep?: number
pricingStepText?: string pricingStepText?: string
@ -40,28 +40,28 @@ function usePricing(): UsePricing {
const [pricingStepText, setPricingStepText] = useState<string>() const [pricingStepText, setPricingStepText] = useState<string>()
const [pricingError, setPricingError] = useState<string>() const [pricingError, setPricingError] = useState<string>()
async function getDTSymbol(ddo: DDO): Promise<string> { async function getDTSymbol(ddo: Asset): Promise<string> {
if (!ocean || !accountId) return if (!ocean || !accountId) return
const { dataToken, dataTokenInfo } = ddo const { dataTokenInfo } = ddo
return dataTokenInfo return dataTokenInfo
? dataTokenInfo.symbol ? dataTokenInfo.symbol
: await ocean?.datatokens.getSymbol(dataToken) : await ocean?.datatokens.getSymbol(dataTokenInfo.address)
} }
async function getDTName(ddo: DDO): Promise<string> { async function getDTName(ddo: Asset): Promise<string> {
if (!ocean || !accountId) return if (!ocean || !accountId) return
const { dataToken, dataTokenInfo } = ddo const { dataTokenInfo } = ddo
return dataTokenInfo return dataTokenInfo
? dataTokenInfo.name ? dataTokenInfo.name
: await ocean?.datatokens.getName(dataToken) : await ocean?.datatokens.getName(dataTokenInfo.address)
} }
// Helper for setting steps & feedback for all flows // Helper for setting steps & feedback for all flows
async function setStep( async function setStep(
index: number, index: number,
type: 'pool' | 'exchange' | 'free' | 'buy' | 'dispense', type: 'pool' | 'exchange' | 'free' | 'buy' | 'dispense',
ddo: DDO ddo: Asset
) { ) {
const dtSymbol = await getDTSymbol(ddo) const dtSymbol = await getDTSymbol(ddo)
setPricingStep(index) setPricingStep(index)
@ -92,18 +92,18 @@ function usePricing(): UsePricing {
async function mint( async function mint(
tokensToMint: string, tokensToMint: string,
ddo: DDO ddo: Asset
): Promise<TransactionReceipt | void> { ): Promise<TransactionReceipt | void> {
const { dataToken } = ddo const { dataTokenInfo } = ddo
Logger.log('mint function', dataToken, accountId) Logger.log('mint function', dataTokenInfo.address, accountId)
const balance = new Decimal( const balance = new Decimal(
await ocean.datatokens.balance(dataToken, accountId) await ocean.datatokens.balance(dataTokenInfo.address, accountId)
) )
const tokens = new Decimal(tokensToMint) const tokens = new Decimal(tokensToMint)
if (tokens.greaterThan(balance)) { if (tokens.greaterThan(balance)) {
const mintAmount = tokens.minus(balance) const mintAmount = tokens.minus(balance)
const tx = await ocean.datatokens.mint( const tx = await ocean.datatokens.mint(
dataToken, dataTokenInfo.address,
accountId, accountId,
mintAmount.toString() mintAmount.toString()
) )
@ -114,7 +114,7 @@ function usePricing(): UsePricing {
async function buyDT( async function buyDT(
amountDataToken: number | string, amountDataToken: number | string,
price: BestPrice, price: BestPrice,
ddo: DDO ddo: Asset
): Promise<TransactionReceipt | void> { ): Promise<TransactionReceipt | void> {
if (!ocean || !accountId) return if (!ocean || !accountId) return
@ -181,18 +181,20 @@ function usePricing(): UsePricing {
case 'free': { case 'free': {
setStep(1, 'dispense', ddo) setStep(1, 'dispense', ddo)
const isDispensable = await ocean.OceanDispenser.isDispensable( const isDispensable = await ocean.OceanDispenser.isDispensable(
ddo.dataToken, ddo?.services[0].datatokenAddress,
accountId, accountId,
'1' '1'
) )
if (!isDispensable) { if (!isDispensable) {
Logger.error(`Dispenser for ${ddo.dataToken} failed to dispense`) Logger.error(
`Dispenser for ${ddo?.services[0].datatokenAddress} failed to dispense`
)
return return
} }
tx = await ocean.OceanDispenser.dispense( tx = await ocean.OceanDispenser.dispense(
ddo.dataToken, ddo?.services[0].datatokenAddress,
accountId, accountId,
'1' '1'
) )
@ -215,9 +217,9 @@ function usePricing(): UsePricing {
async function createPricing( async function createPricing(
priceOptions: PriceOptions, priceOptions: PriceOptions,
ddo: DDO ddo: Asset
): Promise<TransactionReceipt | void> { ): Promise<TransactionReceipt | void> {
const { dataToken } = ddo const dataToken = ddo?.services[0].datatokenAddress
const dtSymbol = await getDTSymbol(ddo) const dtSymbol = await getDTSymbol(ddo)
if (!ocean || !accountId || !dtSymbol) return if (!ocean || !accountId || !dtSymbol) return

View File

@ -1,11 +1,10 @@
import { DDO, Logger, Metadata } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import { import {
Service, Service,
ServiceComputePrivacy, ServiceComputePrivacy,
ServiceType ServiceType
} from '@oceanprotocol/lib/dist/node/ddo/interfaces/Service' } from '@oceanprotocol/lib/dist/node/ddo/interfaces/Service'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { sleep } from '@utils/index'
import { publishFeedback } from '@utils/feedback' import { publishFeedback } from '@utils/feedback'
import { useOcean } from '@context/Ocean' import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3' import { useWeb3 } from '@context/Web3'
@ -19,12 +18,12 @@ export interface DataTokenOptions {
interface UsePublish { interface UsePublish {
publish: ( publish: (
asset: Metadata, asset: DDO,
serviceType: ServiceType, serviceType: ServiceType,
dataTokenOptions?: DataTokenOptions, dataTokenOptions?: DataTokenOptions,
timeout?: number, timeout?: number,
providerUri?: string providerUri?: string
) => Promise<DDO | undefined | null> ) => Promise<Asset>
publishStep?: number publishStep?: number
publishStepText?: string publishStepText?: string
publishError?: string publishError?: string
@ -63,15 +62,15 @@ function usePublish(): UsePublish {
* @param {PriceOptions} priceOptions : number of tokens to mint, datatoken weight , liquidity fee, type : fixed, dynamic * @param {PriceOptions} priceOptions : number of tokens to mint, datatoken weight , liquidity fee, type : fixed, dynamic
* @param {ServiceType} serviceType Desired service type of the asset access or compute * @param {ServiceType} serviceType Desired service type of the asset access or compute
* @param {DataTokenOptions} dataTokenOptions custom name, symbol and cap for datatoken * @param {DataTokenOptions} dataTokenOptions custom name, symbol and cap for datatoken
* @return {Promise<DDO>} Returns the newly published ddo * @return {Promise<Asset>} Returns the newly published ddo
*/ */
async function publish( async function publish(
asset: Metadata, asset: Asset,
serviceType: ServiceType, serviceType: ServiceType,
dataTokenOptions?: DataTokenOptions, dataTokenOptions?: DataTokenOptions,
timeout?: number, timeout?: number,
providerUri?: string providerUri?: string
): Promise<DDO | undefined | null> { ): Promise<Asset> {
if (!ocean || !account) return null if (!ocean || !account) return null
setIsLoading(true) setIsLoading(true)
setPublishError(undefined) setPublishError(undefined)
@ -82,7 +81,7 @@ function usePublish(): UsePublish {
new Date(Date.now()).toISOString().split('.')[0] + 'Z' new Date(Date.now()).toISOString().split('.')[0] + 'Z'
const services: Service[] = [] const services: Service[] = []
const price = '1' const price = '1'
asset.main.dateCreated = asset.main.datePublished = publishedDate asset.created = publishedDate
switch (serviceType) { switch (serviceType) {
case 'access': { case 'access': {
@ -125,24 +124,24 @@ function usePublish(): UsePublish {
Logger.log('services created', services) Logger.log('services created', services)
const ddo = await ocean.assets // const ddo = await ocean.assets
.create( // .create(
asset, // asset,
account, // account,
services, // services,
undefined, // undefined,
dataTokenOptions?.cap, // dataTokenOptions?.cap,
dataTokenOptions?.name, // dataTokenOptions?.name,
dataTokenOptions?.symbol, // dataTokenOptions?.symbol,
providerUri // providerUri
) // )
.next(setStep) // .next(setStep)
Logger.log('ddo created', ddo) // Logger.log('ddo created', ddo)
await ocean.assets.publishDdo(ddo, account.getId()) // await ocean.assets.publishDdo(ddo, account.getId())
Logger.log('ddo published') // Logger.log('ddo published')
await sleep(20000) // await sleep(20000)
setStep(7) // setStep(7)
return ddo // return ddo
} catch (error) { } catch (error) {
setPublishError(error.message) setPublishError(error.message)
Logger.error(error) Logger.error(error)

33
src/@types/Asset.d.ts vendored Normal file
View File

@ -0,0 +1,33 @@
interface AssetNft {
address: string
name: string
symbol: string
owner: string
state: 0 | 1 | 2 | 3 | 4
}
interface AssetDatatoken {
name: string
symbol: string
address: string
serviceId: string
}
interface AssetLastEvent {
tx: string
block: number
from: string
contract: string
}
interface Asset extends DDO {
nft: AssetNft
datatokens: AssetDatatoken[]
event: AssetLastEvent
stats: { consume: number }
isInPurgatory: string
// This is fake and most likely won't be used like this.
// Just here so we can continue to have successful builds.
dataTokenInfo: AssetDatatoken
}

9
src/@types/DDO/Credentials.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
interface Credential {
type: string
values: string[]
}
interface Credentials {
allow: Credential[]
deny: Credential[]
}

18
src/@types/DDO/File.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
// This is all super questionable,
// but we most likely need something to represent what we get
// back from fileinfo endpoint in Provider. But then should be moved out of DDO typings.
interface FileMetadata {
url: string
contentType: string
name?: string
checksum?: string
checksumType?: string
contentLength?: string
encoding?: string
compression?: string
encrypted?: boolean
encryptionMode?: string
resourceId?: string
attributes?: { [key: string]: any }
}

24
src/@types/DDO/Metadata.d.ts vendored Normal file
View File

@ -0,0 +1,24 @@
interface MetadataAlgorithm {
language?: string
version?: string
container: {
entrypoint: string
image: string
tag: string
checksum: string
}
}
interface Metadata {
name: string
description: string
type: 'dataset' | 'algorithm'
author: string
license: string
links?: string[]
tags?: string[]
copyrightHolder?: string
contentLanguage?: string
algorithm?: MetadataAlgorithm
additionalInformation?: any
}

23
src/@types/DDO/Services.d.ts vendored Normal file
View File

@ -0,0 +1,23 @@
interface PublisherTrustedAlgorithm {
did: string
filesChecksum: string
containerSectionChecksum: string
}
interface ServiceComputePrivacy {
allowRawAlgorithm: boolean
allowNetworkAccess: boolean
publisherTrustedAlgorithmPublishers: string[]
publisherTrustedAlgorithms: PublisherTrustedAlgorithm[]
}
interface Service {
type: 'access' | 'compute' | string
files: string
datatokenAddress: string
serviceEndpoint: string
timeout: string
name?: string
description?: string
privacy?: ServiceComputePrivacy
}

12
src/@types/DDO/index.d.ts vendored Normal file
View File

@ -0,0 +1,12 @@
// DDO spec
interface DDO {
'@context': string[]
id: string
version: string
chainId: number
created: string
updated?: string
metadata: Metadata
services: Service[]
credentials?: Credentials
}

View File

@ -1,12 +1,6 @@
import { DDO } from '@oceanprotocol/lib' interface DownloadedAsset {
dtSymbol: string
// declaring into global scope to be able to use this as timestamp: number
// ambiant types despite the above imports networkId: number
declare global { ddo: Asset
interface DownloadedAsset {
dtSymbol: string
timestamp: number
networkId: number
ddo: DDO
}
} }

View File

@ -1,34 +0,0 @@
import {
Metadata,
AdditionalInformation,
EditableMetadataLinks
} from '@oceanprotocol/lib'
// declaring into global scope to be able to use this as
// ambiant types despite the above imports
declare global {
interface DdoMarket {
metadata: any
services: any[]
}
interface AdditionalInformationMarket extends AdditionalInformation {
termsAndConditions: boolean
}
interface MetadataMarket extends Metadata {
// While required for this market, Aquarius/Plecos will keep this as optional
// allowing external pushes of assets without `additionalInformation`.
// Making it optional here helps safeguarding against those assets.
additionalInformation?: AdditionalInformationMarket
}
interface MetadataEditForm {
name: string
description: string
timeout: string
price?: number
links?: string | EditableMetadataLinks[]
author?: string
}
}

View File

@ -1,12 +1,6 @@
import { DDO } from '@oceanprotocol/lib' interface PagedAssets {
results: Asset[]
// declaring into global scope to be able to use this as page: number
// ambiant types despite the above imports totalPages: number
declare global { totalResults: number
interface PagedAssets {
results: DDO[]
page: number
totalPages: number
totalResults: number
}
} }

View File

@ -1,46 +1,41 @@
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable camelcase */ /* eslint-disable camelcase */
import { DDO } from '@oceanprotocol/lib'
// declaring into global scope to be able to use this as interface Explanation {
// ambiant types despite the above imports value: number
declare global { description: string
interface Explanation { details: Explanation[]
value: number }
description: string
details: Explanation[] interface ShardsResponse {
} total: number
successful: number
interface ShardsResponse { failed: number
total: number skipped: number
successful: number }
failed: number
skipped: number interface SearchResponse {
} took: number
timed_out: boolean
interface SearchResponse { _scroll_id?: string | undefined
took: number _shards: ShardsResponse
timed_out: boolean hits: {
_scroll_id?: string | undefined total: number
_shards: ShardsResponse max_score: number
hits: { hits: Array<{
total: number _index: string
max_score: number _type: string
hits: Array<{ _id: string
_index: string _score: number
_type: string _source: Asset
_id: string _version?: number | undefined
_score: number _explanation?: Explanation | undefined
_source: DDO fields?: any
_version?: number | undefined highlight?: any
_explanation?: Explanation | undefined inner_hits?: any
fields?: any matched_queries?: string[] | undefined
highlight?: any sort?: string[] | undefined
inner_hits?: any }>
matched_queries?: string[] | undefined }
sort?: string[] | undefined aggregations?: any
}>
}
aggregations?: any
}
} }

View File

@ -1,9 +1,4 @@
import { import { Logger } from '@oceanprotocol/lib'
DDO,
DID,
Logger,
publisherTrustedAlgorithm as PublisherTrustedAlgorithm
} from '@oceanprotocol/lib'
import { AssetSelectionAsset } from '@shared/Form/FormFields/AssetSelection' import { AssetSelectionAsset } from '@shared/Form/FormFields/AssetSelection'
import { PriceList, getAssetsPriceList } from './subgraph' import { PriceList, getAssetsPriceList } from './subgraph'
import axios, { CancelToken, AxiosResponse } from 'axios' import axios, { CancelToken, AxiosResponse } from 'axios'
@ -13,6 +8,7 @@ import {
SortDirectionOptions, SortDirectionOptions,
SortTermOptions SortTermOptions
} from '../@types/aquarius/SearchQuery' } from '../@types/aquarius/SearchQuery'
import { getServiceByName } from './ddo'
export const MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS = 476 export const MAXIMUM_NUMBER_OF_PAGES_WITH_RESULTS = 476
@ -77,7 +73,7 @@ export function transformQueryResult(
} }
result.results = (queryResult.hits.hits || []).map( result.results = (queryResult.hits.hits || []).map(
(hit) => new DDO(hit._source as DDO) (hit) => hit._source as Asset
) )
result.totalResults = queryResult.hits.total result.totalResults = queryResult.hits.total
result.totalPages = result.totalPages =
@ -111,18 +107,18 @@ export async function queryMetadata(
} }
export async function retrieveDDO( export async function retrieveDDO(
did: string | DID, did: string,
cancelToken: CancelToken cancelToken: CancelToken
): Promise<DDO> { ): Promise<Asset> {
try { try {
const response: AxiosResponse<DDO> = await axios.get( const response: AxiosResponse<Asset> = await axios.get(
`${metadataCacheUri}/api/v1/aquarius/assets/ddo/${did}`, `${metadataCacheUri}/api/v1/aquarius/assets/ddo/${did}`,
{ cancelToken } { cancelToken }
) )
if (!response || response.status !== 200 || !response.data) return if (!response || response.status !== 200 || !response.data) return
const data = { ...response.data } const data = { ...response.data }
return new DDO(data) return data
} catch (error) { } catch (error) {
if (axios.isCancel(error)) { if (axios.isCancel(error)) {
Logger.log(error.message) Logger.log(error.message)
@ -133,7 +129,7 @@ export async function retrieveDDO(
} }
export async function getAssetsNames( export async function getAssetsNames(
didList: string[] | DID[], didList: string[],
cancelToken: CancelToken cancelToken: CancelToken
): Promise<Record<string, string>> { ): Promise<Record<string, string>> {
try { try {
@ -179,10 +175,10 @@ export async function retrieveDDOListByDIDs(
didList: string[], didList: string[],
chainIds: number[], chainIds: number[],
cancelToken: CancelToken cancelToken: CancelToken
): Promise<DDO[]> { ): Promise<Asset[]> {
try { try {
if (didList?.length === 0 || chainIds?.length === 0) return [] if (didList?.length === 0 || chainIds?.length === 0) return []
const orderedDDOListByDIDList: DDO[] = [] const orderedDDOListByDIDList: Asset[] = []
const baseQueryparams = { const baseQueryparams = {
chainIds, chainIds,
filters: [getFilterTerm('id', didList)], filters: [getFilterTerm('id', didList)],
@ -190,8 +186,8 @@ export async function retrieveDDOListByDIDs(
} as BaseQueryParams } as BaseQueryParams
const query = generateBaseQuery(baseQueryparams) const query = generateBaseQuery(baseQueryparams)
const result = await queryMetadata(query, cancelToken) const result = await queryMetadata(query, cancelToken)
didList.forEach((did: string | DID) => { didList.forEach((did: string) => {
const ddo: DDO = result.results.find((ddo: DDO) => ddo.id === did) const ddo = result.results.find((ddo: Asset) => ddo.id === did)
orderedDDOListByDIDList.push(ddo) orderedDDOListByDIDList.push(ddo)
}) })
return orderedDDOListByDIDList return orderedDDOListByDIDList
@ -202,7 +198,7 @@ export async function retrieveDDOListByDIDs(
export async function transformDDOToAssetSelection( export async function transformDDOToAssetSelection(
datasetProviderEndpoint: string, datasetProviderEndpoint: string,
ddoList: DDO[], ddoList: Asset[],
selectedAlgorithms?: PublisherTrustedAlgorithm[], selectedAlgorithms?: PublisherTrustedAlgorithm[],
cancelToken?: CancelToken cancelToken?: CancelToken
): Promise<AssetSelectionAsset[]> { ): Promise<AssetSelectionAsset[]> {
@ -213,7 +209,7 @@ export async function transformDDOToAssetSelection(
for (const ddo of ddoList) { for (const ddo of ddoList) {
didList.push(ddo.id) didList.push(ddo.id)
symbolList[ddo.id] = ddo.dataTokenInfo.symbol symbolList[ddo.id] = ddo.dataTokenInfo.symbol
const algoComputeService = ddo.findServiceByType('compute') const algoComputeService = getServiceByName(ddo, 'compute')
algoComputeService?.serviceEndpoint && algoComputeService?.serviceEndpoint &&
(didProviderEndpointMap[ddo.id] = algoComputeService?.serviceEndpoint) (didProviderEndpointMap[ddo.id] = algoComputeService?.serviceEndpoint)
} }
@ -350,7 +346,8 @@ export async function getDownloadAssets(
.map((ddo) => { .map((ddo) => {
const order = tokenOrders.find( const order = tokenOrders.find(
({ datatokenId }) => ({ datatokenId }) =>
datatokenId?.address.toLowerCase() === ddo.dataToken.toLowerCase() datatokenId?.address.toLowerCase() ===
ddo.services[0].datatokenAddress.toLowerCase()
) )
return { return {

View File

@ -1,21 +1,23 @@
import { DDO, Ocean, ServiceType } from '@oceanprotocol/lib' import { Ocean } from '@oceanprotocol/lib'
import { getServiceByName } from './ddo'
export default async function checkPreviousOrder( export default async function checkPreviousOrder(
ocean: Ocean, ocean: Ocean,
accountId: string, accountId: string,
ddo: DDO, ddo: Asset,
serviceType: ServiceType serviceType: 'access' | 'compute'
): Promise<string> { ): Promise<string> {
if (!ocean) return if (!ocean) return
const service = ddo.findServiceByType(serviceType) const service = getServiceByName(ddo, serviceType)
// apparenlty cost and timeout are not found, even though they are there... // apparenlty cost and timeout are not found, even though they are there...
const previousOrder = await ocean.datatokens.getPreviousValidOrders( // const previousOrder = await ocean.datatokens.getPreviousValidOrders(
ddo.dataToken, // ddo?.services[0].datatokenAddress,
(service.attributes.main as any).cost, // service.cost,
service.index, // service.index,
(service.attributes.main as any).timeout, // service.timeout,
accountId // accountId
) // )
return previousOrder // return previousOrder
return 'dummy'
} }

View File

@ -1,7 +1,6 @@
import { import {
ServiceComputePrivacy, ServiceComputePrivacy,
publisherTrustedAlgorithm as PublisherTrustedAlgorithm, publisherTrustedAlgorithm as PublisherTrustedAlgorithm,
DDO,
Service, Service,
Logger, Logger,
Provider, Provider,
@ -59,7 +58,7 @@ async function getAssetMetadata(
queryDtList: string[], queryDtList: string[],
cancelToken: CancelToken, cancelToken: CancelToken,
chainIds: number[] chainIds: number[]
): Promise<DDO[]> { ): Promise<Asset[]> {
const baseQueryparams = { const baseQueryparams = {
chainIds, chainIds,
filters: [ filters: [
@ -75,35 +74,37 @@ async function getAssetMetadata(
return result.results return result.results
} }
function getServiceEndpoints(data: TokenOrder[], assets: DDO[]): string[] { function getServiceEndpoints(data: TokenOrder[], assets: Asset[]): string[] {
const serviceEndpoints: string[] = [] // const serviceEndpoints: string[] = []
for (let i = 0; i < data.length; i++) { // for (let i = 0; i < data.length; i++) {
try { // try {
const did = web3.utils // const did = web3.utils
.toChecksumAddress(data[i].datatokenId.address) // .toChecksumAddress(data[i].datatokenId.address)
.replace('0x', 'did:op:') // .replace('0x', 'did:op:')
const ddo = assets.filter((x) => x.id === did)[0] // const ddo = assets.filter((x) => x.id === did)[0]
if (ddo === undefined) continue // if (ddo === undefined) continue
const service = ddo.service.filter( // const service = ddo.services.filter(
(x: Service) => x.index === data[i].serviceId // (x: Service) => x.index === data[i].serviceId
)[0] // )[0]
if (!service || service.type !== 'compute') continue // if (!service || service.type !== 'compute') continue
const { serviceEndpoint } = service // const { providerEndpoint } = service
const wasProviderQueried = // const wasProviderQueried =
serviceEndpoints?.filter((x) => x === serviceEndpoint).length > 0 // serviceEndpoints?.filter((x) => x === providerEndpoint).length > 0
if (wasProviderQueried) continue // if (wasProviderQueried) continue
serviceEndpoints.push(serviceEndpoint) // serviceEndpoints.push(providerEndpoint)
} catch (err) { // } catch (err) {
Logger.error(err.message) // Logger.error(err.message)
} // }
} // }
return serviceEndpoints // return serviceEndpoints
return ['dummy']
} }
async function getProviders( async function getProviders(
@ -138,7 +139,7 @@ async function getProviders(
async function getJobs( async function getJobs(
providers: Provider[], providers: Provider[],
account: Account, account: Account,
assets: DDO[] assets: Asset[]
): Promise<ComputeJobMetaData[]> { ): Promise<ComputeJobMetaData[]> {
const computeJobs: ComputeJobMetaData[] = [] const computeJobs: ComputeJobMetaData[] = []
@ -170,13 +171,10 @@ async function getJobs(
const ddo = assets.filter((x) => x.id === did)[0] const ddo = assets.filter((x) => x.id === did)[0]
if (!ddo) continue if (!ddo) continue
const serviceMetadata = ddo.service.filter(
(x: Service) => x.type === 'metadata'
)[0]
const compJob: ComputeJobMetaData = { const compJob: ComputeJobMetaData = {
...job, ...job,
assetName: serviceMetadata.attributes.main.name, assetName: ddo.metadata.name,
assetDtSymbol: ddo.dataTokenInfo.symbol, assetDtSymbol: ddo.dataTokenInfo.symbol,
networkId: ddo.chainId networkId: ddo.chainId
} }
@ -205,7 +203,7 @@ export async function getComputeJobs(
config: Config, config: Config,
ocean: Ocean, ocean: Ocean,
account: Account, account: Account,
ddo?: DDO, ddo?: Asset,
token?: CancelToken token?: CancelToken
): Promise<ComputeResults> { ): Promise<ComputeResults> {
const assetDTAddress = ddo?.dataTokenInfo?.address const assetDTAddress = ddo?.dataTokenInfo?.address

View File

@ -1,8 +1,15 @@
import axios from 'axios'
import { toast } from 'react-toastify'
import isUrl from 'is-url-superb'
import slugify from 'slugify' import slugify from 'slugify'
import { MetadataAlgorithm, Logger } from '@oceanprotocol/lib' import { MetadataAlgorithm } from '@oceanprotocol/lib'
export function getServiceByName(
ddo: Asset | DDO,
name: 'access' | 'compute'
): Service {
if (!ddo) return
const service = ddo.services.filter((service) => service.type === name)[0]
return service
}
export function dateToStringNoMS(date: Date): string { export function dateToStringNoMS(date: Date): string {
return date.toISOString().replace(/\.[0-9]{3}Z/, 'Z') return date.toISOString().replace(/\.[0-9]{3}Z/, 'Z')

View File

@ -1,6 +1,6 @@
import axios, { CancelToken, AxiosResponse } from 'axios' import axios, { CancelToken, AxiosResponse } from 'axios'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { DID, File as FileMetadata, Logger } from '@oceanprotocol/lib' import { DID, Logger } from '@oceanprotocol/lib'
export async function fileinfo( export async function fileinfo(
url: string, url: string,

View File

@ -1,5 +1,5 @@
import { gql, OperationResult, TypedDocumentNode, OperationContext } from 'urql' import { gql, OperationResult, TypedDocumentNode, OperationContext } from 'urql'
import { DDO, Logger } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import { getUrqlClientInstance } from '@context/UrqlProvider' import { getUrqlClientInstance } from '@context/UrqlProvider'
import { getOceanConfig } from './ocean' import { getOceanConfig } from './ocean'
import { import {
@ -35,7 +35,7 @@ export interface PriceList {
} }
export interface AssetListPrices { export interface AssetListPrices {
ddo: DDO ddo: Asset
price: BestPrice price: BestPrice
} }
@ -402,7 +402,7 @@ function transformPriceToBestPrice(
} }
async function getAssetsPoolsExchangesAndDatatokenMap( async function getAssetsPoolsExchangesAndDatatokenMap(
assets: DDO[] assets: Asset[]
): Promise< ): Promise<
[ [
AssetsPoolPricePool[], AssetsPoolPricePool[],
@ -415,13 +415,17 @@ async function getAssetsPoolsExchangesAndDatatokenMap(
const chainAssetLists: any = {} const chainAssetLists: any = {}
for (const ddo of assets) { for (const ddo of assets) {
didDTMap[ddo?.dataToken.toLowerCase()] = ddo.id didDTMap[ddo?.services[0].datatokenAddress.toLowerCase()] = ddo.id
// harcoded until we have chainId on assets // harcoded until we have chainId on assets
if (chainAssetLists[ddo.chainId]) { if (chainAssetLists[ddo.chainId]) {
chainAssetLists[ddo.chainId].push(ddo?.dataToken.toLowerCase()) chainAssetLists[ddo.chainId].push(
ddo?.services[0].datatokenAddress.toLowerCase()
)
} else { } else {
chainAssetLists[ddo.chainId] = [] chainAssetLists[ddo.chainId] = []
chainAssetLists[ddo.chainId].push(ddo?.dataToken.toLowerCase()) chainAssetLists[ddo.chainId].push(
ddo?.services[0].datatokenAddress.toLowerCase()
)
} }
} }
let poolPriceResponse: AssetsPoolPricePool[] = [] let poolPriceResponse: AssetsPoolPricePool[] = []
@ -464,7 +468,7 @@ async function getAssetsPoolsExchangesAndDatatokenMap(
return [poolPriceResponse, frePriceResponse, freePriceResponse, didDTMap] return [poolPriceResponse, frePriceResponse, freePriceResponse, didDTMap]
} }
export async function getAssetsPriceList(assets: DDO[]): Promise<PriceList> { export async function getAssetsPriceList(assets: Asset[]): Promise<PriceList> {
const priceList: PriceList = {} const priceList: PriceList = {}
const values: [ const values: [
@ -493,15 +497,15 @@ export async function getAssetsPriceList(assets: DDO[]): Promise<PriceList> {
return priceList return priceList
} }
export async function getPrice(asset: DDO): Promise<BestPrice> { export async function getPrice(asset: Asset): Promise<BestPrice> {
const freVariables = { const freVariables = {
datatoken: asset?.dataToken.toLowerCase() datatoken: asset?.services[0].datatokenAddress.toLowerCase()
} }
const freeVariables = { const freeVariables = {
datatoken: asset?.dataToken.toLowerCase() datatoken: asset?.services[0].datatokenAddress.toLowerCase()
} }
const poolVariables = { const poolVariables = {
datatokenAddress: asset?.dataToken.toLowerCase() datatokenAddress: asset?.services[0].datatokenAddress.toLowerCase()
} }
const queryContext = getQueryContext(Number(asset.chainId)) const queryContext = getQueryContext(Number(asset.chainId))
@ -530,9 +534,9 @@ export async function getPrice(asset: DDO): Promise<BestPrice> {
return bestPrice return bestPrice
} }
export async function getSpotPrice(asset: DDO): Promise<number> { export async function getSpotPrice(asset: Asset): Promise<number> {
const poolVariables = { const poolVariables = {
datatokenAddress: asset?.dataToken.toLowerCase() datatokenAddress: asset?.services[0].datatokenAddress.toLowerCase()
} }
const queryContext = getQueryContext(Number(asset.chainId)) const queryContext = getQueryContext(Number(asset.chainId))
@ -546,7 +550,7 @@ export async function getSpotPrice(asset: DDO): Promise<number> {
} }
export async function getAssetsBestPrices( export async function getAssetsBestPrices(
assets: DDO[] assets: Asset[]
): Promise<AssetListPrices[]> { ): Promise<AssetListPrices[]> {
const assetsWithPrice: AssetListPrices[] = [] const assetsWithPrice: AssetListPrices[] = []
@ -561,7 +565,7 @@ export async function getAssetsBestPrices(
const frePriceResponse = values[1] const frePriceResponse = values[1]
const freePriceResponse = values[2] const freePriceResponse = values[2]
for (const ddo of assets) { for (const ddo of assets) {
const dataToken = ddo.dataToken.toLowerCase() const dataToken = ddo.services[0].datatokenAddress.toLowerCase()
const poolPrice: AssetsPoolPricePool[] = [] const poolPrice: AssetsPoolPricePool[] = []
const frePrice: AssetsFrePriceFixedRateExchange[] = [] const frePrice: AssetsFrePriceFixedRateExchange[] = []
const freePrice: AssetFreePriceDispenser[] = [] const freePrice: AssetFreePriceDispenser[] = []

View File

@ -2,7 +2,6 @@ import AssetTeaser from '@shared/AssetTeaser/AssetTeaser'
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import Pagination from '@shared/Pagination' import Pagination from '@shared/Pagination'
import styles from './AssetList.module.css' import styles from './AssetList.module.css'
import { DDO } from '@oceanprotocol/lib'
import classNames from 'classnames/bind' import classNames from 'classnames/bind'
import { getAssetsBestPrices, AssetListPrices } from '@utils/subgraph' import { getAssetsBestPrices, AssetListPrices } from '@utils/subgraph'
import Loader from '@shared/atoms/Loader' import Loader from '@shared/atoms/Loader'
@ -20,7 +19,7 @@ function LoaderArea() {
} }
declare type AssetListProps = { declare type AssetListProps = {
assets: DDO[] assets: Asset[]
showPagination: boolean showPagination: boolean
page?: number page?: number
totalPages?: number totalPages?: number

View File

@ -1,4 +1,3 @@
import { DDO } from '@oceanprotocol/lib'
import Link from 'next/link' import Link from 'next/link'
import React, { ReactElement, useEffect, useState } from 'react' import React, { ReactElement, useEffect, useState } from 'react'
import { getAssetsNames } from '@utils/aquarius' import { getAssetsNames } from '@utils/aquarius'
@ -11,7 +10,7 @@ export default function AssetListTitle({
did, did,
title title
}: { }: {
ddo?: DDO ddo?: Asset
did?: string did?: string
title?: string title?: string
}): ReactElement { }): ReactElement {
@ -21,8 +20,7 @@ export default function AssetListTitle({
useEffect(() => { useEffect(() => {
if (title || !appConfig.metadataCacheUri) return if (title || !appConfig.metadataCacheUri) return
if (ddo) { if (ddo) {
const { attributes } = ddo.findServiceByType('metadata') setAssetTitle(ddo.metadata.name)
setAssetTitle(attributes.main.name)
return return
} }

View File

@ -2,15 +2,15 @@ import React from 'react'
import Link from 'next/link' import Link from 'next/link'
import Dotdotdot from 'react-dotdotdot' import Dotdotdot from 'react-dotdotdot'
import Price from '@shared/Price' import Price from '@shared/Price'
import { DDO } from '@oceanprotocol/lib'
import removeMarkdown from 'remove-markdown' import removeMarkdown from 'remove-markdown'
import Publisher from '@shared/Publisher' import Publisher from '@shared/Publisher'
import AssetType from '@shared/AssetType' import AssetType from '@shared/AssetType'
import NetworkName from '@shared/NetworkName' import NetworkName from '@shared/NetworkName'
import styles from './AssetTeaser.module.css' import styles from './AssetTeaser.module.css'
import { getServiceByName } from '@utils/ddo'
declare type AssetTeaserProps = { declare type AssetTeaserProps = {
ddo: DDO ddo: Asset
price: BestPrice price: BestPrice
noPublisher?: boolean noPublisher?: boolean
} }
@ -20,12 +20,11 @@ const AssetTeaser: React.FC<AssetTeaserProps> = ({
price, price,
noPublisher noPublisher
}: AssetTeaserProps) => { }: AssetTeaserProps) => {
const { attributes } = ddo.findServiceByType('metadata') const { name, type, description } = ddo.metadata
const { name, type } = attributes.main
const { dataTokenInfo } = ddo const { dataTokenInfo } = ddo
const isCompute = Boolean(ddo?.findServiceByType('compute')) const isCompute = Boolean(getServiceByName(ddo, 'compute'))
const accessType = isCompute ? 'compute' : 'access' const accessType = isCompute ? 'compute' : 'access'
const { owner } = ddo.publicKey[0] const { owner } = ddo.nft
return ( return (
<article className={`${styles.teaser} ${styles[type]}`}> <article className={`${styles.teaser} ${styles[type]}`}>
@ -49,12 +48,7 @@ const AssetTeaser: React.FC<AssetTeaserProps> = ({
<div className={styles.content}> <div className={styles.content}>
<Dotdotdot tagName="p" clamp={3}> <Dotdotdot tagName="p" clamp={3}>
{removeMarkdown( {removeMarkdown(description?.substring(0, 300) || '')}
attributes?.additionalInformation?.description?.substring(
0,
300
) || ''
)}
</Dotdotdot> </Dotdotdot>
</div> </div>

View File

@ -1,5 +1,4 @@
import React, { ReactElement } from 'react' import React, { ReactElement } from 'react'
import { File as FileMetadata } from '@oceanprotocol/lib'
import filesize from 'filesize' import filesize from 'filesize'
import classNames from 'classnames/bind' import classNames from 'classnames/bind'
import cleanupContentType from '@utils/cleanupContentType' import cleanupContentType from '@utils/cleanupContentType'

View File

@ -1,5 +1,4 @@
import React, { ReactElement, useEffect } from 'react' import React, { ReactElement, useEffect } from 'react'
import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
import { prettySize } from './utils' import { prettySize } from './utils'
import cleanupContentType from '@utils/cleanupContentType' import cleanupContentType from '@utils/cleanupContentType'
import styles from './Info.module.css' import styles from './Info.module.css'

View File

@ -130,7 +130,7 @@ export default function InputElement({
) )
case 'files': case 'files':
return <FilesInput name={name} {...field} {...props} /> return <FilesInput name={name} {...field} {...props} />
case 'providerUri': case 'providerUrl':
return <CustomProvider name={name} {...field} {...props} /> return <CustomProvider name={name} {...field} {...props} />
case 'datatoken': case 'datatoken':
return <Datatoken name={name} {...field} {...props} /> return <Datatoken name={name} {...field} {...props} />

View File

@ -13,7 +13,7 @@ import { retrieveDDOListByDIDs } from '@utils/aquarius'
import { CancelToken } from 'axios' import { CancelToken } from 'axios'
import Title from './Title' import Title from './Title'
import styles from './index.module.css' import styles from './index.module.css'
import { DDO, Logger } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import { useCancelToken } from '@hooks/useCancelToken' import { useCancelToken } from '@hooks/useCancelToken'
const REFETCH_INTERVAL = 20000 const REFETCH_INTERVAL = 20000
@ -77,7 +77,7 @@ export interface Datatoken {
export interface PoolTransaction extends TransactionHistoryPoolTransactions { export interface PoolTransaction extends TransactionHistoryPoolTransactions {
networkId: number networkId: number
ddo: DDO ddo: Asset
} }
const columns = [ const columns = [

View File

@ -26,7 +26,9 @@ export default function TokenApproval({
const config = getOceanConfig(ddo.chainId) const config = getOceanConfig(ddo.chainId)
const tokenAddress = const tokenAddress =
coin === 'OCEAN' ? config.oceanTokenAddress : ddo.dataTokenInfo.address coin === 'OCEAN'
? config.oceanTokenAddress
: ddo.services[0].datatokenAddress
const spender = price.address const spender = price.address
const checkTokenApproval = useCallback(async () => { const checkTokenApproval = useCallback(async () => {

View File

@ -4,24 +4,25 @@ import { getAlgorithmDatasetsForCompute } from '@utils/aquarius'
import { AssetSelectionAsset } from '@shared/Form/FormFields/AssetSelection' import { AssetSelectionAsset } from '@shared/Form/FormFields/AssetSelection'
import AssetComputeList from '@shared/AssetList/AssetComputeList' import AssetComputeList from '@shared/AssetList/AssetComputeList'
import { useAsset } from '@context/Asset' import { useAsset } from '@context/Asset'
import { DDO } from '@oceanprotocol/lib'
import { useCancelToken } from '@hooks/useCancelToken' import { useCancelToken } from '@hooks/useCancelToken'
import { getServiceByName } from '@utils/ddo'
export default function AlgorithmDatasetsListForCompute({ export default function AlgorithmDatasetsListForCompute({
algorithmDid, algorithmDid,
dataset dataset
}: { }: {
algorithmDid: string algorithmDid: string
dataset: DDO dataset: Asset
}): ReactElement { }): ReactElement {
const { type } = useAsset() const { ddo } = useAsset()
const [datasetsForCompute, setDatasetsForCompute] = const [datasetsForCompute, setDatasetsForCompute] =
useState<AssetSelectionAsset[]>() useState<AssetSelectionAsset[]>()
const newCancelToken = useCancelToken() const newCancelToken = useCancelToken()
useEffect(() => { useEffect(() => {
async function getDatasetsAllowedForCompute() { async function getDatasetsAllowedForCompute() {
const isCompute = Boolean(dataset?.findServiceByType('compute')) const isCompute = Boolean(getServiceByName(dataset, 'compute'))
const datasetComputeService = dataset.findServiceByType( const datasetComputeService = getServiceByName(
dataset,
isCompute ? 'compute' : 'access' isCompute ? 'compute' : 'access'
) )
const datasets = await getAlgorithmDatasetsForCompute( const datasets = await getAlgorithmDatasetsForCompute(
@ -32,8 +33,8 @@ export default function AlgorithmDatasetsListForCompute({
) )
setDatasetsForCompute(datasets) setDatasetsForCompute(datasets)
} }
type === 'algorithm' && getDatasetsAllowedForCompute() ddo.metadata.type === 'algorithm' && getDatasetsAllowedForCompute()
}, [type]) }, [ddo.metadata.type])
return ( return (
<div className={styles.datasetsContainer}> <div className={styles.datasetsContainer}>

View File

@ -2,7 +2,6 @@ import React, { ReactElement, useEffect, useState } from 'react'
import styles from './FormComputeDataset.module.css' import styles from './FormComputeDataset.module.css'
import { Field, Form, FormikContextType, useFormikContext } from 'formik' import { Field, Form, FormikContextType, useFormikContext } from 'formik'
import Input from '@shared/Form/Input' import Input from '@shared/Form/Input'
import { DDO } from '@oceanprotocol/lib'
import { AssetSelectionAsset } from '@shared/Form/FormFields/AssetSelection' import { AssetSelectionAsset } from '@shared/Form/FormFields/AssetSelection'
import { compareAsBN } from '@utils/numbers' import { compareAsBN } from '@utils/numbers'
import ButtonBuy from '@shared/ButtonBuy' import ButtonBuy from '@shared/ButtonBuy'
@ -38,8 +37,8 @@ export default function FormStartCompute({
consumableFeedback consumableFeedback
}: { }: {
algorithms: AssetSelectionAsset[] algorithms: AssetSelectionAsset[]
ddoListAlgorithms: DDO[] ddoListAlgorithms: Asset[]
setSelectedAlgorithm: React.Dispatch<React.SetStateAction<DDO>> setSelectedAlgorithm: React.Dispatch<React.SetStateAction<Asset>>
isLoading: boolean isLoading: boolean
isComputeButtonDisabled: boolean isComputeButtonDisabled: boolean
hasPreviousOrder: boolean hasPreviousOrder: boolean
@ -71,9 +70,9 @@ export default function FormStartCompute({
const [algorithmConsumableStatus, setAlgorithmConsumableStatus] = const [algorithmConsumableStatus, setAlgorithmConsumableStatus] =
useState<number>() useState<number>()
function getAlgorithmAsset(algorithmId: string): DDO { function getAlgorithmAsset(algorithmId: string): Asset {
let assetDdo = null let assetDdo = null
ddoListAlgorithms.forEach((ddo: DDO) => { ddoListAlgorithms.forEach((ddo: Asset) => {
if (ddo.id === algorithmId) assetDdo = ddo if (ddo.id === algorithmId) assetDdo = ddo
}) })
return assetDdo return assetDdo
@ -87,7 +86,7 @@ export default function FormStartCompute({
if (!accountId || !isConsumable) return if (!accountId || !isConsumable) return
async function checkIsConsumable() { async function checkIsConsumable() {
const consumable = await ocean.assets.isConsumable( const consumable = await ocean.assets.isConsumable(
algorithmDDO, algorithmDDO as any,
accountId.toLowerCase() accountId.toLowerCase()
) )
if (consumable) setAlgorithmConsumableStatus(consumable.status) if (consumable) setAlgorithmConsumableStatus(consumable.status)

View File

@ -1,10 +1,5 @@
import React, { useState, ReactElement, useEffect, useCallback } from 'react' import React, { useState, ReactElement, useEffect, useCallback } from 'react'
import { import { Logger } from '@oceanprotocol/lib'
DDO,
File as FileMetadata,
Logger,
publisherTrustedAlgorithm
} from '@oceanprotocol/lib'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import Price from '@shared/Price' import Price from '@shared/Price'
import FileIcon from '@shared/FileIcon' import FileIcon from '@shared/FileIcon'
@ -30,7 +25,7 @@ import axios from 'axios'
import FormStartComputeDataset from './FormComputeDataset' import FormStartComputeDataset from './FormComputeDataset'
import styles from './index.module.css' import styles from './index.module.css'
import SuccessConfetti from '@shared/SuccessConfetti' import SuccessConfetti from '@shared/SuccessConfetti'
import { secondsToString } from '@utils/ddo' import { getServiceByName, secondsToString } from '@utils/ddo'
import { AssetSelectionAsset } from '@shared/Form/FormFields/AssetSelection' import { AssetSelectionAsset } from '@shared/Form/FormFields/AssetSelection'
import AlgorithmDatasetsListForCompute from './AlgorithmDatasetsListForCompute' import AlgorithmDatasetsListForCompute from './AlgorithmDatasetsListForCompute'
import { getPreviousOrders, getPrice } from '@utils/subgraph' import { getPreviousOrders, getPrice } from '@utils/subgraph'
@ -56,14 +51,14 @@ export default function Compute({
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
const { accountId } = useWeb3() const { accountId } = useWeb3()
const { ocean, account } = useOcean() const { ocean, account } = useOcean()
const { price, type, ddo } = useAsset() const { price, ddo } = useAsset()
const { buyDT, pricingError, pricingStepText } = usePricing() const { buyDT, pricingError, pricingStepText } = usePricing()
const [isJobStarting, setIsJobStarting] = useState(false) const [isJobStarting, setIsJobStarting] = useState(false)
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
const [algorithmList, setAlgorithmList] = useState<AssetSelectionAsset[]>() const [algorithmList, setAlgorithmList] = useState<AssetSelectionAsset[]>()
const [ddoAlgorithmList, setDdoAlgorithmList] = useState<DDO[]>() const [ddoAlgorithmList, setDdoAlgorithmList] = useState<Asset[]>()
const [selectedAlgorithmAsset, setSelectedAlgorithmAsset] = useState<DDO>() const [selectedAlgorithmAsset, setSelectedAlgorithmAsset] = useState<Asset>()
const [hasAlgoAssetDatatoken, setHasAlgoAssetDatatoken] = useState<boolean>() const [hasAlgoAssetDatatoken, setHasAlgoAssetDatatoken] = useState<boolean>()
const [isPublished, setIsPublished] = useState(false) const [isPublished, setIsPublished] = useState(false)
const [hasPreviousDatasetOrder, setHasPreviousDatasetOrder] = useState(false) const [hasPreviousDatasetOrder, setHasPreviousDatasetOrder] = useState(false)
@ -90,19 +85,19 @@ export default function Compute({
!hasAlgoAssetDatatoken && !hasAlgoAssetDatatoken &&
!isAlgoConsumablePrice) !isAlgoConsumablePrice)
const { timeout } = ddo?.services[0]
async function checkPreviousOrders(ddo: DDO) { async function checkPreviousOrders(ddo: DDO) {
const { timeout } = ( const { type } = ddo.metadata
ddo.findServiceByType('access') || ddo.findServiceByType('compute')
).attributes.main
const orderId = await getPreviousOrders( const orderId = await getPreviousOrders(
ddo.dataToken?.toLowerCase(), ddo.services[0].datatokenAddress?.toLowerCase(),
accountId?.toLowerCase(), accountId?.toLowerCase(),
timeout.toString() timeout.toString()
) )
const assetType = ddo.findServiceByType('metadata').attributes.main.type
if (!isMounted()) return if (!isMounted()) return
if (assetType === 'algorithm') { if (type === 'algorithm') {
setPreviousAlgorithmOrderId(orderId) setPreviousAlgorithmOrderId(orderId)
setHasPreviousAlgorithmOrder(!!orderId) setHasPreviousAlgorithmOrder(!!orderId)
} else { } else {
@ -113,7 +108,7 @@ export default function Compute({
async function checkAssetDTBalance(asset: DDO) { async function checkAssetDTBalance(asset: DDO) {
const AssetDtBalance = await ocean.datatokens.balance( const AssetDtBalance = await ocean.datatokens.balance(
asset.dataToken, asset.services[0].datatokenAddress,
accountId accountId
) )
setalgorithmDTBalance(AssetDtBalance) setalgorithmDTBalance(AssetDtBalance)
@ -121,7 +116,7 @@ export default function Compute({
} }
function getQuerryString( function getQuerryString(
trustedAlgorithmList: publisherTrustedAlgorithm[], trustedAlgorithmList: PublisherTrustedAlgorithm[],
chainId?: number chainId?: number
): SearchQuery { ): SearchQuery {
const algorithmDidList = trustedAlgorithmList.map((x) => x.did) const algorithmDidList = trustedAlgorithmList.map((x) => x.did)
@ -141,28 +136,26 @@ export default function Compute({
async function getAlgorithmList(): Promise<AssetSelectionAsset[]> { async function getAlgorithmList(): Promise<AssetSelectionAsset[]> {
const source = axios.CancelToken.source() const source = axios.CancelToken.source()
const computeService = ddo.findServiceByType('compute') const computeService = ddo.services[0]
let algorithmSelectionList: AssetSelectionAsset[] let algorithmSelectionList: AssetSelectionAsset[]
if ( if (
!computeService.attributes.main.privacy || !computeService.privacy ||
!computeService.attributes.main.privacy.publisherTrustedAlgorithms || !computeService.privacy.publisherTrustedAlgorithms ||
(computeService.attributes.main.privacy.publisherTrustedAlgorithms computeService.privacy.publisherTrustedAlgorithms.length === 0
.length === 0 &&
!computeService.attributes.main.privacy.allowAllPublishedAlgorithms)
) { ) {
algorithmSelectionList = [] algorithmSelectionList = []
} else { } else {
const gueryResults = await queryMetadata( const gueryResults = await queryMetadata(
getQuerryString( getQuerryString(
computeService.attributes.main.privacy.publisherTrustedAlgorithms, computeService.privacy.publisherTrustedAlgorithms,
ddo.chainId ddo.chainId
), ),
source.token source.token
) )
setDdoAlgorithmList(gueryResults.results) setDdoAlgorithmList(gueryResults.results)
const datasetComputeService = ddo.findServiceByType('compute')
algorithmSelectionList = await transformDDOToAssetSelection( algorithmSelectionList = await transformDDOToAssetSelection(
datasetComputeService?.serviceEndpoint, computeService?.serviceEndpoint,
gueryResults.results, gueryResults.results,
[], [],
newCancelToken() newCancelToken()
@ -171,7 +164,7 @@ export default function Compute({
return algorithmSelectionList return algorithmSelectionList
} }
const initMetadata = useCallback(async (ddo: DDO): Promise<void> => { const initMetadata = useCallback(async (ddo: Asset): Promise<void> => {
if (!ddo) return if (!ddo) return
const price = await getPrice(ddo) const price = await getPrice(ddo)
setAlgorithmPrice(price) setAlgorithmPrice(price)
@ -186,6 +179,7 @@ export default function Compute({
: true : true
) )
}, [algorithmPrice]) }, [algorithmPrice])
useEffect(() => { useEffect(() => {
if (!price) return if (!price) return
@ -194,12 +188,9 @@ export default function Compute({
) )
}, [price]) }, [price])
useEffect(() => { // useEffect(() => {
const { timeout } = ( // setDatasetTimeout(secondsToString(timeout))
ddo.findServiceByType('access') || ddo.findServiceByType('compute') // }, [ddo])
).attributes.main
setDatasetTimeout(secondsToString(timeout))
}, [ddo])
useEffect(() => { useEffect(() => {
if (!ddo) return if (!ddo) return
@ -218,27 +209,26 @@ export default function Compute({
initMetadata(selectedAlgorithmAsset) initMetadata(selectedAlgorithmAsset)
const { timeout } = ( const { timeout } = ddo.services[0]
ddo.findServiceByType('access') || ddo.findServiceByType('compute')
).attributes.main // setAlgorithmTimeout(secondsToString(timeout))
setAlgorithmTimeout(secondsToString(timeout))
if (accountId) { if (accountId) {
if (selectedAlgorithmAsset.findServiceByType('access')) { if (getServiceByName(selectedAlgorithmAsset, 'access')) {
checkPreviousOrders(selectedAlgorithmAsset).then(() => { checkPreviousOrders(selectedAlgorithmAsset).then(() => {
if ( if (
!hasPreviousAlgorithmOrder && !hasPreviousAlgorithmOrder &&
selectedAlgorithmAsset.findServiceByType('compute') getServiceByName(selectedAlgorithmAsset, 'compute')
) { ) {
checkPreviousOrders(selectedAlgorithmAsset) checkPreviousOrders(selectedAlgorithmAsset)
} }
}) })
} else if (selectedAlgorithmAsset.findServiceByType('compute')) { } else if (getServiceByName(selectedAlgorithmAsset, 'compute')) {
checkPreviousOrders(selectedAlgorithmAsset) checkPreviousOrders(selectedAlgorithmAsset)
} }
} }
ocean && checkAssetDTBalance(selectedAlgorithmAsset) ocean && checkAssetDTBalance(selectedAlgorithmAsset)
}, [selectedAlgorithmAsset, ocean, accountId, hasPreviousAlgorithmOrder]) }, [ddo, selectedAlgorithmAsset, ocean, accountId, hasPreviousAlgorithmOrder])
// Output errors in toast UI // Output errors in toast UI
useEffect(() => { useEffect(() => {
@ -247,153 +237,153 @@ export default function Compute({
toast.error(newError) toast.error(newError)
}, [error, pricingError]) }, [error, pricingError])
async function startJob(algorithmId: string) { // async function startJob(algorithmId: string) {
try { // try {
if (!ocean) return // if (!ocean) return
setIsJobStarting(true) // setIsJobStarting(true)
setIsPublished(false) // setIsPublished(false)
setError(undefined) // setError(undefined)
const computeService = ddo.findServiceByType('compute') // const computeService = getServiceByName(ddo, 'compute')
const serviceAlgo = selectedAlgorithmAsset.findServiceByType('access') // const serviceAlgo = getServiceByName(selectedAlgorithmAsset, 'access')
? selectedAlgorithmAsset.findServiceByType('access') // ? getServiceByName(selectedAlgorithmAsset, 'access')
: selectedAlgorithmAsset.findServiceByType('compute') // : getServiceByName(selectedAlgorithmAsset, 'compute')
const computeAlgorithm: ComputeAlgorithm = { // const computeAlgorithm: ComputeAlgorithm = {
did: selectedAlgorithmAsset.id, // did: selectedAlgorithmAsset.id,
serviceIndex: serviceAlgo.index, // serviceIndex: serviceAlgo.index,
dataToken: selectedAlgorithmAsset.dataToken // dataToken: selectedAlgorithmAsset.services[0].datatokenAddress
} // }
const allowed = await ocean.compute.isOrderable( // const allowed = await ocean.compute.isOrderable(
ddo.id, // ddo.id,
computeService.index, // computeService.index,
computeAlgorithm // computeAlgorithm
) // )
Logger.log('[compute] Is data set orderable?', allowed) // Logger.log('[compute] Is data set orderable?', allowed)
if (!allowed) { // if (!allowed) {
setError( // setError(
'Data set is not orderable in combination with selected algorithm.' // 'Data set is not orderable in combination with selected algorithm.'
) // )
Logger.error( // Logger.error(
'[compute] Error starting compute job. Dataset is not orderable in combination with selected algorithm.' // '[compute] Error starting compute job. Dataset is not orderable in combination with selected algorithm.'
) // )
return // return
} // }
if (!hasPreviousDatasetOrder && !hasDatatoken) { // if (!hasPreviousDatasetOrder && !hasDatatoken) {
const tx = await buyDT('1', price, ddo) // const tx = await buyDT('1', price, ddo)
if (!tx) { // if (!tx) {
setError('Error buying datatoken.') // setError('Error buying datatoken.')
Logger.error('[compute] Error buying datatoken for data set ', ddo.id) // Logger.error('[compute] Error buying datatoken for data set ', ddo.id)
return // return
} // }
} // }
if (!hasPreviousAlgorithmOrder && !hasAlgoAssetDatatoken) { // if (!hasPreviousAlgorithmOrder && !hasAlgoAssetDatatoken) {
const tx = await buyDT('1', algorithmPrice, selectedAlgorithmAsset) // const tx = await buyDT('1', algorithmPrice, selectedAlgorithmAsset)
if (!tx) { // if (!tx) {
setError('Error buying datatoken.') // setError('Error buying datatoken.')
Logger.error( // Logger.error(
'[compute] Error buying datatoken for algorithm ', // '[compute] Error buying datatoken for algorithm ',
selectedAlgorithmAsset.id // selectedAlgorithmAsset.id
) // )
return // return
} // }
} // }
// TODO: pricingError is always undefined even upon errors during buyDT for whatever reason. // // TODO: pricingError is always undefined even upon errors during buyDT for whatever reason.
// So manually drop out above, but ideally could be replaced with this alone. // // So manually drop out above, but ideally could be replaced with this alone.
if (pricingError) { // if (pricingError) {
setError(pricingError) // setError(pricingError)
return // return
} // }
const assetOrderId = hasPreviousDatasetOrder // const assetOrderId = hasPreviousDatasetOrder
? previousDatasetOrderId // ? previousDatasetOrderId
: await ocean.compute.orderAsset( // : await ocean.compute.orderAsset(
accountId, // accountId,
ddo.id, // ddo.id,
computeService.index, // computeService.index,
computeAlgorithm, // computeAlgorithm,
appConfig.marketFeeAddress, // appConfig.marketFeeAddress,
undefined, // undefined,
null, // null,
false // false
) // )
assetOrderId && // assetOrderId &&
Logger.log( // Logger.log(
`[compute] Got ${ // `[compute] Got ${
hasPreviousDatasetOrder ? 'existing' : 'new' // hasPreviousDatasetOrder ? 'existing' : 'new'
} order ID for dataset: `, // } order ID for dataset: `,
assetOrderId // assetOrderId
) // )
const algorithmAssetOrderId = hasPreviousAlgorithmOrder // const algorithmAssetOrderId = hasPreviousAlgorithmOrder
? previousAlgorithmOrderId // ? previousAlgorithmOrderId
: await ocean.compute.orderAlgorithm( // : await ocean.compute.orderAlgorithm(
algorithmId, // algorithmId,
serviceAlgo.type, // serviceAlgo.type,
accountId, // accountId,
serviceAlgo.index, // serviceAlgo.index,
appConfig.marketFeeAddress, // appConfig.marketFeeAddress,
undefined, // undefined,
null, // null,
false // false
) // )
algorithmAssetOrderId && // algorithmAssetOrderId &&
Logger.log( // Logger.log(
`[compute] Got ${ // `[compute] Got ${
hasPreviousAlgorithmOrder ? 'existing' : 'new' // hasPreviousAlgorithmOrder ? 'existing' : 'new'
} order ID for algorithm: `, // } order ID for algorithm: `,
algorithmAssetOrderId // algorithmAssetOrderId
) // )
if (!assetOrderId || !algorithmAssetOrderId) { // if (!assetOrderId || !algorithmAssetOrderId) {
setError('Error ordering assets.') // setError('Error ordering assets.')
return // return
} // }
computeAlgorithm.transferTxId = algorithmAssetOrderId // computeAlgorithm.transferTxId = algorithmAssetOrderId
Logger.log('[compute] Starting compute job.') // Logger.log('[compute] Starting compute job.')
const output: ComputeOutput = { // const output: ComputeOutput = {
publishAlgorithmLog: true, // publishAlgorithmLog: true,
publishOutput: true // publishOutput: true
} // }
const response = await ocean.compute.start( // const response = await ocean.compute.start(
ddo.id, // ddo.id,
assetOrderId, // assetOrderId,
ddo.dataToken, // ddo.services[0].datatokenAddress,
account, // account,
computeAlgorithm, // computeAlgorithm,
output, // output,
`${computeService.index}`, // `${computeService.index}`,
computeService.type // computeService.type
) // )
if (!response) { // if (!response) {
setError('Error starting compute job.') // setError('Error starting compute job.')
return // return
} // }
Logger.log('[compute] Starting compute job response: ', response) // Logger.log('[compute] Starting compute job response: ', response)
await checkPreviousOrders(selectedAlgorithmAsset) // await checkPreviousOrders(selectedAlgorithmAsset)
await checkPreviousOrders(ddo) // await checkPreviousOrders(ddo)
setIsPublished(true) // setIsPublished(true)
} catch (error) { // } catch (error) {
await checkPreviousOrders(selectedAlgorithmAsset) // await checkPreviousOrders(selectedAlgorithmAsset)
await checkPreviousOrders(ddo) // await checkPreviousOrders(ddo)
setError('Failed to start job!') // setError('Failed to start job!')
Logger.error('[compute] Failed to start job: ', error.message) // Logger.error('[compute] Failed to start job: ', error.message)
} finally { // } finally {
setIsJobStarting(false) // setIsJobStarting(false)
} // }
} // }
return ( return (
<> <>
@ -402,7 +392,7 @@ export default function Compute({
<Price price={price} conversion /> <Price price={price} conversion />
</div> </div>
{type === 'algorithm' ? ( {ddo.metadata.type === 'algorithm' ? (
<> <>
<Alert <Alert
text="This algorithm has been set to private by the publisher and can't be downloaded. You can run it against any allowed data sets though!" text="This algorithm has been set to private by the publisher and can't be downloaded. You can run it against any allowed data sets though!"
@ -418,7 +408,9 @@ export default function Compute({
initialValues={getInitialValues()} initialValues={getInitialValues()}
validateOnMount validateOnMount
validationSchema={validationSchema} validationSchema={validationSchema}
onSubmit={async (values) => await startJob(values.algorithm)} onSubmit={async (values) => {
// await startJob(values.algorithm)
}}
> >
<FormStartComputeDataset <FormStartComputeDataset
algorithms={algorithmList} algorithms={algorithmList}
@ -430,7 +422,7 @@ export default function Compute({
hasDatatoken={hasDatatoken} hasDatatoken={hasDatatoken}
dtBalance={dtBalance} dtBalance={dtBalance}
datasetLowPoolLiquidity={!isConsumablePrice} datasetLowPoolLiquidity={!isConsumablePrice}
assetType={type} assetType={ddo.metadata.type}
assetTimeout={datasetTimeout} assetTimeout={datasetTimeout}
hasPreviousOrderSelectedComputeAsset={hasPreviousAlgorithmOrder} hasPreviousOrderSelectedComputeAsset={hasPreviousAlgorithmOrder}
hasDatatokenSelectedComputeAsset={hasAlgoAssetDatatoken} hasDatatokenSelectedComputeAsset={hasAlgoAssetDatatoken}

View File

@ -1,6 +1,5 @@
import React, { ReactElement, useEffect, useState } from 'react' import React, { ReactElement, useEffect, useState } from 'react'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { File as FileMetadata, DDO } from '@oceanprotocol/lib'
import FileIcon from '@shared/FileIcon' import FileIcon from '@shared/FileIcon'
import Price from '@shared/Price' import Price from '@shared/Price'
import { useSiteMetadata } from '@hooks/useSiteMetadata' import { useSiteMetadata } from '@hooks/useSiteMetadata'
@ -42,7 +41,7 @@ export default function Consume({
isConsumable, isConsumable,
consumableFeedback consumableFeedback
}: { }: {
ddo: DDO ddo: Asset
file: FileMetadata file: FileMetadata
isBalanceSufficient: boolean isBalanceSufficient: boolean
dtBalance: string dtBalance: string
@ -55,7 +54,7 @@ export default function Consume({
const { appConfig } = useSiteMetadata() const { appConfig } = useSiteMetadata()
const [hasPreviousOrder, setHasPreviousOrder] = useState(false) const [hasPreviousOrder, setHasPreviousOrder] = useState(false)
const [previousOrderId, setPreviousOrderId] = useState<string>() const [previousOrderId, setPreviousOrderId] = useState<string>()
const { isInPurgatory, price, type, isAssetNetwork } = useAsset() const { isInPurgatory, price, isAssetNetwork } = useAsset()
const { buyDT, pricingStepText, pricingError, pricingIsLoading } = const { buyDT, pricingStepText, pricingError, pricingIsLoading } =
usePricing() usePricing()
const { consumeStepText, consume, consumeError, isLoading } = useConsume() const { consumeStepText, consume, consumeError, isLoading } = useConsume()
@ -70,7 +69,7 @@ export default function Consume({
if (!ddo || !accountId) return if (!ddo || !accountId) return
const context = getQueryContext(ddo.chainId) const context = getQueryContext(ddo.chainId)
const variables = { const variables = {
id: ddo.dataToken?.toLowerCase(), id: ddo.services[0].datatokenAddress?.toLowerCase(),
account: accountId?.toLowerCase() account: accountId?.toLowerCase()
} }
fetchData(previousOrderQuery, variables, context).then((result: any) => { fetchData(previousOrderQuery, variables, context).then((result: any) => {
@ -105,7 +104,7 @@ export default function Consume({
}, [data, assetTimeout, accountId, isAssetNetwork]) }, [data, assetTimeout, accountId, isAssetNetwork])
useEffect(() => { useEffect(() => {
const { timeout } = ddo.findServiceByType('access').attributes.main const { timeout } = ddo.services[0]
setAssetTimeout(`${timeout}`) setAssetTimeout(`${timeout}`)
}, [ddo]) }, [ddo])
@ -154,7 +153,7 @@ export default function Consume({
} }
const error = await consume( const error = await consume(
ddo.id, ddo.id,
ddo.dataToken, ddo.services[0].datatokenAddress,
'access', 'access',
appConfig.marketFeeAddress, appConfig.marketFeeAddress,
previousOrderId previousOrderId
@ -177,12 +176,12 @@ export default function Consume({
disabled={isDisabled} disabled={isDisabled}
hasPreviousOrder={hasPreviousOrder} hasPreviousOrder={hasPreviousOrder}
hasDatatoken={hasDatatoken} hasDatatoken={hasDatatoken}
dtSymbol={ddo.dataTokenInfo?.symbol} dtSymbol={ddo?.dataTokenInfo?.symbol}
dtBalance={dtBalance} dtBalance={dtBalance}
datasetLowPoolLiquidity={!isConsumablePrice} datasetLowPoolLiquidity={!isConsumablePrice}
onClick={handleConsume} onClick={handleConsume}
assetTimeout={secondsToString(parseInt(assetTimeout))} assetTimeout={secondsToString(parseInt(assetTimeout))}
assetType={type} assetType={ddo?.metadata.type}
stepText={consumeStepText || pricingStepText} stepText={consumeStepText || pricingStepText}
isLoading={pricingIsLoading || isLoading} isLoading={pricingIsLoading || isLoading}
priceType={price?.type} priceType={price?.type}
@ -203,7 +202,7 @@ export default function Consume({
{!isInPurgatory && <PurchaseButton />} {!isInPurgatory && <PurchaseButton />}
</div> </div>
</div> </div>
{type === 'algorithm' && ( {ddo.metadata.type === 'algorithm' && (
<AlgorithmDatasetsListForCompute algorithmDid={ddo.id} dataset={ddo} /> <AlgorithmDatasetsListForCompute algorithmDid={ddo.id} dataset={ddo} />
)} )}
</aside> </aside>

View File

@ -1,4 +1,4 @@
import { DDO, ServiceComputePrivacy } from '@oceanprotocol/lib' import { ServiceComputePrivacy } from '@oceanprotocol/lib'
import React, { ReactElement, useEffect, useState } from 'react' import React, { ReactElement, useEffect, useState } from 'react'
import { useOcean } from '@context/Ocean' import { useOcean } from '@context/Ocean'
import { transformComputeFormToServiceComputePrivacy } from '@utils/compute' import { transformComputeFormToServiceComputePrivacy } from '@utils/compute'
@ -9,7 +9,7 @@ export default function DebugEditCompute({
ddo ddo
}: { }: {
values: ComputePrivacyForm values: ComputePrivacyForm
ddo: DDO ddo: Asset
}): ReactElement { }): ReactElement {
const { ocean } = useOcean() const { ocean } = useOcean()
const [formTransformed, setFormTransformed] = const [formTransformed, setFormTransformed] =

View File

@ -32,59 +32,56 @@ export default function EditComputeDataset({
values: ComputePrivacyForm, values: ComputePrivacyForm,
resetForm: () => void resetForm: () => void
) { ) {
try { // try {
if (price.type === 'free') { // if (price.type === 'free') {
const tx = await setMinterToPublisher( // const tx = await setMinterToPublisher(
ocean, // ocean,
ddo.dataToken, // ddo.services[0].datatokenAddress,
accountId, // accountId,
setError // setError
) // )
if (!tx) return // if (!tx) return
} // }
const privacy = await transformComputeFormToServiceComputePrivacy( // const privacy = await transformComputeFormToServiceComputePrivacy(
values, // values,
ocean // ocean
) // )
// const ddoEditedComputePrivacy = await ocean.compute.editComputePrivacy(
const ddoEditedComputePrivacy = await ocean.compute.editComputePrivacy( // ddo,
ddo, // 1,
1, // privacy as ServiceComputePrivacy
privacy as ServiceComputePrivacy // )
) // if (!ddoEditedComputePrivacy) {
// setError(content.form.error)
if (!ddoEditedComputePrivacy) { // Logger.error(content.form.error)
setError(content.form.error) // return
Logger.error(content.form.error) // }
return // const storedddo = await ocean.assets.updateMetadata(
} // ddoEditedComputePrivacy,
// accountId
const storedddo = await ocean.assets.updateMetadata( // )
ddoEditedComputePrivacy, // if (!storedddo) {
accountId // setError(content.form.error)
) // Logger.error(content.form.error)
if (!storedddo) { // return
setError(content.form.error) // } else {
Logger.error(content.form.error) // if (price.type === 'free') {
return // const tx = await setMinterToDispenser(
} else { // ocean,
if (price.type === 'free') { // ddo.services[0].datatokenAddress,
const tx = await setMinterToDispenser( // accountId,
ocean, // setError
ddo.dataToken, // )
accountId, // if (!tx) return
setError // }
) // // Edit succeeded
if (!tx) return // setSuccess(content.form.success)
} // resetForm()
// Edit succeeded // }
setSuccess(content.form.success) // } catch (error) {
resetForm() // Logger.error(error.message)
} // setError(error.message)
} catch (error) { // }
Logger.error(error.message)
setError(error.message)
}
} }
return ( return (
@ -100,7 +97,7 @@ export default function EditComputeDataset({
// move user's focus to top of screen // move user's focus to top of screen
window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }) window.scrollTo({ top: 0, left: 0, behavior: 'smooth' })
// kick off editing // kick off editing
// await handleSubmit(values, resetForm) await handleSubmit(values as any, resetForm)
}} }}
> >
{({ values, isSubmitting }) => {({ values, isSubmitting }) =>

View File

@ -16,6 +16,7 @@ import { useSiteMetadata } from '@hooks/useSiteMetadata'
import FormActions from './FormActions' import FormActions from './FormActions'
import { useCancelToken } from '@hooks/useCancelToken' import { useCancelToken } from '@hooks/useCancelToken'
import { SortTermOptions } from '../../../../@types/aquarius/SearchQuery' import { SortTermOptions } from '../../../../@types/aquarius/SearchQuery'
import { getServiceByName } from '@utils/ddo'
export default function FormEditComputeDataset({ export default function FormEditComputeDataset({
data, data,
@ -31,8 +32,10 @@ export default function FormEditComputeDataset({
const { values }: FormikContextType<ComputePrivacyForm> = useFormikContext() const { values }: FormikContextType<ComputePrivacyForm> = useFormikContext()
const [allAlgorithms, setAllAlgorithms] = useState<AssetSelectionAsset[]>() const [allAlgorithms, setAllAlgorithms] = useState<AssetSelectionAsset[]>()
const newCancelToken = useCancelToken() const newCancelToken = useCancelToken()
const { publisherTrustedAlgorithms } = const { publisherTrustedAlgorithms } = getServiceByName(
ddo?.findServiceByType('compute').attributes.main.privacy ddo,
'compute'
).privacy
async function getAlgorithmList( async function getAlgorithmList(
publisherTrustedAlgorithms: PublisherTrustedAlgorithm[] publisherTrustedAlgorithms: PublisherTrustedAlgorithm[]
@ -45,7 +48,7 @@ export default function FormEditComputeDataset({
const query = generateBaseQuery(baseParams) const query = generateBaseQuery(baseParams)
const querryResult = await queryMetadata(query, newCancelToken()) const querryResult = await queryMetadata(query, newCancelToken())
const datasetComputeService = ddo.findServiceByType('compute') const datasetComputeService = getServiceByName(ddo, 'compute')
const algorithmSelectionList = await transformDDOToAssetSelection( const algorithmSelectionList = await transformDDOToAssetSelection(
datasetComputeService?.serviceEndpoint, datasetComputeService?.serviceEndpoint,
querryResult.results, querryResult.results,

View File

@ -1,6 +1,7 @@
import { secondsToString } from '@utils/ddo' import { secondsToString } from '@utils/ddo'
import { EditableMetadataLinks } from '@oceanprotocol/lib' import { EditableMetadataLinks } from '@oceanprotocol/lib'
import * as Yup from 'yup' import * as Yup from 'yup'
import { MetadataEditForm } from './_types'
export const validationSchema = Yup.object().shape({ export const validationSchema = Yup.object().shape({
name: Yup.string() name: Yup.string()
@ -14,16 +15,16 @@ export const validationSchema = Yup.object().shape({
}) })
export function getInitialValues( export function getInitialValues(
metadata: MetadataMarket, metadata: Metadata,
timeout: number, timeout: string,
price: number price: number
): Partial<MetadataEditForm> { ): Partial<MetadataEditForm> {
return { return {
name: metadata.main.name, name: metadata.name,
description: metadata.additionalInformation.description, description: metadata.description,
price, price,
timeout: secondsToString(timeout), timeout,
author: metadata.main.author author: metadata.author
} }
} }

View File

@ -0,0 +1,10 @@
import { EditableMetadataLinks } from '@oceanprotocol/lib'
export interface MetadataEditForm {
name: string
description: string
timeout: string
price?: number
links?: string | EditableMetadataLinks[]
author?: string
}

View File

@ -6,13 +6,14 @@ import { useUserPreferences } from '@context/UserPreferences'
// import Debug from './DebugEditMetadata' // import Debug from './DebugEditMetadata'
import Web3Feedback from '@shared/Web3Feedback' import Web3Feedback from '@shared/Web3Feedback'
import FormEditMetadata from './FormEditMetadata' import FormEditMetadata from './FormEditMetadata'
import { mapTimeoutStringToSeconds } from '@utils/ddo' import { getServiceByName, mapTimeoutStringToSeconds } from '@utils/ddo'
import styles from './index.module.css' import styles from './index.module.css'
import { Logger } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import { useWeb3 } from '@context/Web3' import { useWeb3 } from '@context/Web3'
import { useOcean } from '@context/Ocean' import { useOcean } from '@context/Ocean'
import { setMinterToDispenser, setMinterToPublisher } from '@utils/freePrice' import { setMinterToDispenser, setMinterToPublisher } from '@utils/freePrice'
import content from '../../../../../content/pages/edit.json' import content from '../../../../../content/pages/edit.json'
import { MetadataEditForm } from './_types'
export default function Edit({ export default function Edit({
setShowEdit, setShowEdit,
@ -24,13 +25,11 @@ export default function Edit({
const { debug } = useUserPreferences() const { debug } = useUserPreferences()
const { accountId } = useWeb3() const { accountId } = useWeb3()
const { ocean } = useOcean() const { ocean } = useOcean()
const { metadata, ddo, refreshDdo, price } = useAsset() const { ddo, refreshDdo, price } = useAsset()
const [success, setSuccess] = useState<string>() const [success, setSuccess] = useState<string>()
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
const [timeoutStringValue, setTimeoutStringValue] = useState<string>() const [timeoutStringValue, setTimeoutStringValue] = useState<string>()
const timeout = ddo.findServiceByType('access') const { timeout } = ddo.services[0]
? ddo.findServiceByType('access').attributes.main.timeout
: ddo.findServiceByType('compute').attributes.main.timeout
const hasFeedback = error || success const hasFeedback = error || success
@ -50,83 +49,79 @@ export default function Edit({
values: Partial<MetadataEditForm>, values: Partial<MetadataEditForm>,
resetForm: () => void resetForm: () => void
) { ) {
try { // try {
if (price.type === 'free') { // if (price.type === 'free') {
const tx = await setMinterToPublisher( // const tx = await setMinterToPublisher(
ocean, // ocean,
ddo.dataToken, // ddo.services[0].datatokenAddress,
accountId, // accountId,
setError // setError
) // )
if (!tx) return // if (!tx) return
} // }
// Construct new DDO with new values // // Construct new DDO with new values
const ddoEditedMetdata = await ocean.assets.editMetadata(ddo, { // const ddoEditedMetdata = await ocean.assets.editMetadata(ddo as any, {
title: values.name, // title: values.name,
description: values.description, // description: values.description,
links: typeof values.links !== 'string' ? values.links : [], // links: typeof values.links !== 'string' ? values.links : [],
author: values.author === '' ? ' ' : values.author // author: values.author === '' ? ' ' : values.author
}) // })
// price.type === 'exchange' &&
price.type === 'exchange' && // values.price !== price.value &&
values.price !== price.value && // (await updateFixedPrice(values.price))
(await updateFixedPrice(values.price)) // if (!ddoEditedMetdata) {
// setError(content.form.error)
if (!ddoEditedMetdata) { // Logger.error(content.form.error)
setError(content.form.error) // return
Logger.error(content.form.error) // }
return // let ddoEditedTimeout = ddoEditedMetdata
} // if (timeoutStringValue !== values.timeout) {
let ddoEditedTimeout = ddoEditedMetdata // const service =
if (timeoutStringValue !== values.timeout) { // getServiceByName(ddoEditedMetdata, 'access') ||
const service = // getServiceByName(ddoEditedMetdata, 'compute')
ddoEditedMetdata.findServiceByType('access') || // const timeout = mapTimeoutStringToSeconds(values.timeout)
ddoEditedMetdata.findServiceByType('compute') // ddoEditedTimeout = await ocean.assets.editServiceTimeout(
const timeout = mapTimeoutStringToSeconds(values.timeout) // ddoEditedMetdata,
ddoEditedTimeout = await ocean.assets.editServiceTimeout( // service.index,
ddoEditedMetdata, // timeout
service.index, // )
timeout // }
) // if (!ddoEditedTimeout) {
} // setError(content.form.error)
// Logger.error(content.form.error)
if (!ddoEditedTimeout) { // return
setError(content.form.error) // }
Logger.error(content.form.error) // const storedddo = await ocean.assets.updateMetadata(
return // ddoEditedTimeout,
} // accountId
// )
const storedddo = await ocean.assets.updateMetadata( // if (!storedddo) {
ddoEditedTimeout, // setError(content.form.error)
accountId // Logger.error(content.form.error)
) // return
if (!storedddo) { // } else {
setError(content.form.error) // if (price.type === 'free') {
Logger.error(content.form.error) // const tx = await setMinterToDispenser(
return // ocean,
} else { // ddo.services[0].datatokenAddress,
if (price.type === 'free') { // accountId,
const tx = await setMinterToDispenser( // setError
ocean, // )
ddo.dataToken, // if (!tx) return
accountId, // }
setError // // Edit succeeded
) // setSuccess(content.form.success)
if (!tx) return // resetForm()
} // }
// Edit succeeded // } catch (error) {
setSuccess(content.form.success) // Logger.error(error.message)
resetForm() // setError(error.message)
} // }
} catch (error) {
Logger.error(error.message)
setError(error.message)
}
} }
return ( return (
<Formik <Formik
initialValues={getInitialValues(metadata, timeout, price.value)} initialValues={getInitialValues(ddo.metadata, timeout, price.value)}
validationSchema={validationSchema} validationSchema={validationSchema}
onSubmit={async (values, { resetForm }) => { onSubmit={async (values, { resetForm }) => {
// move user's focus to top of screen // move user's focus to top of screen

View File

@ -103,7 +103,7 @@ export default function Pool(): ReactElement {
const queryContext = getQueryContext(ddo.chainId) const queryContext = getQueryContext(ddo.chainId)
const queryVariables = { const queryVariables = {
id: price.address.toLowerCase(), id: price.address.toLowerCase(),
shareId: `${price.address.toLowerCase()}-${ddo.publicKey[0].owner.toLowerCase()}` shareId: `${price.address.toLowerCase()}-${ddo.nft.owner.toLowerCase()}`
} }
const queryResult: OperationResult<PoolLiquidity> = await fetchData( const queryResult: OperationResult<PoolLiquidity> = await fetchData(
@ -172,7 +172,8 @@ export default function Pool(): ReactElement {
// Get weights // Get weights
const weightDt = dataLiquidity.pool.tokens.filter( const weightDt = dataLiquidity.pool.tokens.filter(
(token: any) => token.address === ddo.dataToken.toLowerCase() (token: any) =>
token.address === ddo.services[0].datatokenAddress.toLowerCase()
)[0].denormWeight )[0].denormWeight
const weightDtDecimal = isValidNumber(weightDt) const weightDtDecimal = isValidNumber(weightDt)
@ -249,7 +250,7 @@ export default function Pool(): ReactElement {
refetchLiquidity() refetchLiquidity()
} }
init() init()
}, [dataLiquidity, ddo.dataToken, price.datatoken, price.ocean, price?.value]) }, [dataLiquidity, ddo, price.datatoken, price.ocean, price?.value])
useEffect(() => { useEffect(() => {
setIsRemoveDisabled(isInPurgatory && owner === accountId) setIsRemoveDisabled(isInPurgatory && owner === accountId)
@ -360,7 +361,7 @@ export default function Pool(): ReactElement {
}} }}
swapFee={swapFee} swapFee={swapFee}
dtSymbol={dtSymbol} dtSymbol={dtSymbol}
dtAddress={ddo.dataToken} dtAddress={ddo.services[0].datatokenAddress}
/> />
) : showRemove ? ( ) : showRemove ? (
<Remove <Remove
@ -388,8 +389,8 @@ export default function Pool(): ReactElement {
networkId={ddo.chainId} networkId={ddo.chainId}
path={ path={
ddo.chainId === 2021000 || ddo.chainId === 1287 ddo.chainId === 2021000 || ddo.chainId === 1287
? `tokens/${ddo.dataToken}` ? `tokens/${ddo.services[0].datatokenAddress}`
: `token/${ddo.dataToken}` : `token/${ddo.services[0].datatokenAddress}`
} }
> >
Datatoken Datatoken

View File

@ -1,5 +1,5 @@
import React, { ReactElement, useState } from 'react' import React, { ReactElement, useState } from 'react'
import { DDO, Logger } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import * as Yup from 'yup' import * as Yup from 'yup'
import { Formik } from 'formik' import { Formik } from 'formik'
import Actions from '../Pool/Actions' import Actions from '../Pool/Actions'
@ -23,7 +23,7 @@ export default function FormTrade({
maxOcean, maxOcean,
price price
}: { }: {
ddo: DDO ddo: Asset
balance: PoolBalance balance: PoolBalance
maxDt: string maxDt: string
maxOcean: string maxOcean: string

View File

@ -1,5 +1,4 @@
import React, { ReactElement, useEffect, useState } from 'react' import React, { ReactElement, useEffect, useState } from 'react'
import { DDO } from '@oceanprotocol/lib'
import styles from './Swap.module.css' import styles from './Swap.module.css'
import TradeInput from './TradeInput' import TradeInput from './TradeInput'
import Button from '@shared/atoms/Button' import Button from '@shared/atoms/Button'
@ -26,7 +25,7 @@ export default function Swap({
setMaximumOcean, setMaximumOcean,
setCoin setCoin
}: { }: {
ddo: DDO ddo: Asset
maxDt: string maxDt: string
maxOcean: string maxOcean: string
balance: PoolBalance balance: PoolBalance
@ -149,7 +148,7 @@ export default function Swap({
setTotalValue(newValue) setTotalValue(newValue)
setTokenAmount(value.toString()) setTokenAmount(value.toString())
tokenIn = ddo.dataToken tokenIn = ddo.services[0].datatokenAddress
tokenOut = ocean.pool.oceanAddress tokenOut = ocean.pool.oceanAddress
} else { } else {
newValue = await ocean.pool.getDTReceived( newValue = await ocean.pool.getDTReceived(
@ -160,7 +159,7 @@ export default function Swap({
setTotalValue(value.toString()) setTotalValue(value.toString())
setTokenAmount(newValue) setTokenAmount(newValue)
tokenIn = ocean.pool.oceanAddress tokenIn = ocean.pool.oceanAddress
tokenOut = ddo.dataToken tokenOut = ddo.services[0].datatokenAddress
} }
} else { } else {
if (values.type === 'sell') { if (values.type === 'sell') {
@ -171,7 +170,7 @@ export default function Swap({
setTotalValue(value.toString()) setTotalValue(value.toString())
setTokenAmount(newValue) setTokenAmount(newValue)
tokenIn = ddo.dataToken tokenIn = ddo.services[0].datatokenAddress
tokenOut = ocean.pool.oceanAddress tokenOut = ocean.pool.oceanAddress
} else { } else {
newValue = await ocean.pool.getOceanNeeded( newValue = await ocean.pool.getOceanNeeded(
@ -182,7 +181,7 @@ export default function Swap({
setTotalValue(newValue) setTotalValue(newValue)
setTokenAmount(value.toString()) setTokenAmount(value.toString())
tokenIn = ocean.pool.oceanAddress tokenIn = ocean.pool.oceanAddress
tokenOut = ddo.dataToken tokenOut = ddo.services[0].datatokenAddress
} }
} }

View File

@ -25,19 +25,22 @@ export default function Trade(): ReactElement {
!isAssetNetwork || !isAssetNetwork ||
!balance?.ocean || !balance?.ocean ||
!accountId || !accountId ||
!ddo?.dataToken !ddo?.services[0].datatokenAddress
) )
return return
async function getTokenBalance() { async function getTokenBalance() {
const dtBalance = await ocean.datatokens.balance(ddo.dataToken, accountId) const dtBalance = await ocean.datatokens.balance(
ddo.services[0].datatokenAddress,
accountId
)
setTokenBalance({ setTokenBalance({
ocean: new Decimal(balance.ocean).toString(), ocean: new Decimal(balance.ocean).toString(),
datatoken: new Decimal(dtBalance).toString() datatoken: new Decimal(dtBalance).toString()
}) })
} }
getTokenBalance() getTokenBalance()
}, [balance.ocean, ocean, accountId, ddo.dataToken]) }, [balance.ocean, ocean, accountId, ddo, isAssetNetwork])
// Get maximum amount for either OCEAN or datatoken // Get maximum amount for either OCEAN or datatoken
useEffect(() => { useEffect(() => {

View File

@ -1,7 +1,7 @@
import React, { ReactElement, useState, useEffect } from 'react' import React, { ReactElement, useState, useEffect } from 'react'
import Compute from './Compute' import Compute from './Compute'
import Consume from './Consume' import Consume from './Consume'
import { Logger, File as FileMetadata, DID } from '@oceanprotocol/lib' import { Logger, DID } from '@oceanprotocol/lib'
import Tabs from '@shared/atoms/Tabs' import Tabs from '@shared/atoms/Tabs'
import { compareAsBN } from '@utils/numbers' import { compareAsBN } from '@utils/numbers'
import Pool from './Pool' import Pool from './Pool'
@ -25,27 +25,30 @@ export default function AssetActions(): ReactElement {
const [dtBalance, setDtBalance] = useState<string>() const [dtBalance, setDtBalance] = useState<string>()
const [fileMetadata, setFileMetadata] = useState<FileMetadata>(Object) const [fileMetadata, setFileMetadata] = useState<FileMetadata>(Object)
const [fileIsLoading, setFileIsLoading] = useState<boolean>(false) const [fileIsLoading, setFileIsLoading] = useState<boolean>(false)
const isCompute = Boolean(ddo?.findServiceByType('compute')) const isCompute = Boolean(
ddo?.services.filter((service) => service.type === 'compute')[0]
)
const [isConsumable, setIsConsumable] = useState<boolean>(true) const [isConsumable, setIsConsumable] = useState<boolean>(true)
const [consumableFeedback, setConsumableFeedback] = useState<string>('') const [consumableFeedback, setConsumableFeedback] = useState<string>('')
const newCancelToken = useCancelToken() const newCancelToken = useCancelToken()
const isMounted = useIsMounted() const isMounted = useIsMounted()
useEffect(() => {
if (!ddo || !accountId || !ocean || !isAssetNetwork) return
async function checkIsConsumable() { // useEffect(() => {
const consumable = await ocean.assets.isConsumable( // if (!ddo || !accountId || !ocean || !isAssetNetwork) return
ddo,
accountId.toLowerCase() // async function checkIsConsumable() {
) // const consumable = await ocean.assets.isConsumable(
if (consumable) { // ddo,
setIsConsumable(consumable.result) // accountId.toLowerCase()
setConsumableFeedback(consumable.message) // )
} // if (consumable) {
} // setIsConsumable(consumable.result)
checkIsConsumable() // setConsumableFeedback(consumable.message)
}, [accountId, isAssetNetwork, ddo, ocean]) // }
// }
// checkIsConsumable()
// }, [accountId, isAssetNetwork, ddo, ocean])
useEffect(() => { useEffect(() => {
const oceanConfig = getOceanConfig(ddo.chainId) const oceanConfig = getOceanConfig(ddo.chainId)
@ -74,7 +77,7 @@ export default function AssetActions(): ReactElement {
async function init() { async function init() {
try { try {
const dtBalance = await ocean.datatokens.balance( const dtBalance = await ocean.datatokens.balance(
ddo.dataToken, ddo.services[0].datatokenAddress,
accountId accountId
) )
setDtBalance(dtBalance) setDtBalance(dtBalance)
@ -83,7 +86,7 @@ export default function AssetActions(): ReactElement {
} }
} }
init() init()
}, [ocean, accountId, ddo.dataToken, isAssetNetwork]) }, [ocean, accountId, ddo, isAssetNetwork])
// Check user balance against price // Check user balance against price
useEffect(() => { useEffect(() => {

View File

@ -37,7 +37,7 @@ export default function EditHistory(): ReactElement {
const [result] = useQuery({ const [result] = useQuery({
query: getReceipts, query: getReceipts,
variables: { address: ddo?.dataToken.toLowerCase() }, variables: { address: ddo?.services[0].datatokenAddress.toLowerCase() },
context: queryContext, context: queryContext,
pause: !ddo || !queryContext pause: !ddo || !queryContext
}) })

View File

@ -5,22 +5,20 @@ import Publisher from '@shared/Publisher'
import { useAsset } from '@context/Asset' import { useAsset } from '@context/Asset'
export default function MetaFull(): ReactElement { export default function MetaFull(): ReactElement {
const { ddo, metadata, isInPurgatory, type } = useAsset() const { ddo, isInPurgatory } = useAsset()
const { algorithm } = ddo.findServiceByType('metadata').attributes.main const { type, author, algorithm } = ddo?.metadata
function DockerImage() { function DockerImage() {
const { image, tag } = algorithm.container const { image, tag } = algorithm?.container
return <span>{`${image}:${tag}`}</span> return <span>{`${image}:${tag}`}</span>
} }
return ( return (
<div className={styles.metaFull}> <div className={styles.metaFull}>
{!isInPurgatory && ( {!isInPurgatory && <MetaItem title="Data Author" content={author} />}
<MetaItem title="Data Author" content={metadata?.main.author} />
)}
<MetaItem <MetaItem
title="Owner" title="Owner"
content={<Publisher account={ddo?.publicKey[0].owner} />} content={<Publisher account={ddo?.nft?.owner} />}
/> />
{type === 'algorithm' && algorithm && ( {type === 'algorithm' && algorithm && (

View File

@ -7,12 +7,13 @@ import AddToken from '@shared/AddToken'
import Time from '@shared/atoms/Time' import Time from '@shared/atoms/Time'
import AssetType from '@shared/AssetType' import AssetType from '@shared/AssetType'
import styles from './MetaMain.module.css' import styles from './MetaMain.module.css'
import { getServiceByName } from '@utils/ddo'
export default function MetaMain(): ReactElement { export default function MetaMain(): ReactElement {
const { ddo, owner, type, isAssetNetwork } = useAsset() const { ddo, owner, isAssetNetwork } = useAsset()
const { web3ProviderInfo } = useWeb3() const { web3ProviderInfo } = useWeb3()
const isCompute = Boolean(ddo?.findServiceByType('compute')) const isCompute = Boolean(getServiceByName(ddo, 'compute'))
const accessType = isCompute ? 'compute' : 'access' const accessType = isCompute ? 'compute' : 'access'
const blockscoutNetworks = [1287, 2021000, 2021001, 44787, 246, 1285] const blockscoutNetworks = [1287, 2021000, 2021001, 44787, 246, 1285]
const isBlockscoutExplorer = blockscoutNetworks.includes(ddo?.chainId) const isBlockscoutExplorer = blockscoutNetworks.includes(ddo?.chainId)
@ -21,7 +22,7 @@ export default function MetaMain(): ReactElement {
<aside className={styles.meta}> <aside className={styles.meta}>
<header className={styles.asset}> <header className={styles.asset}>
<AssetType <AssetType
type={type} type={ddo?.metadata.type}
accessType={accessType} accessType={accessType}
className={styles.assetType} className={styles.assetType}
/> />
@ -30,8 +31,8 @@ export default function MetaMain(): ReactElement {
networkId={ddo?.chainId} networkId={ddo?.chainId}
path={ path={
isBlockscoutExplorer isBlockscoutExplorer
? `tokens/${ddo?.dataToken}` ? `tokens/${ddo?.services[0].datatokenAddress}`
: `token/${ddo?.dataToken}` : `token/${ddo?.services[0].datatokenAddress}`
} }
> >
{`${ddo?.dataTokenInfo.name}${ddo?.dataTokenInfo.symbol}`} {`${ddo?.dataTokenInfo.name}${ddo?.dataTokenInfo.symbol}`}
@ -40,7 +41,7 @@ export default function MetaMain(): ReactElement {
{web3ProviderInfo?.name === 'MetaMask' && isAssetNetwork && ( {web3ProviderInfo?.name === 'MetaMask' && isAssetNetwork && (
<span className={styles.addWrap}> <span className={styles.addWrap}>
<AddToken <AddToken
address={ddo?.dataTokenInfo.address} address={ddo?.services[0].datatokenAddress}
symbol={ddo?.dataTokenInfo.symbol} symbol={ddo?.dataTokenInfo.symbol}
logo="https://raw.githubusercontent.com/oceanprotocol/art/main/logo/datatoken.png" logo="https://raw.githubusercontent.com/oceanprotocol/art/main/logo/datatoken.png"
text={`Add ${ddo?.dataTokenInfo.symbol} to wallet`} text={`Add ${ddo?.dataTokenInfo.symbol} to wallet`}

View File

@ -19,26 +19,19 @@ const SampleButton = ({ url }: { url: string }) => (
) )
export default function MetaSecondary(): ReactElement { export default function MetaSecondary(): ReactElement {
const { metadata } = useAsset() const { ddo } = useAsset()
return ( return (
<aside className={styles.metaSecondary}> <aside className={styles.metaSecondary}>
{metadata?.additionalInformation?.links?.length > 0 && ( {ddo?.metadata.links?.length > 0 && (
<div className={styles.samples}> <div className={styles.samples}>
<MetaItem <MetaItem
title="Sample Data" title="Sample Data"
content={ content={<SampleButton url={ddo?.metadata.links[0]} />}
<SampleButton
url={metadata?.additionalInformation?.links[0].url}
/>
}
/> />
</div> </div>
)} )}
{ddo?.metadata?.tags?.length > 0 && <Tags items={ddo?.metadata?.tags} />}
{metadata?.additionalInformation?.tags?.length > 0 && (
<Tags items={metadata?.additionalInformation?.tags} />
)}
</aside> </aside>
) )
} }

View File

@ -17,31 +17,27 @@ import { useWeb3 } from '@context/Web3'
import styles from './index.module.css' import styles from './index.module.css'
import NetworkName from '@shared/NetworkName' import NetworkName from '@shared/NetworkName'
import content from '../../../../content/purgatory.json' import content from '../../../../content/purgatory.json'
import { DDO } from '@oceanprotocol/lib'
export default function AssetContent({ ddo }: { ddo: DDO }): ReactElement { export default function AssetContent({ ddo }: { ddo: Asset }): ReactElement {
const { debug } = useUserPreferences() const { debug } = useUserPreferences()
const { accountId } = useWeb3() const { accountId } = useWeb3()
const { const { price, owner, isInPurgatory, purgatoryData, isAssetNetwork } =
price, useAsset()
metadata,
type,
owner,
isInPurgatory,
purgatoryData,
isAssetNetwork
} = useAsset()
const [showEdit, setShowEdit] = useState<boolean>() const [showEdit, setShowEdit] = useState<boolean>()
const [isComputeType, setIsComputeType] = useState<boolean>(false) const [isComputeType, setIsComputeType] = useState<boolean>(false)
const [showEditCompute, setShowEditCompute] = useState<boolean>() const [showEditCompute, setShowEditCompute] = useState<boolean>()
const [isOwner, setIsOwner] = useState(false) const [isOwner, setIsOwner] = useState(false)
const serviceCompute = ddo.services.filter(
(service) => service.type === 'compute'
)[0]
useEffect(() => { useEffect(() => {
if (!accountId || !owner) return if (!accountId || !owner) return
const isOwner = accountId.toLowerCase() === owner.toLowerCase() const isOwner = accountId.toLowerCase() === owner.toLowerCase()
setIsOwner(isOwner) setIsOwner(isOwner)
setIsComputeType(Boolean(ddo.findServiceByType('compute'))) setIsComputeType(Boolean(serviceCompute))
}, [accountId, price, owner, ddo]) }, [accountId, price, owner, ddo])
function handleEditButton() { function handleEditButton() {
@ -79,7 +75,7 @@ export default function AssetContent({ ddo }: { ddo: DDO }): ReactElement {
<> <>
<Markdown <Markdown
className={styles.description} className={styles.description}
text={metadata?.additionalInformation?.description || ''} text={ddo?.metadata.description || ''}
/> />
<MetaSecondary /> <MetaSecondary />
@ -93,7 +89,7 @@ export default function AssetContent({ ddo }: { ddo: DDO }): ReactElement {
> >
Edit Metadata Edit Metadata
</Button> </Button>
{ddo.findServiceByType('compute') && type === 'dataset' && ( {serviceCompute && ddo?.metadata.type === 'dataset' && (
<> <>
<span className={styles.separator}>|</span> <span className={styles.separator}>|</span>
<Button <Button

View File

@ -15,8 +15,8 @@ const columns = [
{ {
name: 'Data Set', name: 'Data Set',
selector: function getAssetRow(row: AssetListPrices) { selector: function getAssetRow(row: AssetListPrices) {
const { attributes } = row.ddo.findServiceByType('metadata') const { metadata } = row.ddo
return <AssetTitle title={attributes.main.name} ddo={row.ddo} /> return <AssetTitle title={metadata.name} ddo={row.ddo} />
}, },
maxWidth: '45rem', maxWidth: '45rem',
grow: 1 grow: 1

View File

@ -8,7 +8,7 @@ import {
queryMetadata queryMetadata
} from '@utils/aquarius' } from '@utils/aquarius'
import { getHighestLiquidityDatatokens } from '@utils/subgraph' import { getHighestLiquidityDatatokens } from '@utils/subgraph'
import { DDO, Logger } from '@oceanprotocol/lib' import { Logger } from '@oceanprotocol/lib'
import { useUserPreferences } from '@context/UserPreferences' import { useUserPreferences } from '@context/UserPreferences'
import styles from './index.module.css' import styles from './index.module.css'
import { useIsMounted } from '@hooks/useIsMounted' import { useIsMounted } from '@hooks/useIsMounted'
@ -31,11 +31,11 @@ async function getQueryHighest(
return [queryHighest, dtList] return [queryHighest, dtList]
} }
function sortElements(items: DDO[], sorted: string[]) { function sortElements(items: Asset[], sorted: string[]) {
items.sort(function (a, b) { items.sort(function (a, b) {
return ( return (
sorted.indexOf(a.dataToken.toLowerCase()) - sorted.indexOf(a.services[0].datatokenAddress.toLowerCase()) -
sorted.indexOf(b.dataToken.toLowerCase()) sorted.indexOf(b.services[0].datatokenAddress.toLowerCase())
) )
}) })
return items return items

View File

@ -48,9 +48,7 @@ function DetailsAssets({ job }: { job: ComputeJobMetaData }) {
async function getAlgoMetadata() { async function getAlgoMetadata() {
const ddo = await retrieveDDO(job.algoDID, newCancelToken()) const ddo = await retrieveDDO(job.algoDID, newCancelToken())
setAlgoDtSymbol(ddo.dataTokenInfo.symbol) setAlgoDtSymbol(ddo.dataTokenInfo.symbol)
setAlgoName(ddo?.metadata.name)
const { attributes } = ddo.findServiceByType('metadata')
setAlgoName(attributes?.main.name)
} }
getAlgoMetadata() getAlgoMetadata()
}, [appConfig.metadataCacheUri, job.algoDID]) }, [appConfig.metadataCacheUri, job.algoDID])

View File

@ -16,7 +16,6 @@ import { CancelToken } from 'axios'
import { isValidNumber } from '@utils/numbers' import { isValidNumber } from '@utils/numbers'
import Decimal from 'decimal.js' import Decimal from 'decimal.js'
import { useProfile } from '@context/Profile' import { useProfile } from '@context/Profile'
import { DDO } from '@oceanprotocol/lib'
import { useCancelToken } from '@hooks/useCancelToken' import { useCancelToken } from '@hooks/useCancelToken'
import { useIsMounted } from '@hooks/useIsMounted' import { useIsMounted } from '@hooks/useIsMounted'
import { useUserPreferences } from '@context/UserPreferences' import { useUserPreferences } from '@context/UserPreferences'
@ -25,12 +24,12 @@ Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
const REFETCH_INTERVAL = 20000 const REFETCH_INTERVAL = 20000
interface Asset { interface AssetPoolShare {
userLiquidity: number userLiquidity: number
poolShare: PoolShare poolShare: PoolShare
networkId: number networkId: number
createTime: number createTime: number
ddo: DDO ddo: Asset
} }
function findTokenByType(tokens: PoolSharePoolIdTokens[], type: string) { function findTokenByType(tokens: PoolSharePoolIdTokens[], type: string) {
@ -46,7 +45,7 @@ function Symbol({ tokens }: { tokens: PoolSharePoolIdTokens[] }) {
return <>{findTokenByType(tokens, 'datatoken')}</> return <>{findTokenByType(tokens, 'datatoken')}</>
} }
function Liquidity({ row, type }: { row: Asset; type: string }) { function Liquidity({ row, type }: { row: AssetPoolShare; type: string }) {
let price = `` let price = ``
let oceanTokenBalance = '' let oceanTokenBalance = ''
let dataTokenBalance = '' let dataTokenBalance = ''
@ -98,33 +97,33 @@ function Liquidity({ row, type }: { row: Asset; type: string }) {
const columns = [ const columns = [
{ {
name: 'Data Set', name: 'Data Set',
selector: function getAssetRow(row: Asset) { selector: function getAssetRow(row: AssetPoolShare) {
return <AssetTitle ddo={row.ddo} /> return <AssetTitle ddo={row.ddo} />
}, },
grow: 2 grow: 2
}, },
{ {
name: 'Network', name: 'Network',
selector: function getNetwork(row: Asset) { selector: function getNetwork(row: AssetPoolShare) {
return <NetworkName networkId={row.networkId} /> return <NetworkName networkId={row.networkId} />
} }
}, },
{ {
name: 'Datatoken', name: 'Datatoken',
selector: function getSymbol(row: Asset) { selector: function getSymbol(row: AssetPoolShare) {
return <Symbol tokens={row.poolShare.poolId.tokens} /> return <Symbol tokens={row.poolShare.poolId.tokens} />
} }
}, },
{ {
name: 'Liquidity', name: 'Liquidity',
selector: function getAssetRow(row: Asset) { selector: function getAssetRow(row: AssetPoolShare) {
return <Liquidity row={row} type="user" /> return <Liquidity row={row} type="user" />
}, },
right: true right: true
}, },
{ {
name: 'Pool Liquidity', name: 'Pool Liquidity',
selector: function getAssetRow(row: Asset) { selector: function getAssetRow(row: AssetPoolShare) {
return <Liquidity row={row} type="pool" /> return <Liquidity row={row} type="pool" />
}, },
right: true right: true
@ -138,7 +137,7 @@ async function getPoolSharesAssets(
) { ) {
if (data.length < 1) return if (data.length < 1) return
const assetList: Asset[] = [] const assetList: AssetPoolShare[] = []
const didList: string[] = [] const didList: string[] = []
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
@ -169,7 +168,7 @@ export default function PoolShares({
accountId: string accountId: string
}): ReactElement { }): ReactElement {
const { poolShares, isPoolSharesLoading } = useProfile() const { poolShares, isPoolSharesLoading } = useProfile()
const [assets, setAssets] = useState<Asset[]>() const [assets, setAssets] = useState<AssetPoolShare[]>()
const [loading, setLoading] = useState<boolean>(false) const [loading, setLoading] = useState<boolean>(false)
const [dataFetchInterval, setDataFetchInterval] = useState<NodeJS.Timeout>() const [dataFetchInterval, setDataFetchInterval] = useState<NodeJS.Timeout>()
const { chainIds } = useUserPreferences() const { chainIds } = useUserPreferences()

View File

@ -1,5 +1,4 @@
import React, { FormEvent, ReactElement, useState } from 'react' import React, { FormEvent, ReactElement, useState } from 'react'
import { File as FileMetadata } from '@oceanprotocol/lib/dist/node/ddo/interfaces/File'
import Markdown from '@shared/Markdown' import Markdown from '@shared/Markdown'
import Tags from '@shared/atoms/Tags' import Tags from '@shared/atoms/Tags'
import MetaItem from '../../Asset/AssetContent/MetaItem' import MetaItem from '../../Asset/AssetContent/MetaItem'

View File

@ -1,6 +1,5 @@
import React, { ReactElement, useEffect } from 'react' import React, { ReactElement, useEffect } from 'react'
import { useFormikContext } from 'formik' import { useFormikContext } from 'formik'
import { DDO } from '@oceanprotocol/lib'
import { useSiteMetadata } from '@hooks/useSiteMetadata' import { useSiteMetadata } from '@hooks/useSiteMetadata'
import Tabs from '@shared/atoms/Tabs' import Tabs from '@shared/atoms/Tabs'
import { isValidNumber } from '@utils/numbers' import { isValidNumber } from '@utils/numbers'

View File

@ -37,9 +37,9 @@ export default function ServicesFields(): ReactElement {
name="services[0].dataTokenOptions" name="services[0].dataTokenOptions"
/> />
<Field <Field
{...getFieldContent('providerUri', content.services.fields)} {...getFieldContent('providerUrl', content.services.fields)}
component={Input} component={Input}
name="services[0].providerUri" name="services[0].providerUrl"
/> />
<Field <Field
{...getFieldContent('files', content.services.fields)} {...getFieldContent('files', content.services.fields)}

View File

@ -1,5 +1,4 @@
import React from 'react' import React from 'react'
import { File as FileMetadata } from '@oceanprotocol/lib'
import * as Yup from 'yup' import * as Yup from 'yup'
import { allowDynamicPricing, allowFixedPricing } from '../../../app.config.js' import { allowDynamicPricing, allowFixedPricing } from '../../../app.config.js'
import { FormPublishData, StepContent } from './_types' import { FormPublishData, StepContent } from './_types'
@ -34,6 +33,7 @@ export const wizardSteps: StepContent[] = [
export const initialValues: Partial<FormPublishData> = { export const initialValues: Partial<FormPublishData> = {
step: 1, step: 1,
chainId: 1,
metadata: { metadata: {
type: 'dataset', type: 'dataset',
name: '', name: '',
@ -49,7 +49,7 @@ export const initialValues: Partial<FormPublishData> = {
dataTokenOptions: { name: '', symbol: '' }, dataTokenOptions: { name: '', symbol: '' },
timeout: 'Forever', timeout: 'Forever',
access: '', access: '',
providerUri: '' providerUrl: ''
} }
], ],
pricing: { pricing: {
@ -96,7 +96,7 @@ const validationService = {
access: Yup.string() access: Yup.string()
.matches(/Compute|Download/g, { excludeEmptyString: true }) .matches(/Compute|Download/g, { excludeEmptyString: true })
.required('Required'), .required('Required'),
providerUri: Yup.string().url().nullable() providerUrl: Yup.string().url().nullable()
} }
const validationPricing = { const validationPricing = {
@ -124,6 +124,7 @@ const validationPricing = {
// export const validationSchema: Yup.SchemaOf<FormPublishData> = // export const validationSchema: Yup.SchemaOf<FormPublishData> =
export const validationSchema: Yup.SchemaOf<any> = Yup.object().shape({ export const validationSchema: Yup.SchemaOf<any> = Yup.object().shape({
step: Yup.number(), step: Yup.number(),
chainId: Yup.number(),
metadata: Yup.object().shape(validationMetadata), metadata: Yup.object().shape(validationMetadata),
services: Yup.array().of(Yup.object().shape(validationService)), services: Yup.array().of(Yup.object().shape(validationService)),
pricing: Yup.object().shape(validationPricing) pricing: Yup.object().shape(validationPricing)

View File

@ -1,23 +1,22 @@
import { DataTokenOptions } from '@hooks/usePublish' import { DataTokenOptions } from '@hooks/usePublish'
import { EditableMetadataLinks, File } from '@oceanprotocol/lib'
import { ReactElement } from 'react' import { ReactElement } from 'react'
export interface FormPublishService { export interface FormPublishService {
files: string | File[] files: string | FileMetadata[]
links?: string | EditableMetadataLinks[] links?: string[]
timeout: string timeout: string
dataTokenOptions: DataTokenOptions dataTokenOptions: DataTokenOptions
access: 'Download' | 'Compute' | string access: 'Download' | 'Compute' | string
image?: string image?: string
containerTag?: string containerTag?: string
entrypoint?: string entrypoint?: string
providerUri?: string providerUrl?: string
} }
export interface FormPublishData { export interface FormPublishData {
step: number step: number
metadata: { metadata: {
type: 'dataset' | 'algorithm' | string type: 'dataset' | 'algorithm'
name: string name: string
description: string description: string
author: string author: string
@ -26,6 +25,7 @@ export interface FormPublishData {
} }
services: FormPublishService[] services: FormPublishService[]
pricing: PriceOptions pricing: PriceOptions
chainId: number
} }
export interface StepContent { export interface StepContent {

View File

@ -6,6 +6,10 @@ import {
} from '@utils/ddo' } from '@utils/ddo'
import { FormPublishData } from './_types' import { FormPublishData } from './_types'
function encryptMe(files: string | FileMetadata[]): string {
throw new Error('Function not implemented.')
}
export function getFieldContent( export function getFieldContent(
fieldName: string, fieldName: string,
fields: FormFieldContent[] fields: FormFieldContent[]
@ -13,41 +17,55 @@ export function getFieldContent(
return fields.filter((field: FormFieldContent) => field.name === fieldName)[0] return fields.filter((field: FormFieldContent) => field.name === fieldName)[0]
} }
export function transformPublishFormToDdo( export function transformPublishFormToDdo(data: Partial<FormPublishData>): DDO {
data: Partial<FormPublishData>,
ddo?: DdoMarket
): DdoMarket {
const currentTime = dateToStringNoMS(new Date()) const currentTime = dateToStringNoMS(new Date())
const { type } = data const { type } = data.metadata
const { name, description, tags, author, termsAndConditions } = data.metadata const { name, description, tags, author, termsAndConditions } = data.metadata
const { files, links, image, containerTag, entrypoint, providerUri } = const {
data.services[0] access,
files,
const fileUrl = typeof files !== 'string' && files[0].url links,
const algorithmLanguage = getAlgorithmFileExtension(fileUrl)
const algorithm = getAlgorithmComponent(
image, image,
containerTag, containerTag,
entrypoint, entrypoint,
algorithmLanguage providerUrl,
) timeout
} = data.services[0]
const service = { const fileUrl = typeof files !== 'string' && files[0].url
files: typeof files !== 'string' && files,
links: typeof links !== 'string' ? links : [], const filesEncrypted = encryptMe(files)
...(type === 'algorithm' && { ...algorithm })
const service: Service = {
type: access,
files: filesEncrypted,
datatokenAddress: '',
serviceEndpoint: providerUrl,
timeout
} }
const newDdo: DdoMarket = { const newDdo: DDO = {
'@context': [''],
id: '',
version: '4.0.0',
created: currentTime,
chainId: data.chainId,
metadata: { metadata: {
type,
name, name,
description, description,
tags: transformTags(tags), tags: transformTags(tags),
author, author,
dateCreated: ddo ? ddo.metadata.dateCreated : currentTime, license: 'https://market.oceanprotocol.com/terms',
datePublished: '', links,
termsAndConditions, ...(type === 'algorithm' && {
license: 'https://market.oceanprotocol.com/terms' ...getAlgorithmComponent(
image,
containerTag,
entrypoint,
getAlgorithmFileExtension(fileUrl)
)
})
}, },
services: [service] services: [service]
} }

View File

@ -30,7 +30,7 @@ export default function PublishPage({
}: { }: {
content: { title: string; description: string; warning: string } content: { title: string; description: string; warning: string }
}): ReactElement { }): ReactElement {
const { accountId } = useWeb3() const { accountId, chainId } = useWeb3()
const { isInPurgatory, purgatoryData } = useAccountPurgatory(accountId) const { isInPurgatory, purgatoryData } = useAccountPurgatory(accountId)
const { publish, publishError, isLoading, publishStepText } = usePublish() const { publish, publishError, isLoading, publishStepText } = usePublish()
const [success, setSuccess] = useState<string>() const [success, setSuccess] = useState<string>()
@ -101,7 +101,9 @@ export default function PublishPage({
// await handleSubmit(values, resetForm) // await handleSubmit(values, resetForm)
}} }}
> >
{({ values }) => { {({ values, setFieldValue }) => {
setFieldValue('chainId', chainId)
return ( return (
<> <>
<Form className={styles.form} ref={scrollToRef}> <Form className={styles.form} ref={scrollToRef}>