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

added N/A for negative values as well as missing data (#1691)

* added N/A for negative values as well as missing data

* added N/A in teaser for negative orders count

* added N/A to profile and asset teaser

* change typing on Conversion and PriceUnit

* remove log

* removed unnecessary check on price value
This commit is contained in:
EnzoVezzaro 2022-09-22 12:17:12 -04:00 committed by GitHub
parent fa17458d9c
commit 5b2bb3045e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 38 additions and 33 deletions

View File

@ -37,7 +37,7 @@ export default function AssetComputeSelection({
</Dotdotdot> </Dotdotdot>
</div> </div>
<PriceUnit <PriceUnit
price={asset.price} price={Number(asset.price)}
size="small" size="small"
className={styles.price} className={styles.price}
/> />

View File

@ -29,11 +29,13 @@ export default function AssetType({
{type === 'dataset' ? 'dataset' : 'algorithm'} {type === 'dataset' ? 'dataset' : 'algorithm'}
</div> </div>
{totalSales ? ( {(totalSales || totalSales === 0) && (
<div className={styles.typeLabel}> <div className={styles.typeLabel}>
{`${totalSales} ${totalSales === 1 ? 'sale' : 'sales'}`} {totalSales < 0
? 'N/A'
: `${totalSales} ${totalSales === 1 ? 'sale' : 'sales'}`}
</div> </div>
) : null} )}
</div> </div>
) )
} }

View File

@ -108,7 +108,7 @@ export default function AssetSelection({
</label> </label>
<PriceUnit <PriceUnit
price={asset.price} price={Number(asset.price)}
type={asset.price === '0' ? 'free' : undefined} type={asset.price === '0' ? 'free' : undefined}
size="small" size="small"
className={styles.price} className={styles.price}

View File

@ -10,7 +10,7 @@ export default function Conversion({
className, className,
hideApproximateSymbol hideApproximateSymbol
}: { }: {
price: string // expects price in OCEAN, not wei price: number // expects price in OCEAN, not wei
symbol: string symbol: string
className?: string className?: string
hideApproximateSymbol?: boolean hideApproximateSymbol?: boolean
@ -28,18 +28,12 @@ export default function Conversion({
const priceTokenId = getCoingeckoTokenId(symbol) const priceTokenId = getCoingeckoTokenId(symbol)
useEffect(() => { useEffect(() => {
if ( if (!prices || !price || !priceTokenId || !prices[priceTokenId]) {
!prices ||
!price ||
price === '0' ||
!priceTokenId ||
!prices[priceTokenId]
) {
return return
} }
const conversionValue = prices[priceTokenId][currency.toLowerCase()] const conversionValue = prices[priceTokenId][currency.toLowerCase()]
const converted = conversionValue * Number(price) const converted = conversionValue * price
const convertedFormatted = formatCurrency( const convertedFormatted = formatCurrency(
converted, converted,
// No passing of `currency` for non-fiat so symbol conversion // No passing of `currency` for non-fiat so symbol conversion
@ -58,7 +52,7 @@ export default function Conversion({
setPriceConverted(convertedFormattedHTMLstring) setPriceConverted(convertedFormattedHTMLstring)
}, [price, prices, currency, locale, isFiat, priceTokenId]) }, [price, prices, currency, locale, isFiat, priceTokenId])
return Number(price) > 0 ? ( return price > 0 ? (
<span <span
className={`${styles.conversion} ${className || ''}`} className={`${styles.conversion} ${className || ''}`}
title="Approximation based on the current spot price on Coingecko" title="Approximation based on the current spot price on Coingecko"

View File

@ -3,10 +3,9 @@ import { formatCurrency } from '@coingecko/cryptoformat'
import Conversion from './Conversion' import Conversion from './Conversion'
import styles from './PriceUnit.module.css' import styles from './PriceUnit.module.css'
import { useUserPreferences } from '@context/UserPreferences' import { useUserPreferences } from '@context/UserPreferences'
import Badge from '@shared/atoms/Badge'
export function formatPrice(price: string, locale: string): string { export function formatPrice(price: number, locale: string): string {
return formatCurrency(Number(price), '', locale, false, { return formatCurrency(price, '', locale, false, {
// Not exactly clear what `significant figures` are for this library, // Not exactly clear what `significant figures` are for this library,
// but setting this seems to give us the formatting we want. // but setting this seems to give us the formatting we want.
// See https://github.com/oceanprotocol/market/issues/70 // See https://github.com/oceanprotocol/market/issues/70
@ -22,7 +21,7 @@ export default function PriceUnit({
symbol, symbol,
type type
}: { }: {
price: string price: number
type?: string type?: string
className?: string className?: string
size?: 'small' | 'mini' | 'large' size?: 'small' | 'mini' | 'large'
@ -38,7 +37,7 @@ export default function PriceUnit({
) : ( ) : (
<> <>
<div> <div>
{Number.isNaN(Number(price)) ? '-' : formatPrice(price, locale)}{' '} {Number.isNaN(price) ? '-' : formatPrice(price, locale)}{' '}
<span className={styles.symbol}>{symbol}</span> <span className={styles.symbol}>{symbol}</span>
</div> </div>
{conversion && <Conversion price={price} symbol={symbol} />} {conversion && <Conversion price={price} symbol={symbol} />}

View File

@ -16,10 +16,11 @@ export default function Price({
}): ReactElement { }): ReactElement {
const isSupported = const isSupported =
accessDetails?.type === 'fixed' || accessDetails?.type === 'free' accessDetails?.type === 'fixed' || accessDetails?.type === 'free'
const price = `${orderPriceAndFees?.price || accessDetails?.price}`
return isSupported ? ( return isSupported ? (
<PriceUnit <PriceUnit
price={`${orderPriceAndFees?.price || accessDetails?.price}`} price={Number(price)}
symbol={accessDetails.baseToken?.symbol} symbol={accessDetails.baseToken?.symbol}
className={className} className={className}
size={size} size={size}

View File

@ -7,7 +7,9 @@ export default function AssetStats() {
return ( return (
<footer className={styles.stats}> <footer className={styles.stats}>
{!asset || !asset?.stats || asset?.stats?.orders === 0 ? ( {!asset || !asset?.stats || asset?.stats?.orders < 0 ? (
'N/A'
) : asset?.stats?.orders === 0 ? (
'No sales yet' 'No sales yet'
) : ( ) : (
<> <>

View File

@ -45,7 +45,7 @@ function Row({
<div className={styles.type}>{type}</div> <div className={styles.type}>{type}</div>
<div> <div>
<PriceUnit <PriceUnit
price={hasPreviousOrder || hasDatatoken ? '0' : `${price}`} price={hasPreviousOrder || hasDatatoken ? 0 : Number(price)}
symbol={symbol} symbol={symbol}
size="small" size="small"
className={styles.price} className={styles.price}
@ -81,7 +81,7 @@ export default function PriceOutput({
return ( return (
<div className={styles.priceComponent}> <div className={styles.priceComponent}>
You will pay{' '} You will pay{' '}
<PriceUnit price={`${totalPrice}`} symbol={symbol} size="small" /> <PriceUnit price={Number(totalPrice)} symbol={symbol} size="small" />
<Tooltip <Tooltip
content={ content={
<div className={styles.calculation}> <div className={styles.calculation}>

View File

@ -56,7 +56,7 @@ export default function Details(): ReactElement {
</span> </span>
<Conversion <Conversion
className={styles.conversion} className={styles.conversion}
price={value} price={Number(value)}
symbol={key} symbol={key}
/> />
</li> </li>

View File

@ -15,7 +15,7 @@ export default function Stats({
const { chainIds } = useUserPreferences() const { chainIds } = useUserPreferences()
const { assets, assetsTotal, sales } = useProfile() const { assets, assetsTotal, sales } = useProfile()
const [totalSales, setTotalSales] = useState('0') const [totalSales, setTotalSales] = useState(0)
useEffect(() => { useEffect(() => {
if (!assets || !accountId || !chainIds) return if (!assets || !accountId || !chainIds) return
@ -30,7 +30,7 @@ export default function Stats({
parseInt(priceInfo.accessDetails.price) * priceInfo.stats.orders parseInt(priceInfo.accessDetails.price) * priceInfo.stats.orders
} }
} }
setTotalSales(JSON.stringify(count)) setTotalSales(count)
} catch (error) { } catch (error) {
LoggerInstance.error(error.message) LoggerInstance.error(error.message)
} }
@ -43,14 +43,21 @@ export default function Stats({
<NumberUnit <NumberUnit
label="Total Sales" label="Total Sales"
value={ value={
<Conversion totalSales > 0 ? (
price={totalSales} <Conversion
symbol={'ocean'} price={totalSales}
hideApproximateSymbol symbol={'ocean'}
/> hideApproximateSymbol
/>
) : (
'0'
)
} }
/> />
<NumberUnit label={`Sale${sales === 1 ? '' : 's'}`} value={sales} /> <NumberUnit
label={`Sale${sales === 1 ? '' : 's'}`}
value={sales < 0 ? 0 : sales}
/>
<NumberUnit label="Published" value={assetsTotal} /> <NumberUnit label="Published" value={assetsTotal} />
</div> </div>
) )