From ebe9f9afe79bce0adae371c403ac707cd44f1c15 Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Thu, 5 Oct 2023 23:27:27 +0200 Subject: [PATCH] refactor: Receive component from jsx to tsx --- src/components/BitcoinQR.tsx | 10 +++---- src/components/CopyButton.tsx | 15 +++++++++- src/components/{Receive.jsx => Receive.tsx} | 33 +++++++++++++-------- 3 files changed, 39 insertions(+), 19 deletions(-) rename src/components/{Receive.jsx => Receive.tsx} (93%) diff --git a/src/components/BitcoinQR.tsx b/src/components/BitcoinQR.tsx index a666391e6..a033b4636 100644 --- a/src/components/BitcoinQR.tsx +++ b/src/components/BitcoinQR.tsx @@ -6,17 +6,17 @@ import { AmountSats, BitcoinAddress } from '../libs/JmWalletApi' interface BitcoinQRProps { address: BitcoinAddress - sats: AmountSats - errorCorrectionLevel: QRCode.QRCodeErrorCorrectionLevel + amount?: AmountSats + errorCorrectionLevel?: QRCode.QRCodeErrorCorrectionLevel width?: number } -export const BitcoinQR = ({ address, sats, errorCorrectionLevel = 'H', width = 260 }: BitcoinQRProps) => { +export const BitcoinQR = ({ address, amount, errorCorrectionLevel = 'H', width = 260 }: BitcoinQRProps) => { const [data, setData] = useState() const [image, setImage] = useState() useEffect(() => { - const btc = satsToBtc(String(sats)) || 0 + const btc = amount ? satsToBtc(String(amount)) || 0 : 0 const uri = `bitcoin:${address}${btc > 0 ? `?amount=${btc.toFixed(8)}` : ''}` QRCode.toDataURL(uri, { @@ -31,7 +31,7 @@ export const BitcoinQR = ({ address, sats, errorCorrectionLevel = 'H', width = 2 setImage(undefined) setData(uri) }) - }, [address, sats, errorCorrectionLevel, width]) + }, [address, amount, errorCorrectionLevel, width]) return (
diff --git a/src/components/CopyButton.tsx b/src/components/CopyButton.tsx index 713afc26d..c3a479338 100644 --- a/src/components/CopyButton.tsx +++ b/src/components/CopyButton.tsx @@ -38,15 +38,25 @@ interface CopyableProps { onSuccess?: () => void onError?: (e: Error) => void className?: string + disabled?: boolean } -function Copyable({ value, onSuccess, onError, className, children, ...props }: PropsWithChildren) { +function Copyable({ + value, + onSuccess, + onError, + className, + children, + disabled, + ...props +}: PropsWithChildren) { const valueFallbackInputRef = useRef(null) return ( <>