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

output price on asset teaser

This commit is contained in:
Matthias Kretschmann 2020-08-05 11:18:05 +02:00
parent 1f64e9b5e9
commit 3ab8ae198f
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 24 additions and 11 deletions

View File

@ -1,31 +1,44 @@
import React from 'react' import React, { useState, useEffect } from 'react'
import { Link } from 'gatsby' import { Link } from 'gatsby'
import Dotdotdot from 'react-dotdotdot' import Dotdotdot from 'react-dotdotdot'
import { MetadataMarket } from '../../@types/Metadata' import { MetadataMarket } from '../../@types/Metadata'
import Price from '../atoms/Price' import Price from '../atoms/Price'
import styles from './AssetTeaser.module.css' import styles from './AssetTeaser.module.css'
import { useMetadata } from '@oceanprotocol/react'
import { DDO } from '@oceanprotocol/lib'
declare type AssetTeaserProps = { declare type AssetTeaserProps = {
did: string ddo: DDO
metadata: MetadataMarket metadata: MetadataMarket
} }
const AssetTeaser: React.FC<AssetTeaserProps> = ({ const AssetTeaser: React.FC<AssetTeaserProps> = ({
did, ddo,
metadata metadata
}: AssetTeaserProps) => { }: AssetTeaserProps) => {
if (!metadata.additionalInformation) return null if (!metadata.additionalInformation) return null
const { name } = metadata.main const { name } = metadata.main
const { description, access } = metadata.additionalInformation const { description } = metadata.additionalInformation
const { getBestPrice } = useMetadata(ddo.id)
const [price, setPrice] = useState<string>()
useEffect(() => {
async function init() {
const price = await getBestPrice(ddo.dataToken)
price && setPrice(price)
}
init()
}, [])
return ( return (
<article className={styles.teaser}> <article className={styles.teaser}>
<Link to={`/asset/${did}`} className={styles.link}> <Link to={`/asset/${ddo.id}`} className={styles.link}>
<h1 className={styles.title}>{name}</h1> <h1 className={styles.title}>{name}</h1>
{access === 'Compute' && ( {/* {access === 'Compute' && (
<div className={styles.accessLabel}>{access}</div> <div className={styles.accessLabel}>{access}</div>
)} )} */}
<div className={styles.content}> <div className={styles.content}>
<Dotdotdot tagName="p" clamp={3}> <Dotdotdot tagName="p" clamp={3}>
@ -33,7 +46,9 @@ const AssetTeaser: React.FC<AssetTeaserProps> = ({
</Dotdotdot> </Dotdotdot>
</div> </div>
<footer className={styles.foot}>{/* <Price price={price} /> */}</footer> <footer className={styles.foot}>
{price && <Price price={price} />}
</footer>
</Link> </Link>
</article> </article>
) )

View File

@ -50,9 +50,7 @@ const AssetList: React.FC<AssetListProps> = ({ queryResult }) => {
'metadata' 'metadata'
) )
return ( return <AssetTeaser ddo={ddo} metadata={attributes} key={ddo.id} />
<AssetTeaser did={ddo.id} metadata={attributes} key={ddo.id} />
)
}) })
) : ( ) : (
<div className={styles.empty}> <div className={styles.empty}>