2020-10-01 17:13:19 +02:00
|
|
|
import { MetadataMarket } from '../../../@types/MetaData'
|
2020-11-26 16:02:42 +01:00
|
|
|
import React, { ReactElement, useEffect, useState } from 'react'
|
2020-12-02 14:37:01 +01:00
|
|
|
import { graphql, Link, useStaticQuery } from 'gatsby'
|
2020-07-06 12:49:30 +02:00
|
|
|
import Markdown from '../../atoms/Markdown'
|
|
|
|
import MetaFull from './MetaFull'
|
|
|
|
import MetaSecondary from './MetaSecondary'
|
2020-07-07 09:43:45 +02:00
|
|
|
import styles from './index.module.css'
|
2020-07-08 17:57:53 +02:00
|
|
|
import AssetActions from '../AssetActions'
|
2020-07-21 14:04:32 +02:00
|
|
|
import { DDO } from '@oceanprotocol/lib'
|
2020-09-09 16:07:37 +02:00
|
|
|
import { useUserPreferences } from '../../../providers/UserPreferences'
|
2020-10-20 13:10:03 +02:00
|
|
|
import Pricing from './Pricing'
|
2020-11-27 12:04:35 +01:00
|
|
|
import { useOcean, usePricing } from '@oceanprotocol/react'
|
2020-10-24 17:01:04 +02:00
|
|
|
import EtherscanLink from '../../atoms/EtherscanLink'
|
2020-10-28 23:59:14 +01:00
|
|
|
import Bookmark from './Bookmark'
|
2020-11-27 12:04:35 +01:00
|
|
|
import Publisher from '../../atoms/Publisher'
|
2020-11-26 16:02:42 +01:00
|
|
|
import { useAsset } from '../../../providers/Asset'
|
2020-12-02 14:37:01 +01:00
|
|
|
import Alert from '../../atoms/Alert'
|
2020-07-06 12:49:30 +02:00
|
|
|
|
|
|
|
export interface AssetContentProps {
|
2020-07-16 13:39:02 +02:00
|
|
|
metadata: MetadataMarket
|
2020-07-21 13:21:22 +02:00
|
|
|
ddo: DDO
|
2020-07-06 12:49:30 +02:00
|
|
|
path?: string
|
|
|
|
}
|
|
|
|
|
2020-12-02 14:37:01 +01:00
|
|
|
const contentQuery = graphql`
|
|
|
|
query AssetContentQuery {
|
|
|
|
purgatory: allFile(filter: { relativePath: { eq: "purgatory.json" } }) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
childContentJson {
|
|
|
|
asset {
|
|
|
|
title
|
|
|
|
description
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2020-07-06 12:49:30 +02:00
|
|
|
export default function AssetContent({
|
|
|
|
metadata,
|
2020-07-21 13:21:22 +02:00
|
|
|
ddo
|
2020-07-06 12:49:30 +02:00
|
|
|
}: AssetContentProps): ReactElement {
|
2020-12-02 14:37:01 +01:00
|
|
|
const data = useStaticQuery(contentQuery)
|
|
|
|
const content = data.purgatory.edges[0].node.childContentJson.asset
|
|
|
|
|
2020-09-09 16:07:37 +02:00
|
|
|
const { debug } = useUserPreferences()
|
2020-10-24 17:01:04 +02:00
|
|
|
const { accountId, networkId } = useOcean()
|
2020-12-02 14:37:01 +01:00
|
|
|
const { owner, isInPurgatory, purgatoryData } = useAsset()
|
2020-10-24 17:01:04 +02:00
|
|
|
const { dtSymbol, dtName } = usePricing(ddo)
|
2020-11-26 16:02:42 +01:00
|
|
|
const [showPricing, setShowPricing] = useState(false)
|
|
|
|
const { price } = useAsset()
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setShowPricing(accountId === owner && price.isConsumable === '')
|
|
|
|
}, [accountId, owner, price])
|
2020-07-06 12:49:30 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<article className={styles.grid}>
|
2020-10-20 20:56:54 +02:00
|
|
|
<div>
|
2020-10-20 18:33:24 +02:00
|
|
|
{showPricing && <Pricing ddo={ddo} />}
|
2020-10-20 20:56:54 +02:00
|
|
|
<div className={styles.content}>
|
2020-11-05 14:43:13 +01:00
|
|
|
{metadata?.additionalInformation?.categories?.length && (
|
|
|
|
<p>
|
|
|
|
<Link
|
|
|
|
to={`/search?categories=${metadata?.additionalInformation?.categories[0]}`}
|
|
|
|
>
|
|
|
|
{metadata?.additionalInformation?.categories[0]}
|
|
|
|
</Link>
|
2020-10-30 14:58:36 +01:00
|
|
|
</p>
|
2020-11-05 14:43:13 +01:00
|
|
|
)}
|
2020-10-24 17:01:04 +02:00
|
|
|
|
2020-11-05 14:43:13 +01:00
|
|
|
<aside className={styles.meta}>
|
2020-10-24 17:01:04 +02:00
|
|
|
<p className={styles.datatoken}>
|
|
|
|
<EtherscanLink
|
|
|
|
networkId={networkId}
|
|
|
|
path={`token/${ddo.dataToken}`}
|
|
|
|
>
|
|
|
|
{dtName ? (
|
2020-11-03 14:57:40 +01:00
|
|
|
`${dtName} — ${dtSymbol}`
|
2020-10-24 17:01:04 +02:00
|
|
|
) : (
|
|
|
|
<code>{ddo.dataToken}</code>
|
|
|
|
)}
|
|
|
|
</EtherscanLink>
|
|
|
|
</p>
|
2020-11-27 12:04:35 +01:00
|
|
|
Published By <Publisher account={owner} />
|
2020-10-20 20:56:54 +02:00
|
|
|
</aside>
|
2020-07-06 12:49:30 +02:00
|
|
|
|
2020-12-02 14:37:01 +01:00
|
|
|
{isInPurgatory ? (
|
|
|
|
<Alert
|
|
|
|
title={content.title}
|
|
|
|
badge={`Reason: ${purgatoryData?.reason}`}
|
|
|
|
text={content.description}
|
|
|
|
state="error"
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<Markdown
|
|
|
|
className={styles.description}
|
|
|
|
text={metadata?.additionalInformation?.description || ''}
|
|
|
|
/>
|
2020-07-08 00:06:48 +02:00
|
|
|
|
2020-12-02 14:37:01 +01:00
|
|
|
<MetaSecondary metadata={metadata} />
|
|
|
|
</>
|
|
|
|
)}
|
2020-07-08 00:06:48 +02:00
|
|
|
|
2020-12-02 14:37:01 +01:00
|
|
|
<MetaFull
|
|
|
|
ddo={ddo}
|
|
|
|
metadata={metadata}
|
|
|
|
isInPurgatory={isInPurgatory}
|
|
|
|
/>
|
2020-08-03 12:04:03 +02:00
|
|
|
|
2020-10-20 20:56:54 +02:00
|
|
|
{debug === true && (
|
|
|
|
<pre>
|
|
|
|
<code>{JSON.stringify(ddo, null, 2)}</code>
|
|
|
|
</pre>
|
|
|
|
)}
|
2020-10-28 23:59:14 +01:00
|
|
|
|
|
|
|
<Bookmark did={ddo.id} />
|
2020-10-20 20:56:54 +02:00
|
|
|
</div>
|
2020-07-06 12:49:30 +02:00
|
|
|
</div>
|
2020-10-20 20:56:54 +02:00
|
|
|
|
2020-11-02 19:18:21 +01:00
|
|
|
<div className={styles.actions}>
|
|
|
|
<AssetActions ddo={ddo} />
|
2020-07-06 12:49:30 +02:00
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
)
|
|
|
|
}
|