asi-calculator/features/prices/components/Price/Price.tsx
Matthias Kretschmann 0d08ba807b
better number formatting (#9)
* tweak number display

* select whole amount upon input focus

* handle letter input

* number formatting
2024-04-16 12:20:29 +02:00

27 lines
737 B
TypeScript

import { useLocale, usePrices, type PriceCoingecko } from '@/features/prices'
import { PriceChange } from './PriceChange'
import styles from './Price.module.css'
import { formatFiat } from '@/lib'
export function Price({ price }: { price: PriceCoingecko }) {
const { isValidating, isLoading } = usePrices()
const locale = useLocale()
const feedbackClasses = isLoading
? 'isLoading'
: isValidating
? 'isValidating'
: ''
return (
<p className={styles.price}>
<span className={`${styles.fiat} ${feedbackClasses}`}>
{formatFiat(price.usd, 'USD', locale)}
</span>
{price?.usd_24h_change ? (
<PriceChange priceChange={price.usd_24h_change} />
) : null}
</p>
)
}