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

Merge branch 'v4' into feature/publish

This commit is contained in:
Matthias Kretschmann 2022-01-11 19:49:11 +00:00
commit 38ce25225f
Signed by: m
GPG Key ID: 606EEEF3C479A91F
34 changed files with 71 additions and 81 deletions

View File

@ -7,7 +7,7 @@ import React, {
useCallback,
ReactNode
} from 'react'
import { LoggerInstance, Purgatory } from '@oceanprotocol/lib'
import { Asset, LoggerInstance, Purgatory } from '@oceanprotocol/lib'
import getAssetPurgatoryData from '@utils/purgatory'
import { CancelToken } from 'axios'
import { retrieveDDO } from '@utils/aquarius'
@ -110,7 +110,7 @@ function AssetProvider({
setDID(asset as string)
setTitle(ddo.metadata.name)
setOwner(ddo.nft.owner)
setIsInPurgatory(ddo.isInPurgatory === 'true')
setIsInPurgatory(ddo.purgatory.state === true)
await setPurgatory(ddo.id)
}
init()

View File

@ -14,7 +14,7 @@ import {
} from '@utils/subgraph'
import { useUserPreferences } from './UserPreferences'
import { PoolShares_poolShares as PoolShare } from '../@types/apollo/PoolShares'
import { LoggerInstance } from '@oceanprotocol/lib'
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import { getDownloadAssets, getPublishedAssets } from '@utils/aquarius'
import { useSiteMetadata } from '@hooks/useSiteMetadata'
import { accountTruncate } from '@utils/web3'

View File

@ -1,4 +1,4 @@
import { LoggerInstance } from '@oceanprotocol/lib'
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import { useState } from 'react'
import { TransactionReceipt } from 'web3-core'
import { Decimal } from 'decimal.js'
@ -43,8 +43,8 @@ function usePricing(): UsePricing {
async function getDTSymbol(ddo: Asset): Promise<string> {
if (!accountId) return
const { dataTokenInfo } = ddo
return dataTokenInfo.symbol
const { datatokens } = ddo
return datatokens[0].symbol
// return dataTokenInfo
// ? dataTokenInfo.symbol
// : await ocean?.datatokens.getSymbol(dataTokenInfo.address)
@ -52,8 +52,8 @@ function usePricing(): UsePricing {
async function getDTName(ddo: Asset): Promise<string> {
if (!accountId) return
const { dataTokenInfo } = ddo
return dataTokenInfo.name
const { datatokens } = ddo
return datatokens[0].name
// return dataTokenInfo
// ? dataTokenInfo.name
// : await ocean?.datatokens.getName(dataTokenInfo.address)
@ -96,8 +96,8 @@ function usePricing(): UsePricing {
tokensToMint: string,
ddo: Asset
): Promise<TransactionReceipt | void> {
const { dataTokenInfo } = ddo
LoggerInstance.log('mint function', dataTokenInfo.address, accountId)
const { datatokens } = ddo
LoggerInstance.log('mint function', datatokens[0].address, accountId)
// const balance = new Decimal(
// await ocean.datatokens.balance(dataTokenInfo.address, accountId)
// )

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

@ -1,33 +0,0 @@
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
}

View File

@ -1,12 +0,0 @@
interface MetadataAlgorithmContainer {
entrypoint: string
image: string
tag: string
checksum: string
}
interface MetadataAlgorithm {
language?: string
version?: string
container: MetadataAlgorithmContainer
}

View File

@ -1,4 +1,8 @@
import { LoggerInstance } from '@oceanprotocol/lib'
import {
Asset,
LoggerInstance,
PublisherTrustedAlgorithm
} from '@oceanprotocol/lib'
import { AssetSelectionAsset } from '@shared/FormFields/AssetSelection'
import { PriceList, getAssetsPriceList } from './subgraph'
import axios, { CancelToken, AxiosResponse } from 'axios'
@ -208,7 +212,7 @@ export async function transformDDOToAssetSelection(
const didProviderEndpointMap: any = {}
for (const ddo of ddoList) {
didList.push(ddo.id)
symbolList[ddo.id] = ddo.dataTokenInfo.symbol
symbolList[ddo.id] = ddo.datatokens[0].symbol
const algoComputeService = getServiceByName(ddo, 'compute')
algoComputeService?.serviceEndpoint &&
(didProviderEndpointMap[ddo.id] = algoComputeService?.serviceEndpoint)

View File

@ -9,6 +9,7 @@
// Account
// } from '@oceanprotocol/lib'
// import { ComputeJob } from '@oceanprotocol/lib/dist/node/ocean/interfaces/Compute'
import { Asset } from '@oceanprotocol/lib'
import { CancelToken } from 'axios'
import { gql } from 'urql'
import { queryMetadata, getFilterTerm, generateBaseQuery } from './aquarius'

View File

@ -1,3 +1,5 @@
import { Asset, DDO, Service } from '@oceanprotocol/lib'
export function getServiceByName(
ddo: Asset | DDO,
name: 'access' | 'compute'

View File

@ -1,5 +1,5 @@
import { gql, OperationResult, TypedDocumentNode, OperationContext } from 'urql'
import { LoggerInstance } from '@oceanprotocol/lib'
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import { getUrqlClientInstance } from '@context/UrqlProvider'
import { getOceanConfig } from './ocean'
import {

View File

@ -4,6 +4,7 @@ import { getAssetsNames } from '@utils/aquarius'
import styles from './AssetListTitle.module.css'
import axios from 'axios'
import { useSiteMetadata } from '@hooks/useSiteMetadata'
import { Asset } from '@oceanprotocol/lib'
export default function AssetListTitle({
ddo,

View File

@ -7,6 +7,7 @@ import { getAssetsBestPrices, AssetListPrices } from '@utils/subgraph'
import Loader from '@shared/atoms/Loader'
import { useUserPreferences } from '@context/UserPreferences'
import { useIsMounted } from '@hooks/useIsMounted'
import { Asset } from '@oceanprotocol/lib'
const cx = classNames.bind(styles)

View File

@ -8,6 +8,7 @@ import AssetType from '@shared/AssetType'
import NetworkName from '@shared/NetworkName'
import styles from './AssetTeaser.module.css'
import { getServiceByName } from '@utils/ddo'
import { Asset } from '@oceanprotocol/lib'
declare type AssetTeaserProps = {
ddo: Asset
@ -21,7 +22,7 @@ export default function AssetTeaser({
noPublisher
}: AssetTeaserProps): ReactElement {
const { name, type, description } = ddo.metadata
const { dataTokenInfo } = ddo
const { datatokens } = ddo
const isCompute = Boolean(getServiceByName(ddo, 'compute'))
const accessType = isCompute ? 'compute' : 'access'
const { owner } = ddo.nft
@ -31,7 +32,7 @@ export default function AssetTeaser({
<Link href={`/asset/${ddo.id}`}>
<a className={styles.link}>
<header className={styles.header}>
<div className={styles.symbol}>{dataTokenInfo?.symbol}</div>
<div className={styles.symbol}>{datatokens[0]?.symbol}</div>
<Dotdotdot clamp={3}>
<h1 className={styles.title}>{name}</h1>
</Dotdotdot>

View File

@ -13,7 +13,7 @@ import { retrieveDDOListByDIDs } from '@utils/aquarius'
import { CancelToken } from 'axios'
import Title from './Title'
import styles from './index.module.css'
import { LoggerInstance } from '@oceanprotocol/lib'
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import { useCancelToken } from '@hooks/useCancelToken'
const REFETCH_INTERVAL = 20000

View File

@ -5,6 +5,7 @@ import { AssetSelectionAsset } from '@shared/FormFields/AssetSelection'
import AssetComputeList from '@shared/AssetList/AssetComputeList'
import { useCancelToken } from '@hooks/useCancelToken'
import { getServiceByName } from '@utils/ddo'
import { Asset } from '@oceanprotocol/lib'
export default function AlgorithmDatasetsListForCompute({
ddo,

View File

@ -10,6 +10,7 @@ import { useAsset } from '@context/Asset'
import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3'
import content from '../../../../../content/pages/startComputeDataset.json'
import { Asset } from '@oceanprotocol/lib'
export default function FormStartCompute({
algorithms,
@ -159,7 +160,7 @@ export default function FormStartCompute({
}
hasPreviousOrder={hasPreviousOrder}
hasDatatoken={hasDatatoken}
dtSymbol={ddo?.dataTokenInfo?.symbol}
dtSymbol={ddo?.datatokens[0]?.symbol}
dtBalance={dtBalance}
datasetLowPoolLiquidity={datasetLowPoolLiquidity}
assetTimeout={assetTimeout}

View File

@ -2,14 +2,16 @@ import React, { useState, ReactElement, useEffect, useCallback } from 'react'
import {
LoggerInstance,
ComputeAlgorithm,
ComputeOutput
ComputeOutput,
Asset,
DDO,
PublisherTrustedAlgorithm
} from '@oceanprotocol/lib'
import { toast } from 'react-toastify'
import Price from '@shared/Price'
import FileIcon from '@shared/FileIcon'
import Alert from '@shared/atoms/Alert'
import { useSiteMetadata } from '@hooks/useSiteMetadata'
import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3'
import { usePricing } from '@hooks/usePricing'
import { useAsset } from '@context/Asset'
@ -427,7 +429,7 @@ export default function Compute({
hasDatatokenSelectedComputeAsset={hasAlgoAssetDatatoken}
oceanSymbol={price ? price.oceanSymbol : ''}
dtSymbolSelectedComputeAsset={
selectedAlgorithmAsset?.dataTokenInfo?.symbol
selectedAlgorithmAsset?.datatokens[0]?.symbol
}
dtBalanceSelectedComputeAsset={algorithmDTBalance}
selectedComputeAssetLowPoolLiquidity={!isAlgoConsumablePrice}

View File

@ -17,6 +17,7 @@ import AlgorithmDatasetsListForCompute from './Compute/AlgorithmDatasetsListForC
import styles from './Consume.module.css'
import { useIsMounted } from '@hooks/useIsMounted'
import { FileMetadata } from '@utils/provider'
import { Asset } from '@oceanprotocol/lib'
const previousOrderQuery = gql`
query PreviousOrder($id: String!, $account: String!) {
@ -177,7 +178,7 @@ export default function Consume({
disabled={isDisabled}
hasPreviousOrder={hasPreviousOrder}
hasDatatoken={hasDatatoken}
dtSymbol={ddo?.dataTokenInfo?.symbol}
dtSymbol={ddo?.datatokens[0]?.symbol}
dtBalance={dtBalance}
datasetLowPoolLiquidity={!isConsumablePrice}
onClick={handleConsume}

View File

@ -1,5 +1,5 @@
import React, { ReactElement, useState } from 'react'
import { LoggerInstance } from '@oceanprotocol/lib'
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import * as Yup from 'yup'
import { Formik } from 'formik'
import Actions from '../Pool/Actions'

View File

@ -11,6 +11,7 @@ import PriceImpact from './PriceImpact'
import Decimal from 'decimal.js'
import { useAsset } from '@context/Asset'
import { FormTradeData, TradeItem } from './_types'
import { Asset } from '@oceanprotocol/lib'
Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })
@ -41,7 +42,7 @@ export default function Swap({
})
const [dtItem, setDtItem] = useState<TradeItem>({
amount: '0',
token: ddo.dataTokenInfo.symbol,
token: ddo.datatokens[0].symbol,
maxAmount: '0'
})
@ -126,7 +127,7 @@ export default function Swap({
const switchTokens = () => {
setFieldValue('type', values.type === 'buy' ? 'sell' : 'buy')
setCoin(values.type === 'sell' ? 'OCEAN' : ddo.dataTokenInfo.symbol)
setCoin(values.type === 'sell' ? 'OCEAN' : ddo.datatokens[0].symbol)
// don't reset form because we don't want to reset type
setFieldValue('datatoken', 0)
setFieldValue('ocean', 0)

View File

@ -1,13 +1,12 @@
import React, { ReactElement, useState, useEffect } from 'react'
import Compute from './Compute'
import Consume from './Consume'
import { LoggerInstance } from '@oceanprotocol/lib'
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import Tabs, { TabsItem } from '@shared/atoms/Tabs'
import { compareAsBN } from '@utils/numbers'
import Pool from './Pool'
import Trade from './Trade'
import { useAsset } from '@context/Asset'
import { useOcean } from '@context/Ocean'
import { useWeb3 } from '@context/Web3'
import Web3Feedback from '@shared/Web3Feedback'
import { FileMetadata, getFileInfo } from '@utils/provider'

View File

@ -3,6 +3,7 @@ import MetaItem from './MetaItem'
import styles from './MetaFull.module.css'
import Publisher from '@shared/Publisher'
import { useAsset } from '@context/Asset'
import { Asset } from '@oceanprotocol/lib'
export default function MetaFull({ ddo }: { ddo: Asset }): ReactElement {
const { isInPurgatory } = useAsset()

View File

@ -8,6 +8,7 @@ import Time from '@shared/atoms/Time'
import AssetType from '@shared/AssetType'
import styles from './MetaMain.module.css'
import { getServiceByName } from '@utils/ddo'
import { Asset } from '@oceanprotocol/lib'
export default function MetaMain({ ddo }: { ddo: Asset }): ReactElement {
const { isAssetNetwork } = useAsset()
@ -18,8 +19,8 @@ export default function MetaMain({ ddo }: { ddo: Asset }): ReactElement {
const blockscoutNetworks = [1287, 2021000, 2021001, 44787, 246, 1285]
const isBlockscoutExplorer = blockscoutNetworks.includes(ddo?.chainId)
const dataTokenName = ddo?.dataTokenInfo?.name
const dataTokenSymbol = ddo?.dataTokenInfo?.symbol
const dataTokenName = ddo?.datatokens[0]?.name
const dataTokenSymbol = ddo?.datatokens[0]?.symbol
return (
<aside className={styles.meta}>
@ -45,9 +46,9 @@ export default function MetaMain({ ddo }: { ddo: Asset }): ReactElement {
<span className={styles.addWrap}>
<AddToken
address={ddo?.services[0].datatokenAddress}
symbol={(ddo as Asset)?.dataTokenInfo?.symbol}
symbol={(ddo as Asset)?.datatokens[0]?.symbol}
logo="https://raw.githubusercontent.com/oceanprotocol/art/main/logo/datatoken.png"
text={`Add ${(ddo as Asset)?.dataTokenInfo?.symbol} to wallet`}
text={`Add ${(ddo as Asset)?.datatokens[0]?.symbol} to wallet`}
className={styles.add}
minimal
/>

View File

@ -3,6 +3,7 @@ import MetaItem from './MetaItem'
import styles from './MetaSecondary.module.css'
import Tags from '@shared/atoms/Tags'
import Button from '@shared/atoms/Button'
import { Asset } from '@oceanprotocol/lib'
const SampleButton = ({ url }: { url: string }) => (
<Button

View File

@ -13,6 +13,7 @@ import EditHistory from './EditHistory'
import styles from './index.module.css'
import NetworkName from '@shared/NetworkName'
import content from '../../../../content/purgatory.json'
import { Asset } from '@oceanprotocol/lib'
export default function AssetContent({
ddo,

View File

@ -1,4 +1,4 @@
import { ServiceComputeOptions } from '@oceanprotocol/lib'
import { Asset, ServiceComputeOptions } from '@oceanprotocol/lib'
import React, { ReactElement, useEffect, useState } from 'react'
// import { transformComputeFormToServiceComputePrivacy } from '@utils/compute'
import DebugOutput from '@shared/DebugOutput'

View File

@ -1,3 +1,4 @@
import { Metadata } from '@oceanprotocol/lib'
import { mapTimeoutStringToSeconds, secondsToString } from '@utils/ddo'
// import { EditableMetadataLinks } from '@oceanprotocol/lib'
import * as Yup from 'yup'

View File

@ -25,8 +25,8 @@ const columns = [
name: 'Datatoken Symbol',
selector: function getAssetRow(row: AssetListPrices) {
return (
<Tooltip content={row.ddo.dataTokenInfo.name}>
{row.ddo.dataTokenInfo.symbol}
<Tooltip content={row.ddo.datatokens[0].name}>
{row.ddo.datatokens[0].symbol}
</Tooltip>
)
},

View File

@ -8,7 +8,7 @@ import {
queryMetadata
} from '@utils/aquarius'
import { getHighestLiquidityDatatokens } from '@utils/subgraph'
import { LoggerInstance } from '@oceanprotocol/lib'
import { Asset, LoggerInstance } from '@oceanprotocol/lib'
import { useUserPreferences } from '@context/UserPreferences'
import styles from './index.module.css'
import { useIsMounted } from '@hooks/useIsMounted'

View File

@ -47,7 +47,7 @@ function DetailsAssets({ job }: { job: ComputeJobMetaData }) {
useEffect(() => {
async function getAlgoMetadata() {
const ddo = await retrieveDDO(job.algoDID, newCancelToken())
setAlgoDtSymbol(ddo.dataTokenInfo.symbol)
setAlgoDtSymbol(ddo.datatokens[0].symbol)
setAlgoName(ddo?.metadata.name)
}
getAlgoMetadata()

View File

@ -19,6 +19,7 @@ import { useProfile } from '@context/Profile'
import { useCancelToken } from '@hooks/useCancelToken'
import { useIsMounted } from '@hooks/useIsMounted'
import { useUserPreferences } from '@context/UserPreferences'
import { Asset } from '@oceanprotocol/lib'
Decimal.set({ toExpNeg: -18, precision: 18, rounding: 1 })

View File

@ -4,6 +4,7 @@ import { FormPublishData } from '../_types'
import { useFormikContext } from 'formik'
import { transformPublishFormToDdo } from '../_utils'
import styles from './index.module.css'
import { DDO } from '@oceanprotocol/lib'
export default function Debug(): ReactElement {
const { values } = useFormikContext<FormPublishData>()

View File

@ -4,6 +4,7 @@ import { FormPublishData } from '../_types'
import { useFormikContext } from 'formik'
import AssetContent from 'src/components/Asset/AssetContent'
import { transformPublishFormToDdo } from '../_utils'
import { Asset } from '@oceanprotocol/lib'
export default function Preview(): ReactElement {
const [ddo, setDdo] = useState<Asset>()

View File

@ -7,6 +7,7 @@ import MetadataFields from './Metadata'
import ServicesFields from './Services'
import Preview from './Preview'
import Submission from './Submission'
import { ServiceComputeOptions } from '@oceanprotocol/lib'
export const wizardSteps: StepContent[] = [
{
@ -98,6 +99,13 @@ export const initialValues: FormPublishData = {
}
}
export interface MetadataAlgorithmContainer {
entrypoint: string
image: string
tag: string
checksum: string
}
export const algorithmContainerPresets: MetadataAlgorithmContainer[] = [
{
image: 'node',

View File

@ -8,7 +8,10 @@ import {
import { mapTimeoutStringToSeconds } from '@utils/ddo'
import { getEncryptedFiles } from '@utils/provider'
import slugify from 'slugify'
import { algorithmContainerPresets } from './_constants'
import {
algorithmContainerPresets,
MetadataAlgorithmContainer
} from './_constants'
import { FormPublishData } from './_types'
export function getFieldContent(
@ -148,6 +151,7 @@ export async function transformPublishFormToDdo(
const newDdo: DDO = {
'@context': ['https://w3id.org/did/v1'],
id: did,
nftAddress,
version: '4.0.0',
chainId,
nftAddress,