1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-11-15 09:44:53 +01:00

safeguard against assets without attributes.additionalInformation

This commit is contained in:
Matthias Kretschmann 2020-09-10 19:54:32 +02:00
parent 5b36da54d2
commit cda52aef1c
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 52 additions and 43 deletions

View File

@ -15,11 +15,7 @@ const AssetTeaser: React.FC<AssetTeaserProps> = ({
ddo, ddo,
metadata metadata
}: AssetTeaserProps) => { }: AssetTeaserProps) => {
// TODO: hacky safeguard should be replaced with search query to account for pagination
if (!metadata.additionalInformation) return null
const { name } = metadata.main const { name } = metadata.main
const { description } = metadata.additionalInformation
const isCompute = Boolean(ddo.findServiceByType('compute')) const isCompute = Boolean(ddo.findServiceByType('compute'))
return ( return (
@ -30,7 +26,7 @@ const AssetTeaser: React.FC<AssetTeaserProps> = ({
<div className={styles.content}> <div className={styles.content}>
<Dotdotdot tagName="p" clamp={3}> <Dotdotdot tagName="p" clamp={3}>
{description || ''} {metadata?.additionalInformation?.description || ''}
</Dotdotdot> </Dotdotdot>
</div> </div>

View File

@ -7,6 +7,7 @@ import Tabs from '../../atoms/Tabs'
import { useOcean, useMetadata } from '@oceanprotocol/react' import { useOcean, useMetadata } from '@oceanprotocol/react'
import compareAsBN from '../../../utils/compareAsBN' import compareAsBN from '../../../utils/compareAsBN'
import Pool from './Pool' import Pool from './Pool'
import { AdditionalInformationMarket } from '../../../@types/MetaData'
export default function AssetActions({ ddo }: { ddo: DDO }): ReactElement { export default function AssetActions({ ddo }: { ddo: DDO }): ReactElement {
const { balance } = useOcean() const { balance } = useOcean()
@ -15,7 +16,6 @@ export default function AssetActions({ ddo }: { ddo: DDO }): ReactElement {
const isCompute = Boolean(ddo.findServiceByType('compute')) const isCompute = Boolean(ddo.findServiceByType('compute'))
const { attributes } = ddo.findServiceByType('metadata') const { attributes } = ddo.findServiceByType('metadata')
const { priceType } = attributes.additionalInformation
// Check user balance against price // Check user balance against price
useEffect(() => { useEffect(() => {
@ -44,7 +44,10 @@ export default function AssetActions({ ddo }: { ddo: DDO }): ReactElement {
title: 'Use', title: 'Use',
content: UseContent content: UseContent
}, },
(!priceType || priceType === 'dynamic') && { (!((attributes.additionalInformation as unknown) as AdditionalInformationMarket)
?.priceType ||
((attributes.additionalInformation as unknown) as AdditionalInformationMarket)
?.priceType === 'dynamic') && {
title: 'Pool', title: 'Pool',
content: <Pool ddo={ddo} /> content: <Pool ddo={ddo} />
} }

View File

@ -18,7 +18,6 @@ export default function MetaFull({
const { ocean, accountId } = useOcean() const { ocean, accountId } = useOcean()
const { id, dataToken } = ddo const { id, dataToken } = ddo
const { dateCreated, datePublished, author, license } = metadata.main const { dateCreated, datePublished, author, license } = metadata.main
const { categories, copyrightHolder } = metadata.additionalInformation
const [dtName, setDtName] = useState<string>() const [dtName, setDtName] = useState<string>()
const [dtSymbol, setDtSymbol] = useState<string>() const [dtSymbol, setDtSymbol] = useState<string>()
@ -38,9 +37,17 @@ export default function MetaFull({
return ( return (
<div className={styles.metaFull}> <div className={styles.metaFull}>
<MetaItem title="Author" content={author} /> <MetaItem title="Author" content={author} />
<MetaItem title="Copyright Holder" content={copyrightHolder} /> <MetaItem
title="Copyright Holder"
content={metadata?.additionalInformation?.copyrightHolder}
/>
<MetaItem title="License" content={license} /> <MetaItem title="License" content={license} />
{categories && <MetaItem title="Category" content={categories[0]} />} {metadata?.additionalInformation?.categories && (
<MetaItem
title="Category"
content={metadata?.additionalInformation?.categories[0]}
/>
)}
<MetaItem title="Data Created" content={<Time date={dateCreated} />} /> <MetaItem title="Data Created" content={<Time date={dateCreated} />} />
<MetaItem <MetaItem

View File

@ -10,31 +10,33 @@ export default function MetaSecondary({
}: { }: {
metadata: MetadataMarket metadata: MetadataMarket
}): ReactElement { }): ReactElement {
const { links, tags } = metadata.additionalInformation
return ( return (
<aside className={styles.metaSecondary}> <aside className={styles.metaSecondary}>
{tags && tags.length > 0 && <Tags items={tags} />} {metadata?.additionalInformation?.tags &&
metadata?.additionalInformation?.tags.length > 0 && (
<Tags items={metadata?.additionalInformation?.tags} />
)}
{links && links.length && ( {metadata?.additionalInformation?.links &&
<div className={styles.samples}> metadata?.additionalInformation?.links.length && (
<MetaItem <div className={styles.samples}>
title="Sample Data" <MetaItem
content={ title="Sample Data"
<Button content={
href={links[0].url} <Button
target="_blank" href={metadata?.additionalInformation?.links[0].url}
rel="noreferrer" target="_blank"
download rel="noreferrer"
style="text" download
size="small" style="text"
> size="small"
Download Sample >
</Button> Download Sample
} </Button>
/> }
</div> />
)} </div>
)}
</aside> </aside>
) )
} }

View File

@ -21,7 +21,6 @@ export default function AssetContent({
ddo ddo
}: AssetContentProps): ReactElement { }: AssetContentProps): ReactElement {
const { datePublished } = metadata.main const { datePublished } = metadata.main
const { description, categories } = metadata.additionalInformation
const { debug } = useUserPreferences() const { debug } = useUserPreferences()
return ( return (
@ -29,16 +28,19 @@ export default function AssetContent({
<div className={styles.content}> <div className={styles.content}>
<aside className={styles.meta}> <aside className={styles.meta}>
<p>{datePublished && <Time date={datePublished} />}</p> <p>{datePublished && <Time date={datePublished} />}</p>
{categories && categories.length && ( {metadata?.additionalInformation?.categories &&
<p> metadata?.additionalInformation?.categories?.length && (
<Link to={`/search?categories=["${categories[0]}"]`}> <p>
{categories[0]} <Link
</Link> to={`/search?categories=["${metadata?.additionalInformation?.categories[0]}"]`}
</p> >
)} {metadata?.additionalInformation?.categories[0]}
</Link>
</p>
)}
</aside> </aside>
<Markdown text={description || ''} /> <Markdown text={metadata?.additionalInformation?.description || ''} />
<MetaSecondary metadata={metadata} /> <MetaSecondary metadata={metadata} />

View File

@ -14,8 +14,7 @@ async function getLatestAssets(metadataStoreUri: string) {
const result = await metadataStore.queryMetadata({ const result = await metadataStore.queryMetadata({
page: 1, page: 1,
// TODO: hacky workaround because some assets pushed by external devs are faulty // TODO: reduce assets here, once faulty assets pushed by external devs are removed
// See molecules/AssetTeaser.tsx
offset: 100, offset: 100,
query: {}, query: {},
sort: { created: -1 } sort: { created: -1 }