mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
* Free Pricing Option at create Pricing (#621) * Free Pricing Option + env var toggle * Create Pricing step msg * Default 'allowFreePricing' to true temp for review * Fix price 0 on free tab * Attempt fix useSiteMetadata * Fix linting * Feature/free price support consume compute (#654) * Update fetch free price * Feedback change UI remove 0's * update button msg && fix * compute algorithm list show 'Free' instead of '0' * updateMetadata() v3 workaround solution for free pricing (#677) * compute algorithm list show 'Free' instead of '0' * workaround editMetaData free price * utils function for compute & download * `allowFreePricing` default to false
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import React, { ReactElement } from 'react'
|
|
import { formatCurrency } from '@coingecko/cryptoformat'
|
|
import classNames from 'classnames/bind'
|
|
import Conversion from './Conversion'
|
|
import styles from './PriceUnit.module.css'
|
|
import { useUserPreferences } from '../../../providers/UserPreferences'
|
|
import Badge from '../Badge'
|
|
|
|
const cx = classNames.bind(styles)
|
|
|
|
export function formatPrice(price: string, locale: string): string {
|
|
return formatCurrency(Number(price), '', locale, false, {
|
|
// Not exactly clear what `significant figures` are for this library,
|
|
// but setting this seems to give us the formatting we want.
|
|
// See https://github.com/oceanprotocol/market/issues/70
|
|
significantFigures: 4
|
|
})
|
|
}
|
|
|
|
export default function PriceUnit({
|
|
price,
|
|
className,
|
|
small,
|
|
conversion,
|
|
symbol,
|
|
type
|
|
}: {
|
|
price: string
|
|
type?: string
|
|
className?: string
|
|
small?: boolean
|
|
conversion?: boolean
|
|
symbol?: string
|
|
}): ReactElement {
|
|
const { locale } = useUserPreferences()
|
|
|
|
const styleClasses = cx({
|
|
price: true,
|
|
small: small,
|
|
[className]: className
|
|
})
|
|
|
|
return (
|
|
<div className={styleClasses}>
|
|
{type && type === 'free' ? (
|
|
<div> Free </div>
|
|
) : (
|
|
<>
|
|
<div>
|
|
{Number.isNaN(Number(price)) ? '-' : formatPrice(price, locale)}{' '}
|
|
<span className={styles.symbol}>{symbol || 'OCEAN'}</span>
|
|
{type && type === 'pool' && (
|
|
<Badge label="pool" className={styles.badge} />
|
|
)}
|
|
</div>
|
|
{conversion && <Conversion price={price} />}
|
|
</>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|