import React, { ReactElement, useState, useEffect } from 'react' import styles from './index.module.css' import { useMetadata, useOcean } from '@oceanprotocol/react' import { DDO } from '@oceanprotocol/lib' import Loader from '../Loader' import Tooltip from '../Tooltip' import PriceUnit from './PriceUnit' export default function Price({ ddo, className, small, conversion, setPriceOutside }: { ddo: DDO className?: string small?: boolean conversion?: boolean setPriceOutside?: (price: string) => void }): ReactElement { const { ocean, chainId, accountId } = useOcean() const { getBestPrice } = useMetadata() const [price, setPrice] = useState() useEffect(() => { if (!ocean || !accountId || !chainId) return async function init() { const price = await getBestPrice(ddo.dataToken) setPrice(price) setPriceOutside && price !== '' && setPriceOutside(price) } init() }, [chainId, accountId, ocean]) return !ocean ? (
Please connect your wallet to view price
) : price ? ( ) : price === '' ? (
No price found{' '}
) : ( ) }