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

fix asset display

This commit is contained in:
Matthias Kretschmann 2020-07-21 13:21:22 +02:00
parent 14bc02b9ee
commit f08b7da22a
Signed by: m
GPG Key ID: 606EEEF3C479A91F
7 changed files with 31 additions and 27 deletions

View File

@ -16,7 +16,7 @@ const AssetTeaser: React.FC<AssetTeaserProps> = ({
}: AssetTeaserProps) => { }: AssetTeaserProps) => {
if (!metadata.additionalInformation) return null if (!metadata.additionalInformation) return null
const { name, price } = metadata.main const { name } = metadata.main
const { description, access } = metadata.additionalInformation const { description, access } = metadata.additionalInformation
return ( return (
@ -33,9 +33,7 @@ const AssetTeaser: React.FC<AssetTeaserProps> = ({
</Dotdotdot> </Dotdotdot>
</div> </div>
<footer className={styles.foot}> <footer className={styles.foot}>{/* <Price price={price} /> */}</footer>
<Price price={price} />
</footer>
</Link> </Link>
</article> </article>
) )

View File

@ -1,5 +1,5 @@
import React, { useState, useEffect, ReactElement } from 'react' import React, { useState, useEffect, ReactElement } from 'react'
import { Ocean } from '@oceanprotocol/lib' import { DDO } from '@oceanprotocol/lib'
import { fromWei } from 'web3-utils' import { fromWei } from 'web3-utils'
import compareAsBN, { Comparisson } from '../../../utils/compareAsBN' import compareAsBN, { Comparisson } from '../../../utils/compareAsBN'
import Loader from '../../atoms/Loader' import Loader from '../../atoms/Loader'
@ -22,7 +22,8 @@ export default function Compute({ did }: { did: string }): ReactElement {
const { ocean } = useOcean() const { ocean } = useOcean()
const { ddo } = useMetadata(did) const { ddo } = useMetadata(did)
const { compute, isLoading, computeStepText, computeError } = useCompute() 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 [isJobStarting, setIsJobStarting] = useState(false)
const [, setError] = useState('') const [, setError] = useState('')

View File

@ -1,7 +1,7 @@
import React, { ReactElement } from 'react' import React, { ReactElement } from 'react'
import { fromWei } from 'web3-utils' import { fromWei } from 'web3-utils'
import { toast } from 'react-toastify' 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 compareAsBN, { Comparisson } from '../../../utils/compareAsBN'
import Button from '../../atoms/Button' import Button from '../../atoms/Button'
import File from '../../atoms/File' import File from '../../atoms/File'
@ -9,22 +9,22 @@ import Price from '../../atoms/Price'
import Web3Feedback from '../../molecules/Wallet/Feedback' import Web3Feedback from '../../molecules/Wallet/Feedback'
import styles from './Consume.module.css' import styles from './Consume.module.css'
import Loader from '../../atoms/Loader' import Loader from '../../atoms/Loader'
import { useOcean, useConsume, useMetadata } from '@oceanprotocol/react' import { useOcean, useConsume } from '@oceanprotocol/react'
export default function Consume({ export default function Consume({
did, ddo,
file file
}: { }: {
did: string ddo: DDO
file: FileMetadata file: FileMetadata
}): ReactElement { }): ReactElement {
const { ddo } = useMetadata(did) const accessService = ddo.findServiceByType('access')
const { cost } = ddo.findServiceByType('access').attributes.main const { cost } = accessService.attributes.main
const { ocean } = useOcean() const { ocean } = useOcean()
const { consumeStepText, consume, consumeError } = useConsume() const { consumeStepText, consume, consumeError } = useConsume()
const isFree = cost === '0' // const isFree = cost === '0'
// const isBalanceSufficient = // const isBalanceSufficient =
// isFree || compareAsBN(balanceInOcean, fromWei(cost), Comparisson.gte) // isFree || compareAsBN(balanceInOcean, fromWei(cost), Comparisson.gte)
const isDisabled = !ocean const isDisabled = !ocean
@ -39,10 +39,11 @@ export default function Consume({
) : ( ) : (
<Button <Button
style="primary" style="primary"
onClick={() => consume(did, ddo.dataToken, 'access')} onClick={() => consume(ddo.id, ddo.dataToken, 'access')}
disabled={isDisabled} disabled={isDisabled}
> >
{isFree ? 'Download' : 'Buy'} Download
{/* {isFree ? 'Download' : 'Buy'} */}
</Button> </Button>
) )
@ -53,7 +54,7 @@ export default function Consume({
<File file={file} /> <File file={file} />
</div> </div>
<div className={styles.pricewrapper}> <div className={styles.pricewrapper}>
<Price price={cost} className={styles.price} /> {/* <Price price={cost} className={styles.price} /> */}
<PurchaseButton /> <PurchaseButton />
</div> </div>
</div> </div>

View File

@ -4,13 +4,14 @@ import styles from './index.module.css'
import Compute from './Compute' import Compute from './Compute'
import Consume from './Consume' import Consume from './Consume'
import { MetadataMarket } from '../../../@types/Metadata' import { MetadataMarket } from '../../../@types/Metadata'
import { MetadataStore, Logger, DDO } from '@oceanprotocol/lib'
export default function AssetActions({ export default function AssetActions({
metadata, metadata,
did ddo
}: { }: {
metadata: MetadataMarket metadata: MetadataMarket
did: string ddo: DDO
}): ReactElement { }): ReactElement {
const { access } = metadata.additionalInformation const { access } = metadata.additionalInformation
const isCompute = access && access === 'Compute' const isCompute = access && access === 'Compute'
@ -24,9 +25,9 @@ export default function AssetActions({
<div className={styles.tabContent}> <div className={styles.tabContent}>
<TabPanel> <TabPanel>
{isCompute ? ( {isCompute ? (
<Compute did={did} /> <Compute ddo={ddo} />
) : ( ) : (
<Consume did={did} file={metadata.main.files[0]} /> <Consume ddo={ddo} file={metadata.main.files[0]} />
)} )}
</TabPanel> </TabPanel>
<TabPanel>Trade Me</TabPanel> <TabPanel>Trade Me</TabPanel>

View File

@ -18,7 +18,7 @@ export default function MetaFull({
<div className={styles.metaFull}> <div className={styles.metaFull}>
<MetaItem title="Author" content={author} /> <MetaItem title="Author" content={author} />
<MetaItem title="License" content={license} /> <MetaItem title="License" content={license} />
<MetaItem title="Category" content={categories[0]} /> {categories && <MetaItem title="Category" content={categories[0]} />}
<MetaItem title="Data Created" content={<Time date={dateCreated} />} /> <MetaItem title="Data Created" content={<Time date={dateCreated} />} />
<MetaItem <MetaItem

View File

@ -7,16 +7,17 @@ import MetaFull from './MetaFull'
import MetaSecondary from './MetaSecondary' import MetaSecondary from './MetaSecondary'
import styles from './index.module.css' import styles from './index.module.css'
import AssetActions from '../AssetActions' import AssetActions from '../AssetActions'
import { MetadataStore, Logger, DDO } from '@oceanprotocol/lib'
export interface AssetContentProps { export interface AssetContentProps {
metadata: MetadataMarket metadata: MetadataMarket
did: string ddo: DDO
path?: string path?: string
} }
export default function AssetContent({ export default function AssetContent({
metadata, metadata,
did ddo
}: AssetContentProps): ReactElement { }: AssetContentProps): ReactElement {
const { datePublished } = metadata.main const { datePublished } = metadata.main
const { description, categories } = metadata.additionalInformation const { description, categories } = metadata.additionalInformation
@ -39,7 +40,7 @@ export default function AssetContent({
<MetaSecondary metadata={metadata} /> <MetaSecondary metadata={metadata} />
<MetaFull did={did} metadata={metadata} /> <MetaFull did={ddo.id} metadata={metadata} />
<div className={styles.buttonGroup}> <div className={styles.buttonGroup}>
{/* <EditAction {/* <EditAction
@ -53,7 +54,7 @@ export default function AssetContent({
</div> </div>
<div> <div>
<div className={styles.sticky}> <div className={styles.sticky}>
<AssetActions metadata={metadata} did={did} /> <AssetActions metadata={metadata} ddo={ddo} />
</div> </div>
</div> </div>
</article> </article>

View File

@ -4,7 +4,7 @@ import AssetContent from '../../components/organisms/AssetContent'
import Layout from '../../components/Layout' import Layout from '../../components/Layout'
import { PageProps } from 'gatsby' import { PageProps } from 'gatsby'
import { MetadataMarket, ServiceMetadataMarket } from '../../@types/Metadata' 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 Alert from '../../components/atoms/Alert'
import Loader from '../../components/atoms/Loader' import Loader from '../../components/atoms/Loader'
import { useSiteMetadata } from '../../hooks/useSiteMetadata' import { useSiteMetadata } from '../../hooks/useSiteMetadata'
@ -14,6 +14,7 @@ export default function AssetRoute(props: PageProps): ReactElement {
const [metadata, setMetadata] = useState<MetadataMarket>() const [metadata, setMetadata] = useState<MetadataMarket>()
const [title, setTitle] = useState<string>() const [title, setTitle] = useState<string>()
const [error, setError] = useState<string>() const [error, setError] = useState<string>()
const [ddo, setDdo] = useState<DDO>()
const did = props.location.pathname.split('/')[2] const did = props.location.pathname.split('/')[2]
@ -25,6 +26,7 @@ export default function AssetRoute(props: PageProps): ReactElement {
Logger Logger
) )
const ddo = await metadataStore.retrieveDDO(did) const ddo = await metadataStore.retrieveDDO(did)
setDdo(ddo)
if (!ddo) { if (!ddo) {
setTitle('Could not retrieve asset') setTitle('Could not retrieve asset')
@ -50,7 +52,7 @@ export default function AssetRoute(props: PageProps): ReactElement {
<Layout title={title} uri={props.location.pathname}> <Layout title={title} uri={props.location.pathname}>
<Router basepath="/asset"> <Router basepath="/asset">
<AssetContent <AssetContent
did={did} ddo={ddo}
metadata={metadata as MetadataMarket} metadata={metadata as MetadataMarket}
path=":did" path=":did"
/> />