diff --git a/src/components/auth/SignupDialog.tsx b/src/components/auth/SignupDialog.tsx index b80f333..19cbd24 100644 --- a/src/components/auth/SignupDialog.tsx +++ b/src/components/auth/SignupDialog.tsx @@ -301,7 +301,7 @@ const SignupDialog: React.FC = ({ isOpen, onClose, onComplete {getTitle()} -
+
{/* Welcome Step - New engaging introduction */} {step === 'welcome' && (
diff --git a/src/components/wallet/ActionButtons.tsx b/src/components/wallet/ActionButtons.tsx deleted file mode 100644 index e360d95..0000000 --- a/src/components/wallet/ActionButtons.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { Button } from '@/components/ui/button'; -import { Send, Download } from 'lucide-react'; - -interface ActionButtonsProps { - onSendClick: () => void; - onReceiveClick: () => void; - isLoading?: boolean; -} - -export function ActionButtons({ onSendClick, onReceiveClick, isLoading }: ActionButtonsProps) { - return ( -
- - - -
- ); -} diff --git a/src/components/wallet/BalanceDisplay.tsx b/src/components/wallet/BalanceDisplay.tsx deleted file mode 100644 index 310af0c..0000000 --- a/src/components/wallet/BalanceDisplay.tsx +++ /dev/null @@ -1,107 +0,0 @@ -import { QrCode, Copy, Check } from 'lucide-react'; -import { useState, useEffect } from 'react'; -import { exchangeRateService } from '@/lib/exchangeRateService'; - -interface BalanceDisplayProps { - totalBalance: number; - balances: { [key: string]: number }; - showSats: boolean; - setShowSats: (showSats: boolean) => void; - // Lightning address props - userPubkey?: string; - npubCashUsername?: string; - onCopyToClipboard: (text: string) => Promise; - onShowLightningAddressQR: (qrCode: string) => void; - generateQRCode: (text: string) => Promise; -} - -export function BalanceDisplay({ - totalBalance, - balances, - showSats, - setShowSats, - userPubkey, - npubCashUsername, - onCopyToClipboard, - onShowLightningAddressQR, - generateQRCode, -}: BalanceDisplayProps) { - const [lightningAddressCopied, setLightningAddressCopied] = useState(false); - const [btcUsdRate, setBtcUsdRate] = useState(null); - - useEffect(() => { - exchangeRateService.getBtcUsdRate() - .then(rate => setBtcUsdRate(rate)) - .catch(() => setBtcUsdRate(null)); - }, []); - - const convertCurrency = (sats: number, showSats: boolean): string => { - if (showSats) { - return `₿${sats.toLocaleString()}`; - } else if (btcUsdRate) { - const btcAmount = sats / 100000000; - const usd = btcAmount * btcUsdRate; - return `$${usd.toFixed(2)}`; - } else { - return `₿${sats.toLocaleString()}`; - } - }; - - return ( -
-
- -
- - {/* Lightning Address */} - {userPubkey && ( -
- - -
- )} -
- ); -} diff --git a/src/components/wallet/CashuWallet.tsx b/src/components/wallet/CashuWallet.tsx index e661421..2d76b4e 100644 --- a/src/components/wallet/CashuWallet.tsx +++ b/src/components/wallet/CashuWallet.tsx @@ -11,18 +11,14 @@ import { useMintManager } from '@/hooks/cashu/useMintManager'; import { useWalletTransactions } from '@/hooks/cashu/useWalletTransactions'; import { useHistoryManager } from '@/hooks/cashu/useHistoryManager'; import { QRModal } from '@/components/ui/qr-modal'; -import { BalanceDisplay } from './BalanceDisplay'; -import { MintDisplay } from './MintDisplay'; -import { ActionButtons } from './ActionButtons'; -import { ModeToggle } from './ModeToggle'; +import { WalletHeader } from './WalletHeader'; +import { TransactionCard } from './PaymentCard'; +import { WalletModals } from './MintModals'; import { Drawer, DrawerContent, DrawerHeader, DrawerTitle } from '@/components/ui/drawer'; -import { ReceiveCard } from './ReceiveCard'; -import { SendCard } from './SendCard'; import { TransactionHistory } from './TransactionHistory'; -import { ProofBreakdownModal } from './ProofBreakdownModal'; -import { RemoveMintModal } from './RemoveMintModal'; -import { LoginIcon } from '@/components/auth/LoginIcon'; -import { ChevronUp } from 'lucide-react'; +import { ScrollArea } from '@/components/ui/scroll-area'; +import { ChevronUp, Send, Download } from 'lucide-react'; +import { Button } from '@/components/ui/button'; export function CashuWallet() { // ============================================================================ @@ -282,73 +278,61 @@ export function CashuWallet() { <>
- {/* Mode Toggle */} -
- -
- - {/* Login Icon */} -
- -
- - {/* Centered Balance and Mint Display */} -
- {/* Balance Display */} - { - setLightningAddressQRCode(qr); - setShowLightningAddressQR(true); - }} - generateQRCode={generateQRCode} - /> + {/* Wallet Header (includes mode toggle, login icon, balance, lightning address, and mint selector) */} + { + setLightningAddressQRCode(qr); + setShowLightningAddressQR(true); + }} + generateQRCode={generateQRCode} + // MintSelector props + activeMintUrl={activeMintUrl} + setActiveMintUrl={handleSetActiveMintSync} + mints={mints} + mintUrl={mintUrl} + setMintUrl={setMintUrl} + onAddMint={handleAddMint} + onRemoveMint={handleRemoveMintClick} + onShowDenominations={(mintUrl) => handleShowDenominations(mintUrl, setShowProofBreakdown, setProofBreakdown)} + getCleanMintLabel={getCleanMintLabel} + dropdownOpen={mintDropdownOpen} + setDropdownOpen={setMintDropdownOpen} + /> - {/* Mint Display */} - handleShowDenominations(mintUrl, setShowProofBreakdown, setProofBreakdown)} - getCleanMintLabel={getCleanMintLabel} - dropdownOpen={mintDropdownOpen} - setDropdownOpen={setMintDropdownOpen} - /> -
{/* Action Buttons and Transaction History Container */}
{/* Action Buttons */} - setShowSendModal(true)} - onReceiveClick={() => setShowReceiveModal(true)} - isLoading={isLoading || isNpubCashLoading} - /> - - {/* Sent Token Display */} - {sentToken && ( - setSentToken(null)} - title="Cashu Token" - description="Share this token with the recipient to send them your sats" - qrCodeUrl={sentTokenQRCode} - content={sentToken} - icon="qr" - /> - )} +
+ + + +
{/* Transaction History Button */}
@@ -363,70 +347,30 @@ export function CashuWallet() { {/* Modals */} <> - setShowProofBreakdown(false)} - breakdown={proofBreakdown} - /> - - setShowLightningQR(false)} - title="Lightning Address QR Code" - description="Scan to send Lightning payments" - qrCodeUrl={lightningQRCode} - content={''} - icon="qr" - /> - - setShowLightningAddressQR(false)} - title="Lightning Address" - description="Scan this QR code to send payments to your Lightning address" - qrCodeUrl={lightningAddressQRCode} - content={user?.pubkey ? `${npubCashUserInfo?.name || nip19.npubEncode(user.pubkey)}@npubx.cash` : ''} - icon="zap" - /> - - {currentInvoice && ( - { - // Clean up event listener when modal is closed manually - if (mintQuoteUnsubscribeRef.current) { - mintQuoteUnsubscribeRef.current(); - mintQuoteUnsubscribeRef.current = null; - } - setShowInvoiceModal(false); - }} - onExpiry={() => { - // Clean up event listener when invoice expires - if (mintQuoteUnsubscribeRef.current) { - mintQuoteUnsubscribeRef.current(); - mintQuoteUnsubscribeRef.current = null; - } - toast({ - variant: "destructive", - title: "Invoice Expired", - description: "The Lightning invoice has expired. Please create a new one.", - }); - }} - title="Lightning Invoice" - description={`Pay this invoice to receive ${currentInvoice.amount} sats`} - qrCodeUrl={currentInvoice.qrCodeUrl} - content={currentInvoice.invoice} - icon="zap" - expiryTimestamp={currentInvoice.expiry} - /> - )} - - setShowRemoveMintModal(false)} - mint={mintToRemove} - onConfirm={handleConfirmRemoveMint} + {/* Bottom Drawer Modals */} @@ -436,8 +380,9 @@ export function CashuWallet() { Send
- {}} + quoteAmount="" + setQuoteAmount={() => {}} activeMintUrl={activeMintUrl} onSend={() => { const wasPendingBefore = pendingLightningAddress !== null && pendingLightningAddress !== ''; handleSend(); - // Only close drawer after lightning address flow is complete - // Don't close on Step 1 (address input), only close on Step 2 (amount input) if (mode === 'tokens' || wasPendingBefore) { setShowSendModal(false); } }} + onReceive={() => {}} isResolvingAddress={isResolvingAddress} isLoading={isLoading || isNpubCashLoading} /> @@ -471,17 +419,30 @@ export function CashuWallet() { Receive
- {}} + lightningInvoice="" + setLightningInvoice={() => {}} + lightningAddressInput="" + setLightningAddressInput={() => {}} + lightningAddressAmount="" + setLightningAddressAmount={() => {}} + pendingLightningAddress={null} + setPendingLightningAddress={() => {}} tokenInput={tokenInput} setTokenInput={setTokenInput} quoteAmount={quoteAmount} setQuoteAmount={setQuoteAmount} activeMintUrl={activeMintUrl} + onSend={() => {}} onReceive={() => { handleReceive(); setShowReceiveModal(false); }} + isResolvingAddress={false} isLoading={isLoading || isNpubCashLoading} />
@@ -493,12 +454,12 @@ export function CashuWallet() { Transactions -
+ -
+ diff --git a/src/components/wallet/MintDisplay.tsx b/src/components/wallet/MintDisplay.tsx deleted file mode 100644 index 1de58b6..0000000 --- a/src/components/wallet/MintDisplay.tsx +++ /dev/null @@ -1,182 +0,0 @@ -import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; -import { Plus, X, Check, ChevronDown } from 'lucide-react'; -import { useState, useEffect } from 'react'; -import { exchangeRateService } from '@/lib/exchangeRateService'; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, - DropdownMenuSeparator, -} from '@/components/ui/dropdown-menu'; - -interface CashuMint { - url: string; - name?: string; -} - -interface MintDisplayProps { - balances: { [key: string]: number }; - showSats: boolean; - activeMintUrl: string | null; - setActiveMintUrl: (url: string | null) => void; - mints: CashuMint[]; - mintUrl: string; - setMintUrl: (url: string) => void; - onAddMint: () => void; - onRemoveMint: (mint: CashuMint) => void; - onShowDenominations: (mintUrl: string) => void; - getCleanMintLabel: (mint: { name?: string; url: string }) => string; - dropdownOpen: boolean; - setDropdownOpen: (open: boolean) => void; -} - -export function MintDisplay({ - balances, - showSats, - activeMintUrl, - setActiveMintUrl, - mints, - mintUrl, - setMintUrl, - onAddMint, - onRemoveMint, - onShowDenominations, - getCleanMintLabel, - dropdownOpen, - setDropdownOpen, -}: MintDisplayProps) { - const [btcUsdRate, setBtcUsdRate] = useState(null); - - useEffect(() => { - exchangeRateService.getBtcUsdRate() - .then(rate => setBtcUsdRate(rate)) - .catch(() => setBtcUsdRate(null)); - }, []); - - const convertCurrency = (sats: number, showSats: boolean): string => { - if (showSats) { - return `₿${sats.toLocaleString()}`; - } else if (btcUsdRate) { - const btcAmount = sats / 100000000; - const usd = btcAmount * btcUsdRate; - return `$${usd.toFixed(2)}`; - } else { - return `₿${sats.toLocaleString()}`; - } - }; - - const activeMint = mints.find(mint => mint.url === activeMintUrl); - const activeBalance = activeMint ? balances[activeMint.url] || 0 : 0; - - return ( -
- {/* Mint Selector Dropdown */} -
- - - - - - {mints - .filter((mint) => mint.url) - .map((mint, index) => { - const isActive = activeMintUrl === mint.url; - const balance = balances[mint.url] || 0; - - return ( - setActiveMintUrl(mint.url)} - className="flex items-center justify-between p-3 text-base" - > -
- {isActive && ( -
- -
- )} -
-
- {getCleanMintLabel(mint)} -
-
-
-
- - {convertCurrency(balance, showSats)} - - -
-
- ); - })} - {mints.length > 0 && } - -
- setMintUrl(e.target.value)} - className="flex-1" - onClick={(e) => e.stopPropagation()} - onKeyDown={(e) => { - e.stopPropagation(); - // Prevent dropdown from closing on keyboard input - if (e.key === 'Escape') { - setDropdownOpen(false); - } else if (e.key === 'Enter') { - e.preventDefault(); - if (mintUrl.trim()) { - onAddMint(); - } - } - }} - onKeyUp={(e) => e.stopPropagation()} - /> - -
-
-
-
-
-
- ); -} diff --git a/src/components/wallet/MintModals.tsx b/src/components/wallet/MintModals.tsx new file mode 100644 index 0000000..4af8ab0 --- /dev/null +++ b/src/components/wallet/MintModals.tsx @@ -0,0 +1,274 @@ +import { Button } from '@/components/ui/button'; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import { Badge } from '@/components/ui/badge'; +import { X, Coins, AlertTriangle, RefreshCw } from 'lucide-react'; +import { QRModal } from '@/components/ui/qr-modal'; +import { nip19 } from 'nostr-tools'; +import { useToast } from '@/hooks/useToast'; + +interface ProofBreakdown { + mintUrl: string; + denominations: { [key: number]: number }; + totalBalance: number; +} + +interface MintToRemove { + url: string; + name?: string; +} + +interface WalletModalProps { + // Proof Breakdown Modal + showProofBreakdown: boolean; + setShowProofBreakdown: (show: boolean) => void; + proofBreakdown: ProofBreakdown | null; + + // Remove Mint Modal + showRemoveMintModal: boolean; + setShowRemoveMintModal: (show: boolean) => void; + mintToRemove: MintToRemove | null; + onConfirmRemoveMint: () => void; + isLoading: boolean; + + // QR Modals + showLightningQR: boolean; + setShowLightningQR: (show: boolean) => void; + lightningQRCode: string; + showLightningAddressQR: boolean; + setShowLightningAddressQR: (show: boolean) => void; + lightningAddressQRCode: string; + userPubkey?: string; + npubCashUserInfo?: { name?: string } | null; + + // Invoice Modal + currentInvoice?: { + amount: number; + qrCodeUrl: string; + invoice: string; + expiry: number; + } | null; + showInvoiceModal: boolean; + setShowInvoiceModal: (show: boolean) => void; + mintQuoteUnsubscribeRef: React.MutableRefObject<(() => void) | null>; + + // Sent Token Modal + sentToken: string | null; + setSentToken: (token: string | null) => void; + sentTokenQRCode: string; +} + +export function WalletModals({ + showProofBreakdown, + setShowProofBreakdown, + proofBreakdown, + showRemoveMintModal, + setShowRemoveMintModal, + mintToRemove, + onConfirmRemoveMint, + isLoading, + showLightningQR, + setShowLightningQR, + lightningQRCode, + showLightningAddressQR, + setShowLightningAddressQR, + lightningAddressQRCode, + userPubkey, + npubCashUserInfo, + currentInvoice, + showInvoiceModal, + setShowInvoiceModal, + mintQuoteUnsubscribeRef, + sentToken, + setSentToken, + sentTokenQRCode, +}: WalletModalProps) { + const { toast } = useToast(); + return ( + <> + {/* Proof Breakdown Modal */} + {showProofBreakdown && proofBreakdown && ( +
setShowProofBreakdown(false)} + > + e.stopPropagation()} + > + + + + + Token Breakdown + + + {new URL(proofBreakdown.mintUrl).hostname} + + + +
+
+ {proofBreakdown.totalBalance.toLocaleString()} sats +
+
Total Balance
+
+ +
+
Denominations:
+ {Object.entries(proofBreakdown.denominations) + .sort(([a], [b]) => parseInt(a) - parseInt(b)) + .map(([amount, count]) => ( +
+
+ + {parseInt(amount).toLocaleString()} sats +
+ + × {count} + +
+ ))} +
+ +
+ 💡 Tip: If you can't pay an invoice, try sending tokens to yourself to get different denominations. +
+
+
+
+ )} + + {/* Remove Mint Modal */} + {showRemoveMintModal && mintToRemove && ( +
+ + + + + + Remove Mint + + + Are you sure you want to remove this mint from your wallet? + + + +
+
{mintToRemove.name || new URL(mintToRemove.url).hostname}
+
+ +
+
⚠️ This will remove the mint and all associated data. Any tokens from this mint will no longer be accessible.
+
💡 You can always add this mint back later if needed.
+
+ +
+ + +
+
+
+
+ )} + + {/* QR Modals */} + setShowLightningQR(false)} + title="Lightning Address QR Code" + description="Scan to send Lightning payments" + qrCodeUrl={lightningQRCode} + content={''} + icon="qr" + /> + + setShowLightningAddressQR(false)} + title="Lightning Address" + description="Scan this QR code to send payments to your Lightning address" + qrCodeUrl={lightningAddressQRCode} + content={userPubkey ? `${npubCashUserInfo?.name || nip19.npubEncode(userPubkey)}@npubx.cash` : ''} + icon="zap" + /> + + {currentInvoice && ( + { + if (mintQuoteUnsubscribeRef.current) { + mintQuoteUnsubscribeRef.current(); + mintQuoteUnsubscribeRef.current = null; + } + setShowInvoiceModal(false); + }} + onExpiry={() => { + if (mintQuoteUnsubscribeRef.current) { + mintQuoteUnsubscribeRef.current(); + mintQuoteUnsubscribeRef.current = null; + } + toast({ + variant: "destructive", + title: "Invoice Expired", + description: "The Lightning invoice has expired. Please create a new one.", + }); + }} + title="Lightning Invoice" + description={`Pay this invoice to receive ${currentInvoice.amount} sats`} + qrCodeUrl={currentInvoice.qrCodeUrl} + content={currentInvoice.invoice} + icon="zap" + expiryTimestamp={currentInvoice.expiry} + /> + )} + + {/* Sent Token Modal */} + {sentToken && ( + setSentToken(null)} + title="Cashu Token" + description="Share this token with the recipient to send them your sats" + qrCodeUrl={sentTokenQRCode} + content={sentToken} + icon="qr" + /> + )} + + ); +} diff --git a/src/components/wallet/MintSelector.tsx b/src/components/wallet/MintSelector.tsx new file mode 100644 index 0000000..f7e5010 --- /dev/null +++ b/src/components/wallet/MintSelector.tsx @@ -0,0 +1,190 @@ +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Plus, X, Check, ChevronDown, Wallet } from 'lucide-react'; +import { useState, useEffect } from 'react'; +import { exchangeRateService } from '@/lib/exchangeRateService'; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, + DropdownMenuSeparator, +} from '@/components/ui/dropdown-menu'; + +interface CashuMint { + url: string; + name?: string; +} + +interface MintSelectorProps { + balances: { [key: string]: number }; + showSats: boolean; + activeMintUrl: string | null; + setActiveMintUrl: (url: string | null) => void; + mints: CashuMint[]; + mintUrl: string; + setMintUrl: (url: string) => void; + onAddMint: () => void; + onRemoveMint: (mint: CashuMint) => void; + onShowDenominations: (mintUrl: string) => void; + getCleanMintLabel: (mint: { name?: string; url: string }) => string; + dropdownOpen: boolean; + setDropdownOpen: (open: boolean) => void; +} + +export function MintSelector({ + balances, + showSats, + activeMintUrl, + setActiveMintUrl, + mints, + mintUrl, + setMintUrl, + onAddMint, + onRemoveMint, + onShowDenominations, + getCleanMintLabel, + dropdownOpen, + setDropdownOpen, +}: MintSelectorProps) { + const [btcUsdRate, setBtcUsdRate] = useState(null); + + useEffect(() => { + exchangeRateService.getBtcUsdRate() + .then(rate => setBtcUsdRate(rate)) + .catch(() => setBtcUsdRate(null)); + }, []); + + const formatBalance = (sats: number): string => { + if (showSats) { + return `₿${sats.toLocaleString()}`; + } else if (btcUsdRate) { + const btcAmount = sats / 100000000; + const usd = btcAmount * btcUsdRate; + return `$${usd.toFixed(2)}`; + } else { + return `₿${sats.toLocaleString()}`; + } + }; + + const activeMint = mints.find(mint => mint.url === activeMintUrl); + const activeBalance = activeMint ? balances[activeMint.url] || 0 : 0; + + return ( +
+ + + + + + {mints + .filter((mint) => mint.url) + .map((mint, index) => { + const isActive = activeMintUrl === mint.url; + const balance = balances[mint.url] || 0; + + return ( + setActiveMintUrl(mint.url)} + className="flex items-center justify-between p-3 text-base" + > +
+ {isActive && ( +
+ +
+ )} +
+
+ {getCleanMintLabel(mint)} +
+
+
+
+ + {formatBalance(balance)} + + +
+
+ ); + })} + {mints.length > 0 && } + +
+ setMintUrl(e.target.value)} + className="flex-1" + onClick={(e) => e.stopPropagation()} + onKeyDown={(e) => { + e.stopPropagation(); + if (e.key === 'Escape') { + setDropdownOpen(false); + } else if (e.key === 'Enter') { + e.preventDefault(); + if (mintUrl.trim()) { + onAddMint(); + } + } + }} + onKeyUp={(e) => e.stopPropagation()} + /> + +
+
+
+
+ + {activeMint && ( +
+ +
+ )} +
+ ); +} diff --git a/src/components/wallet/ModeToggle.tsx b/src/components/wallet/ModeToggle.tsx deleted file mode 100644 index ae92f5d..0000000 --- a/src/components/wallet/ModeToggle.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { Zap, Coins } from 'lucide-react'; -import { useToast } from '@/hooks/useToast'; - -interface ModeToggleProps { - mode: 'tokens' | 'lightning'; - setMode: (mode: 'tokens' | 'lightning') => void; -} - -export function ModeToggle({ mode, setMode }: ModeToggleProps) { - const { toast } = useToast(); - - const toggleMode = () => { - const newMode = mode === 'tokens' ? 'lightning' : 'tokens'; - setMode(newMode); - - toast({ - title: `${newMode === 'tokens' ? 'Cashu' : 'Lightning'} Enabled!`, - description: newMode === 'tokens' - ? 'Send and receive with Cashu eCash' - : 'Send and receive with Lightning', - }); - }; - - return ( - - ); -} diff --git a/src/components/wallet/PaymentCard.tsx b/src/components/wallet/PaymentCard.tsx new file mode 100644 index 0000000..a4fc7a5 --- /dev/null +++ b/src/components/wallet/PaymentCard.tsx @@ -0,0 +1,256 @@ +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Send, Download, Zap, Loader2, X } from 'lucide-react'; + +interface TransactionCardProps { + mode: 'tokens' | 'lightning'; + operation: 'send' | 'receive'; + // Send props + sendAmount: string; + setSendAmount: (value: string) => void; + lightningInvoice: string; + setLightningInvoice: (value: string) => void; + lightningAddressInput: string; + setLightningAddressInput: (value: string) => void; + lightningAddressAmount: string; + setLightningAddressAmount: (value: string) => void; + pendingLightningAddress: string | null; + setPendingLightningAddress: (value: string | null) => void; + // Receive props + tokenInput: string; + setTokenInput: (value: string) => void; + quoteAmount: string; + setQuoteAmount: (value: string) => void; + // Common props + activeMintUrl: string | null; + onSend: () => void; + onReceive: () => void; + isResolvingAddress: boolean; + isLoading: boolean; +} + +export function TransactionCard({ + mode, + operation, + sendAmount, + setSendAmount, + lightningInvoice, + setLightningInvoice, + lightningAddressInput, + setLightningAddressInput, + lightningAddressAmount, + setLightningAddressAmount, + pendingLightningAddress, + setPendingLightningAddress, + tokenInput, + setTokenInput, + quoteAmount, + setQuoteAmount, + activeMintUrl, + onSend, + onReceive, + isResolvingAddress, + isLoading, +}: TransactionCardProps) { + return ( +
+ {/* Title */} +
+

+ {operation === 'send' ? ( + mode === 'tokens' + ? 'Generate Cashu token to send' + : pendingLightningAddress ? ( + + Sending to:{' '} + {pendingLightningAddress} + + ) : 'Pay invoices or addresses' + ) : ( + mode === 'tokens' + ? 'Enter Cashu token to redeem' + : 'Deposit funds with Lightning' + )} +

+
+ + {/* Content */} +
+ {!activeMintUrl && ( +
+ {operation === 'send' + ? (mode === 'tokens' ? 'Select a mint to send tokens' : 'Select a mint to pay Lightning invoices') + : (mode === 'tokens' ? 'Select a mint to receive tokens' : 'Select a mint to create Lightning invoice') + } +
+ )} + + {operation === 'send' ? ( + // Send Mode + mode === 'tokens' ? ( + // Cashu Token Send +
+ setSendAmount(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter' && sendAmount && activeMintUrl && !isLoading) { + onSend(); + } + }} + disabled={!activeMintUrl} + className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2 [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none [-moz-appearance:textfield]" + /> +
+ +
+
+ ) : pendingLightningAddress ? ( + // Lightning Address Amount Input +
+ setLightningAddressAmount(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter' && lightningAddressAmount && activeMintUrl && !isResolvingAddress && !isLoading) { + onSend(); + } + }} + disabled={!activeMintUrl} + className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2 [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none [-moz-appearance:textfield]" + /> +
+ + +
+
+ ) : ( + // Lightning Invoice/Address Input +
+ { + const value = e.target.value; + if (value.includes('@')) { + setLightningAddressInput(value); + setLightningInvoice(''); + } else { + setLightningInvoice(value); + setLightningAddressInput(''); + } + }} + onKeyDown={(e) => { + if (e.key === 'Enter' && (lightningInvoice.trim() || lightningAddressInput.trim()) && activeMintUrl && !isLoading) { + onSend(); + } + }} + disabled={!activeMintUrl} + className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2" + /> +
+ +
+
+ ) + ) : ( + // Receive Mode + mode === 'tokens' ? ( + // Cashu Token Receive +
+ setTokenInput(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter' && tokenInput.trim() && activeMintUrl && !isLoading) { + onReceive(); + } + }} + disabled={!activeMintUrl} + className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2" + /> +
+ +
+
+ ) : ( + // Lightning Invoice Receive +
+ setQuoteAmount(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter' && quoteAmount && activeMintUrl && !isLoading) { + onReceive(); + } + }} + disabled={!activeMintUrl} + className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2 [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none [-moz-appearance:textfield]" + /> +
+ +
+
+ ) + )} +
+
+ ); +} diff --git a/src/components/wallet/ProofBreakdownModal.tsx b/src/components/wallet/ProofBreakdownModal.tsx deleted file mode 100644 index 54ed818..0000000 --- a/src/components/wallet/ProofBreakdownModal.tsx +++ /dev/null @@ -1,79 +0,0 @@ -import { Button } from '@/components/ui/button'; -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; -import { Badge } from '@/components/ui/badge'; -import { X, Coins } from 'lucide-react'; - -interface ProofBreakdown { - mintUrl: string; - denominations: { [key: number]: number }; - totalBalance: number; -} - -interface ProofBreakdownModalProps { - isOpen: boolean; - onClose: () => void; - breakdown: ProofBreakdown | null; -} - -export function ProofBreakdownModal({ isOpen, onClose, breakdown }: ProofBreakdownModalProps) { - if (!isOpen || !breakdown) return null; - - return ( -
- e.stopPropagation()} - > - - - - - Token Breakdown - - - {new URL(breakdown.mintUrl).hostname} - - - -
-
- {breakdown.totalBalance.toLocaleString()} sats -
-
Total Balance
-
- -
-
Denominations:
- {Object.entries(breakdown.denominations) - .sort(([a], [b]) => parseInt(a) - parseInt(b)) - .map(([amount, count]) => ( -
-
- - {parseInt(amount).toLocaleString()} sats -
- - × {count} - -
- ))} -
- -
- 💡 Tip: If you can't pay an invoice, try sending tokens to yourself to get different denominations. -
-
-
-
- ); -} diff --git a/src/components/wallet/ReceiveCard.tsx b/src/components/wallet/ReceiveCard.tsx deleted file mode 100644 index 2e1f065..0000000 --- a/src/components/wallet/ReceiveCard.tsx +++ /dev/null @@ -1,109 +0,0 @@ -import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; -import { Download, Zap } from 'lucide-react'; - -interface ReceiveCardProps { - mode: 'tokens' | 'lightning'; - tokenInput: string; - setTokenInput: (value: string) => void; - quoteAmount: string; - setQuoteAmount: (value: string) => void; - activeMintUrl: string | null; - onReceive: () => void; - isLoading: boolean; -} - -export function ReceiveCard({ - mode, - tokenInput, - setTokenInput, - quoteAmount, - setQuoteAmount, - activeMintUrl, - onReceive, - isLoading, -}: ReceiveCardProps) { - return ( -
- {/* Title */} -
-

- {mode === 'tokens' - ? 'Enter Cashu token to redeem' - : 'Deposit funds with Lightning' - } -

-
- - {/* Content */} -
- {mode === 'tokens' ? ( - <> - {!activeMintUrl && ( -
- Select a mint to receive tokens -
- )} -
- setTokenInput(e.target.value)} - onKeyDown={(e) => { - if (e.key === 'Enter' && tokenInput.trim() && activeMintUrl && !isLoading) { - onReceive(); - } - }} - disabled={!activeMintUrl} - className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2" - /> -
- -
-
- - ) : ( - <> - {!activeMintUrl && ( -
- Select a mint to create Lightning invoice -
- )} -
- setQuoteAmount(e.target.value)} - onKeyDown={(e) => { - if (e.key === 'Enter' && quoteAmount && activeMintUrl && !isLoading) { - onReceive(); - } - }} - disabled={!activeMintUrl} - className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2 [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none [-moz-appearance:textfield]" - /> -
- -
-
- - )} -
-
- ); -} diff --git a/src/components/wallet/RemoveMintModal.tsx b/src/components/wallet/RemoveMintModal.tsx deleted file mode 100644 index a9eaca0..0000000 --- a/src/components/wallet/RemoveMintModal.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { Button } from '@/components/ui/button'; -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; -import { AlertTriangle, X, RefreshCw } from 'lucide-react'; - -interface MintToRemove { - url: string; - name?: string; -} - -interface RemoveMintModalProps { - isOpen: boolean; - onClose: () => void; - mint: MintToRemove | null; - onConfirm: () => void; - isLoading: boolean; -} - -export function RemoveMintModal({ isOpen, onClose, mint, onConfirm, isLoading }: RemoveMintModalProps) { - if (!isOpen || !mint) return null; - - return ( -
- - - - - - Remove Mint - - - Are you sure you want to remove this mint from your wallet? - - - -
-
{mint.name || new URL(mint.url).hostname}
-
- -
-
⚠️ This will remove the mint and all associated data. Any tokens from this mint will no longer be accessible.
-
💡 You can always add this mint back later if needed.
-
- -
- - -
-
-
-
- ); -} diff --git a/src/components/wallet/SendCard.tsx b/src/components/wallet/SendCard.tsx deleted file mode 100644 index b05f36b..0000000 --- a/src/components/wallet/SendCard.tsx +++ /dev/null @@ -1,185 +0,0 @@ -import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; -import { Send, Zap, Loader2, X } from 'lucide-react'; - -interface SendCardProps { - mode: 'tokens' | 'lightning'; - sendAmount: string; - setSendAmount: (value: string) => void; - lightningInvoice: string; - setLightningInvoice: (value: string) => void; - lightningAddressInput: string; - setLightningAddressInput: (value: string) => void; - lightningAddressAmount: string; - setLightningAddressAmount: (value: string) => void; - pendingLightningAddress: string | null; - setPendingLightningAddress: (value: string | null) => void; - activeMintUrl: string | null; - onSend: () => void; - isResolvingAddress: boolean; - isLoading: boolean; -} - -export function SendCard({ - mode, - sendAmount, - setSendAmount, - lightningInvoice, - setLightningInvoice, - lightningAddressInput, - setLightningAddressInput, - lightningAddressAmount, - setLightningAddressAmount, - pendingLightningAddress, - setPendingLightningAddress, - activeMintUrl, - onSend, - isResolvingAddress, - isLoading, -}: SendCardProps) { - return ( -
- {/* Title */} -
-

- {mode === 'tokens' - ? 'Generate Cashu token to send' - : pendingLightningAddress - ? ( - - Sending to:{' '} - {pendingLightningAddress} - - ) - : 'Pay invoices or addresses' - } -

-
- - {/* Content */} -
- {mode === 'tokens' ? ( - <> - {!activeMintUrl && ( -
- Select a mint to send tokens -
- )} -
- setSendAmount(e.target.value)} - onKeyDown={(e) => { - if (e.key === 'Enter' && sendAmount && activeMintUrl && !isLoading) { - onSend(); - } - }} - disabled={!activeMintUrl} - className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2 [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none [-moz-appearance:textfield]" - /> -
- -
-
- - ) : ( - <> - {!activeMintUrl && ( -
- Select a mint to pay Lightning invoices -
- )} - {pendingLightningAddress ? ( - // Step 2: Show amount input for Lightning address -
- setLightningAddressAmount(e.target.value)} - onKeyDown={(e) => { - if (e.key === 'Enter' && lightningAddressAmount && activeMintUrl && !isResolvingAddress && !isLoading) { - onSend(); - } - }} - disabled={!activeMintUrl} - className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2 [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none [-moz-appearance:textfield]" - /> -
- - -
-
- ) : ( - // Step 1: Show invoice/address input -
- { - const value = e.target.value; - if (value.includes('@')) { - setLightningAddressInput(value); - setLightningInvoice(''); - } else { - setLightningInvoice(value); - setLightningAddressInput(''); - } - }} - onKeyDown={(e) => { - if (e.key === 'Enter' && (lightningInvoice.trim() || lightningAddressInput.trim()) && activeMintUrl && !isLoading) { - onSend(); - } - }} - disabled={!activeMintUrl} - className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2" - /> -
- -
-
- )} - - )} -
-
- ); -} diff --git a/src/components/wallet/WalletHeader.tsx b/src/components/wallet/WalletHeader.tsx new file mode 100644 index 0000000..faafda0 --- /dev/null +++ b/src/components/wallet/WalletHeader.tsx @@ -0,0 +1,193 @@ +import { useState, useEffect } from 'react'; +import { nip19 } from 'nostr-tools'; +import { Zap, Coins, Copy, Check, QrCode } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { exchangeRateService } from '@/lib/exchangeRateService'; +import { useToast } from '@/hooks/useToast'; +import { LoginIcon } from '@/components/auth/LoginIcon'; +import { MintSelector } from './MintSelector'; + +interface CashuMint { + url: string; + name?: string; +} + +interface WalletHeaderProps { + totalBalance: number; + balances: { [key: string]: number }; + showSats: boolean; + setShowSats: (showSats: boolean) => void; + mode: 'tokens' | 'lightning'; + setMode: (mode: 'tokens' | 'lightning') => void; + userPubkey?: string; + npubCashUsername?: string; + onCopyToClipboard: (text: string) => Promise; + onShowLightningAddressQR: (qrCode: string) => void; + generateQRCode: (text: string) => Promise; + // MintSelector props + activeMintUrl: string | null; + setActiveMintUrl: (url: string | null) => void; + mints: CashuMint[]; + mintUrl: string; + setMintUrl: (url: string) => void; + onAddMint: () => void; + onRemoveMint: (mint: CashuMint) => void; + onShowDenominations: (mintUrl: string) => void; + getCleanMintLabel: (mint: { name?: string; url: string }) => string; + dropdownOpen: boolean; + setDropdownOpen: (open: boolean) => void; +} + +export function WalletHeader({ + totalBalance, + balances, + showSats, + setShowSats, + mode, + setMode, + userPubkey, + npubCashUsername, + onCopyToClipboard, + onShowLightningAddressQR, + generateQRCode, + // MintSelector props + activeMintUrl, + setActiveMintUrl, + mints, + mintUrl, + setMintUrl, + onAddMint, + onRemoveMint, + onShowDenominations, + getCleanMintLabel, + dropdownOpen, + setDropdownOpen, +}: WalletHeaderProps) { + const [lightningAddressCopied, setLightningAddressCopied] = useState(false); + const [btcUsdRate, setBtcUsdRate] = useState(null); + const { toast } = useToast(); + + useEffect(() => { + exchangeRateService.getBtcUsdRate() + .then(rate => setBtcUsdRate(rate)) + .catch(() => setBtcUsdRate(null)); + }, []); + + const toggleMode = () => { + const newMode = mode === 'tokens' ? 'lightning' : 'tokens'; + setMode(newMode); + + toast({ + title: `${newMode === 'tokens' ? 'Cashu' : 'Lightning'} Enabled!`, + description: newMode === 'tokens' + ? 'Send and receive with Cashu eCash' + : 'Send and receive with Lightning', + }); + }; + + + return ( +
+ {/* Mode Toggle */} +
+ +
+ + {/* Login Icon */} +
+ +
+ + {/* Balance Display */} +
+
+ +
+ + {/* Lightning Address and Mint Selector Grid */} +
+
+
+ {/* Lightning Address Row */} + {userPubkey && ( +
+ + +
+ )} + + {/* Mint Selector Row */} + +
+
+
+
+
+ ); +}