From 8686078ae801fdc15df5a40ee158a43373d37c1c Mon Sep 17 00:00:00 2001 From: bndw Date: Wed, 26 Apr 2023 17:49:25 -0700 Subject: Initial commit --- app/components/bitcoin-price.tsx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 app/components/bitcoin-price.tsx (limited to 'app/components/bitcoin-price.tsx') diff --git a/app/components/bitcoin-price.tsx b/app/components/bitcoin-price.tsx new file mode 100644 index 0000000..af837d9 --- /dev/null +++ b/app/components/bitcoin-price.tsx @@ -0,0 +1,26 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { BitcoinPrice as btcPrice } from "../utils/bitcoin-price"; + +export const BitcoinPrice = () => { + const [isLoading, setLoading] = useState(false); + const bitcoinPrice = btcPrice(); + + const formatCurrency = (val: string) => { + const n = parseFloat(val); + const formatter = new Intl.NumberFormat("en-US", { + style: "currency", + currency: "USD", + maximumFractionDigits: 0, + }); + + return formatter.format(n); + }; + + useEffect(() => setLoading(!bitcoinPrice), [bitcoinPrice]); + + if (isLoading || !bitcoinPrice) return

Loading...

; + + return
Bitcoin price: {formatCurrency(bitcoinPrice)}
; +}; -- cgit v1.2.3