1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-06-29 00:57:50 +02:00
market/src/components/atoms/Price.tsx

35 lines
643 B
TypeScript
Raw Normal View History

2020-07-07 23:00:16 +02:00
import React, { ReactElement } from 'react'
2020-05-07 08:03:30 +02:00
import Web3 from 'web3'
2020-07-07 23:00:16 +02:00
import classNames from 'classnames/bind'
2020-05-07 08:03:30 +02:00
import styles from './Price.module.css'
2020-07-07 23:00:16 +02:00
const cx = classNames.bind(styles)
2020-05-07 08:03:30 +02:00
export default function Price({
price,
2020-05-25 14:53:38 +02:00
className,
small
2020-05-07 08:03:30 +02:00
}: {
price: string
className?: string
2020-05-25 14:53:38 +02:00
small?: boolean
2020-07-07 23:00:16 +02:00
}): ReactElement {
const styleClasses = cx({
price: true,
small: small,
[className]: className
})
2020-05-07 08:03:30 +02:00
const isFree = price === '0'
2020-07-07 23:00:16 +02:00
2020-05-07 08:03:30 +02:00
const displayPrice = isFree ? (
'Free'
) : (
<>
<span>OCEAN</span> {Web3.utils.fromWei(price)}
</>
)
2020-07-07 23:00:16 +02:00
return <div className={styleClasses}>{displayPrice}</div>
2020-05-07 08:03:30 +02:00
}