From f08b7da22add7e682730304460f0875bb5bd303c Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 21 Jul 2020 13:21:22 +0200 Subject: [PATCH] fix asset display --- src/components/molecules/AssetTeaser.tsx | 6 ++---- .../organisms/AssetActions/Compute.tsx | 5 +++-- .../organisms/AssetActions/Consume.tsx | 21 ++++++++++--------- .../organisms/AssetActions/index.tsx | 9 ++++---- .../organisms/AssetContent/MetaFull.tsx | 2 +- .../organisms/AssetContent/index.tsx | 9 ++++---- src/pages/asset/index.tsx | 6 ++++-- 7 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/components/molecules/AssetTeaser.tsx b/src/components/molecules/AssetTeaser.tsx index 03f3c1356..9958f0f81 100644 --- a/src/components/molecules/AssetTeaser.tsx +++ b/src/components/molecules/AssetTeaser.tsx @@ -16,7 +16,7 @@ const AssetTeaser: React.FC = ({ }: AssetTeaserProps) => { if (!metadata.additionalInformation) return null - const { name, price } = metadata.main + const { name } = metadata.main const { description, access } = metadata.additionalInformation return ( @@ -33,9 +33,7 @@ const AssetTeaser: React.FC = ({ -
- -
+
{/* */}
) diff --git a/src/components/organisms/AssetActions/Compute.tsx b/src/components/organisms/AssetActions/Compute.tsx index b2522037b..c52a593ef 100644 --- a/src/components/organisms/AssetActions/Compute.tsx +++ b/src/components/organisms/AssetActions/Compute.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect, ReactElement } from 'react' -import { Ocean } from '@oceanprotocol/lib' +import { DDO } from '@oceanprotocol/lib' import { fromWei } from 'web3-utils' import compareAsBN, { Comparisson } from '../../../utils/compareAsBN' import Loader from '../../atoms/Loader' @@ -22,7 +22,8 @@ export default function Compute({ did }: { did: string }): ReactElement { const { ocean } = useOcean() const { ddo } = useMetadata(did) const { compute, isLoading, computeStepText, computeError } = useCompute() - const computeService = ddo.findServiceByType('compute').attributes.main + const computeService = new DDO(ddo).findServiceByType('compute').attributes + .main const [isJobStarting, setIsJobStarting] = useState(false) const [, setError] = useState('') diff --git a/src/components/organisms/AssetActions/Consume.tsx b/src/components/organisms/AssetActions/Consume.tsx index 26e9d3770..48c630f47 100644 --- a/src/components/organisms/AssetActions/Consume.tsx +++ b/src/components/organisms/AssetActions/Consume.tsx @@ -1,7 +1,7 @@ import React, { ReactElement } from 'react' import { fromWei } from 'web3-utils' import { toast } from 'react-toastify' -import { File as FileMetadata } from '@oceanprotocol/lib' +import { File as FileMetadata, DDO } from '@oceanprotocol/lib' import compareAsBN, { Comparisson } from '../../../utils/compareAsBN' import Button from '../../atoms/Button' import File from '../../atoms/File' @@ -9,22 +9,22 @@ import Price from '../../atoms/Price' import Web3Feedback from '../../molecules/Wallet/Feedback' import styles from './Consume.module.css' import Loader from '../../atoms/Loader' -import { useOcean, useConsume, useMetadata } from '@oceanprotocol/react' +import { useOcean, useConsume } from '@oceanprotocol/react' export default function Consume({ - did, + ddo, file }: { - did: string + ddo: DDO file: FileMetadata }): ReactElement { - const { ddo } = useMetadata(did) - const { cost } = ddo.findServiceByType('access').attributes.main + const accessService = ddo.findServiceByType('access') + const { cost } = accessService.attributes.main const { ocean } = useOcean() const { consumeStepText, consume, consumeError } = useConsume() - const isFree = cost === '0' + // const isFree = cost === '0' // const isBalanceSufficient = // isFree || compareAsBN(balanceInOcean, fromWei(cost), Comparisson.gte) const isDisabled = !ocean @@ -39,10 +39,11 @@ export default function Consume({ ) : ( ) @@ -53,7 +54,7 @@ export default function Consume({
- + {/* */}
diff --git a/src/components/organisms/AssetActions/index.tsx b/src/components/organisms/AssetActions/index.tsx index 37e398b01..01d0f6d26 100644 --- a/src/components/organisms/AssetActions/index.tsx +++ b/src/components/organisms/AssetActions/index.tsx @@ -4,13 +4,14 @@ import styles from './index.module.css' import Compute from './Compute' import Consume from './Consume' import { MetadataMarket } from '../../../@types/Metadata' +import { MetadataStore, Logger, DDO } from '@oceanprotocol/lib' export default function AssetActions({ metadata, - did + ddo }: { metadata: MetadataMarket - did: string + ddo: DDO }): ReactElement { const { access } = metadata.additionalInformation const isCompute = access && access === 'Compute' @@ -24,9 +25,9 @@ export default function AssetActions({
{isCompute ? ( - + ) : ( - + )} Trade Me diff --git a/src/components/organisms/AssetContent/MetaFull.tsx b/src/components/organisms/AssetContent/MetaFull.tsx index 141c952ce..24c414597 100644 --- a/src/components/organisms/AssetContent/MetaFull.tsx +++ b/src/components/organisms/AssetContent/MetaFull.tsx @@ -18,7 +18,7 @@ export default function MetaFull({
- + {categories && } } /> - +
{/*
- +
diff --git a/src/pages/asset/index.tsx b/src/pages/asset/index.tsx index 57e483cd2..36e454c27 100644 --- a/src/pages/asset/index.tsx +++ b/src/pages/asset/index.tsx @@ -4,7 +4,7 @@ import AssetContent from '../../components/organisms/AssetContent' import Layout from '../../components/Layout' import { PageProps } from 'gatsby' import { MetadataMarket, ServiceMetadataMarket } from '../../@types/Metadata' -import { MetadataStore, Logger } from '@oceanprotocol/lib' +import { MetadataStore, Logger, DDO } from '@oceanprotocol/lib' import Alert from '../../components/atoms/Alert' import Loader from '../../components/atoms/Loader' import { useSiteMetadata } from '../../hooks/useSiteMetadata' @@ -14,6 +14,7 @@ export default function AssetRoute(props: PageProps): ReactElement { const [metadata, setMetadata] = useState() const [title, setTitle] = useState() const [error, setError] = useState() + const [ddo, setDdo] = useState() const did = props.location.pathname.split('/')[2] @@ -25,6 +26,7 @@ export default function AssetRoute(props: PageProps): ReactElement { Logger ) const ddo = await metadataStore.retrieveDDO(did) + setDdo(ddo) if (!ddo) { setTitle('Could not retrieve asset') @@ -50,7 +52,7 @@ export default function AssetRoute(props: PageProps): ReactElement {