From 64a25f3f3e60699e57d32f423ff02f177a03ec85 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 11 Jan 2022 19:45:14 +0000 Subject: [PATCH] use Asset from ocean.js, adapt to new structure --- src/@context/Asset.tsx | 4 +-- src/@context/Profile.tsx | 2 +- src/@hooks/usePricing.ts | 14 ++++---- src/@types/Asset.d.ts | 33 ------------------- src/@types/DDO/Credentials.d.ts | 9 ----- src/@types/DDO/Metadata.d.ts | 28 ---------------- src/@types/DDO/Services.d.ts | 29 ---------------- src/@types/DDO/index.d.ts | 10 ------ src/@utils/aquarius.ts | 8 +++-- src/@utils/compute.ts | 1 + src/@utils/ddo.ts | 2 ++ src/@utils/subgraph.ts | 2 +- .../@shared/AssetList/AssetListTitle.tsx | 1 + src/components/@shared/AssetList/index.tsx | 1 + .../@shared/AssetTeaser/AssetTeaser.tsx | 5 +-- .../@shared/PoolTransactions/index.tsx | 2 +- .../AlgorithmDatasetsListForCompute.tsx | 1 + .../Compute/FormComputeDataset.tsx | 3 +- .../Asset/AssetActions/Compute/index.tsx | 8 +++-- src/components/Asset/AssetActions/Consume.tsx | 3 +- .../Asset/AssetActions/Trade/FormTrade.tsx | 2 +- .../Asset/AssetActions/Trade/Swap.tsx | 5 +-- src/components/Asset/AssetActions/index.tsx | 3 +- .../Asset/AssetContent/MetaFull.tsx | 1 + .../Asset/AssetContent/MetaMain.tsx | 9 ++--- .../Asset/AssetContent/MetaSecondary.tsx | 1 + src/components/Asset/AssetContent/index.tsx | 1 + .../Asset/Edit/DebugEditCompute.tsx | 2 +- src/components/Asset/Edit/_constants.ts | 1 + src/components/Home/Bookmarks.tsx | 4 +-- src/components/Home/index.tsx | 2 +- .../Profile/History/ComputeJobs/Details.tsx | 2 +- src/components/Profile/History/PoolShares.tsx | 1 + src/components/Publish/Debug/index.tsx | 1 + src/components/Publish/Preview/index.tsx | 1 + src/components/Publish/_constants.tsx | 8 +++++ src/components/Publish/_types.ts | 3 +- src/components/Publish/_utils.ts | 9 ++++- 38 files changed, 76 insertions(+), 146 deletions(-) delete mode 100644 src/@types/Asset.d.ts delete mode 100644 src/@types/DDO/Credentials.d.ts delete mode 100644 src/@types/DDO/Metadata.d.ts delete mode 100644 src/@types/DDO/Services.d.ts delete mode 100644 src/@types/DDO/index.d.ts diff --git a/src/@context/Asset.tsx b/src/@context/Asset.tsx index 18f694660..bb39fff8b 100644 --- a/src/@context/Asset.tsx +++ b/src/@context/Asset.tsx @@ -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() diff --git a/src/@context/Profile.tsx b/src/@context/Profile.tsx index beaa5ae65..10ed7b6e4 100644 --- a/src/@context/Profile.tsx +++ b/src/@context/Profile.tsx @@ -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' diff --git a/src/@hooks/usePricing.ts b/src/@hooks/usePricing.ts index 1c0bee299..2cd932144 100644 --- a/src/@hooks/usePricing.ts +++ b/src/@hooks/usePricing.ts @@ -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 { 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 { 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 { - 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) // ) diff --git a/src/@types/Asset.d.ts b/src/@types/Asset.d.ts deleted file mode 100644 index 4111fc97b..000000000 --- a/src/@types/Asset.d.ts +++ /dev/null @@ -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 -} diff --git a/src/@types/DDO/Credentials.d.ts b/src/@types/DDO/Credentials.d.ts deleted file mode 100644 index bebe34a9d..000000000 --- a/src/@types/DDO/Credentials.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -interface Credential { - type: string - values: string[] -} - -interface Credentials { - allow: Credential[] - deny: Credential[] -} diff --git a/src/@types/DDO/Metadata.d.ts b/src/@types/DDO/Metadata.d.ts deleted file mode 100644 index 4ab62ec36..000000000 --- a/src/@types/DDO/Metadata.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -interface MetadataAlgorithmContainer { - entrypoint: string - image: string - tag: string - checksum: string -} - -interface MetadataAlgorithm { - language?: string - version?: string - container: MetadataAlgorithmContainer -} - -interface Metadata { - created: string - updated: string - name: string - description: string - type: 'dataset' | 'algorithm' | string - author: string - license: string - links?: string[] - tags?: string[] - copyrightHolder?: string - contentLanguage?: string - algorithm?: MetadataAlgorithm - additionalInformation?: any -} diff --git a/src/@types/DDO/Services.d.ts b/src/@types/DDO/Services.d.ts deleted file mode 100644 index 7ff1588b1..000000000 --- a/src/@types/DDO/Services.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -interface PublisherTrustedAlgorithm { - did: string - filesChecksum: string - containerSectionChecksum: string -} - -interface ServiceComputeOptions { - namespace: string - cpu?: number - gpu?: number - gpuType?: string - memory?: string - volumeSize?: string - allowRawAlgorithm: boolean - allowNetworkAccess: boolean - publisherTrustedAlgorithmPublishers: string[] - publisherTrustedAlgorithms: PublisherTrustedAlgorithm[] -} - -interface Service { - type: 'access' | 'compute' | string - files: string - datatokenAddress: string - serviceEndpoint: string - timeout: number - name?: string - description?: string - compute?: ServiceComputeOptions -} diff --git a/src/@types/DDO/index.d.ts b/src/@types/DDO/index.d.ts deleted file mode 100644 index 7069761d2..000000000 --- a/src/@types/DDO/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -// DDO spec -interface DDO { - '@context': string[] - id: string - version: string - chainId: number - metadata: Metadata - services: Service[] - credentials?: Credentials -} diff --git a/src/@utils/aquarius.ts b/src/@utils/aquarius.ts index 7e52450b6..2ed876859 100644 --- a/src/@utils/aquarius.ts +++ b/src/@utils/aquarius.ts @@ -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) diff --git a/src/@utils/compute.ts b/src/@utils/compute.ts index d0d918b6b..7cfd9ef27 100644 --- a/src/@utils/compute.ts +++ b/src/@utils/compute.ts @@ -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' diff --git a/src/@utils/ddo.ts b/src/@utils/ddo.ts index 1046b70a0..14ccd87cc 100644 --- a/src/@utils/ddo.ts +++ b/src/@utils/ddo.ts @@ -1,3 +1,5 @@ +import { Asset, DDO, Service } from '@oceanprotocol/lib' + export function getServiceByName( ddo: Asset | DDO, name: 'access' | 'compute' diff --git a/src/@utils/subgraph.ts b/src/@utils/subgraph.ts index 58550c25e..f4668b6d8 100644 --- a/src/@utils/subgraph.ts +++ b/src/@utils/subgraph.ts @@ -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 { diff --git a/src/components/@shared/AssetList/AssetListTitle.tsx b/src/components/@shared/AssetList/AssetListTitle.tsx index e5c1b0d6e..ce9d68796 100644 --- a/src/components/@shared/AssetList/AssetListTitle.tsx +++ b/src/components/@shared/AssetList/AssetListTitle.tsx @@ -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, diff --git a/src/components/@shared/AssetList/index.tsx b/src/components/@shared/AssetList/index.tsx index 78340d0f3..4e1978750 100644 --- a/src/components/@shared/AssetList/index.tsx +++ b/src/components/@shared/AssetList/index.tsx @@ -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) diff --git a/src/components/@shared/AssetTeaser/AssetTeaser.tsx b/src/components/@shared/AssetTeaser/AssetTeaser.tsx index 7615b4a28..c32c6c84c 100644 --- a/src/components/@shared/AssetTeaser/AssetTeaser.tsx +++ b/src/components/@shared/AssetTeaser/AssetTeaser.tsx @@ -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({
-
{dataTokenInfo?.symbol}
+
{datatokens[0]?.symbol}

{name}

diff --git a/src/components/@shared/PoolTransactions/index.tsx b/src/components/@shared/PoolTransactions/index.tsx index 6f88ae2ff..afdfe09f2 100644 --- a/src/components/@shared/PoolTransactions/index.tsx +++ b/src/components/@shared/PoolTransactions/index.tsx @@ -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 diff --git a/src/components/Asset/AssetActions/Compute/AlgorithmDatasetsListForCompute.tsx b/src/components/Asset/AssetActions/Compute/AlgorithmDatasetsListForCompute.tsx index f9735ef96..b0d5d572b 100644 --- a/src/components/Asset/AssetActions/Compute/AlgorithmDatasetsListForCompute.tsx +++ b/src/components/Asset/AssetActions/Compute/AlgorithmDatasetsListForCompute.tsx @@ -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, diff --git a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx index c1ce14849..fafbc4114 100644 --- a/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx +++ b/src/components/Asset/AssetActions/Compute/FormComputeDataset.tsx @@ -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} diff --git a/src/components/Asset/AssetActions/Compute/index.tsx b/src/components/Asset/AssetActions/Compute/index.tsx index 9efcc5161..70ede8cb3 100644 --- a/src/components/Asset/AssetActions/Compute/index.tsx +++ b/src/components/Asset/AssetActions/Compute/index.tsx @@ -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} diff --git a/src/components/Asset/AssetActions/Consume.tsx b/src/components/Asset/AssetActions/Consume.tsx index 416db0e87..6271afb44 100644 --- a/src/components/Asset/AssetActions/Consume.tsx +++ b/src/components/Asset/AssetActions/Consume.tsx @@ -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} diff --git a/src/components/Asset/AssetActions/Trade/FormTrade.tsx b/src/components/Asset/AssetActions/Trade/FormTrade.tsx index 127fc6e38..20135bb4c 100644 --- a/src/components/Asset/AssetActions/Trade/FormTrade.tsx +++ b/src/components/Asset/AssetActions/Trade/FormTrade.tsx @@ -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' diff --git a/src/components/Asset/AssetActions/Trade/Swap.tsx b/src/components/Asset/AssetActions/Trade/Swap.tsx index 221123df5..365aee962 100644 --- a/src/components/Asset/AssetActions/Trade/Swap.tsx +++ b/src/components/Asset/AssetActions/Trade/Swap.tsx @@ -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({ 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) diff --git a/src/components/Asset/AssetActions/index.tsx b/src/components/Asset/AssetActions/index.tsx index 264d243b9..8ea0d0c9a 100644 --- a/src/components/Asset/AssetActions/index.tsx +++ b/src/components/Asset/AssetActions/index.tsx @@ -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' diff --git a/src/components/Asset/AssetContent/MetaFull.tsx b/src/components/Asset/AssetContent/MetaFull.tsx index 359ce2a94..75996e2ac 100644 --- a/src/components/Asset/AssetContent/MetaFull.tsx +++ b/src/components/Asset/AssetContent/MetaFull.tsx @@ -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() diff --git a/src/components/Asset/AssetContent/MetaMain.tsx b/src/components/Asset/AssetContent/MetaMain.tsx index f9093790f..2f1229a13 100644 --- a/src/components/Asset/AssetContent/MetaMain.tsx +++ b/src/components/Asset/AssetContent/MetaMain.tsx @@ -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 (