+
+ {/* ========================================================================
+ SECTION: Balance Display
+ ======================================================================== */}
+ {isInitialized && (
+
+
+
+
+
+ {/* Active Mint Dropdown and Balance */}
+
+
+
+
+
+
+ Connected Mints
+
+ {mints.length === 0 && (
+ No mints connected
+ )}
+ {mints
+ .filter((mint) => mint.url)
+ .map((mint, index) => (
+ setActiveMintUrl(mint.url)}
+ >
+
+ {getCleanMintLabel(mint as any)}
+
+
+ ))}
+
+
+
+
setMintUrl(e.target.value)}
+ className="h-8"
+ />
+
+
+
+
+
+
+ {/* Active Mint Balance */}
+ {activeMintUrl && (
+
+
+
+ )}
+
+
+ )}
+
+ {/* ========================================================================
+ SECTION: Error Display
+ ======================================================================== */}
+ {error && (
+
+
+ {error}
+
+
+
+ )}
+
+ {/* ========================================================================
+ SECTION: Receive & Send Cards
+ ======================================================================== */}
+
+
+ {/* Receive Card */}
+
+
+
+
+
+ Receive
+
+
+
+
+
+
+
+ {receiveMode === 'tokens'
+ ? 'Enter Cashu token to redeem'
+ : 'Deposit funds with Lightning'
+ }
+
+
+
+ {receiveMode === 'tokens' ? (
+
+ setTokenInput(e.target.value)}
+ className="flex-1"
+ />
+
+
+ ) : (
+ <>
+ {!activeMintUrl && (
+
+ Select a mint from "Connected Mints" to create Lightning invoice
+
+ )}
+
+ setQuoteAmount(e.target.value)}
+ />
+
+
+ >
+ )}
+
+
+
+ {/* Send Card */}
+
+
+
+
+
+ Send
+
+
+
+
+
+
+
+ {sendMode === 'tokens'
+ ? 'Generate Cashu token to send'
+ : pendingLightningAddress
+ ? 'Enter the amount to send'
+ : 'Pay Lightning invoices or addresses from balance'
+ }
+
+
+
+ {sendMode === 'tokens' ? (
+ <>
+ {!activeMintUrl && (
+
+ Select a mint from "Connected Mints" to send tokens
+
+ )}
+
+ setSendAmount(e.target.value)}
+ />
+
+
+ >
+ ) : (
+ <>
+ {!activeMintUrl && (
+
+ Select a mint from "Connected Mints" to pay Lightning invoices
+
+ )}
+ {pendingLightningAddress ? (
+ // Step 2: Show amount input for Lightning address
+
+
+
+ Sending to: {pendingLightningAddress}
+
+
+ Enter amount to send
+
+
+
+ setLightningAddressAmount(e.target.value)}
+ autoFocus
+ />
+
+
+
+
+ ) : (
+ // Step 1: Show invoice/address input
+
+ {
+ const value = e.target.value;
+ if (value.includes('@')) {
+ setLightningAddressInput(value);
+ setLightningInvoice('');
+ } else {
+ setLightningInvoice(value);
+ setLightningAddressInput('');
+ }
+ }}
+ className="flex-1"
+ />
+
+
+ )}
+ >
+ )}
+
+
+
+
+ {/* ========================================================================
+ SECTION: Sent Token Display
+ ======================================================================== */}
+ {sentToken && (
+
+
+
+
+
+ Token Created Successfully
+
+
+ Share this token with the recipient to send them your sats
+
+
+
+
+
+ {sentToken.length > 20 ? `${sentToken.substring(0, 20)}...` : sentToken}
+
+
+
+
+
+ )}
+
+ {/* ========================================================================
+ SECTION: Pending Lightning Payments
+ ======================================================================== */}
+ {pendingQuotes.length > 0 && (
+
+
+
+
+
+ Pending Lightning Payments
+
+
+ Click "Check Payment" after paying the Lightning invoice
+
+
+
+
+ {pendingQuotes.map((quote) => (
+
+
+
+
{quote.amount} sats
+
+ {new URL(quote.mintUrl).hostname}
+
+
+ Created: {new Date(quote.timestamp).toLocaleTimeString()}
+
+
+
+
+
+
+ {quote.invoice.length > 20 ? `${quote.invoice.substring(0, 20)}...` : quote.invoice}
+
+
+
+
+ ))}
+
+
+
+ )}
+
+ {/* ========================================================================
+ SECTION: Transaction History
+ ======================================================================== */}
+
+
+
+
+
+ Transaction History
+
+ {historyEntries.length > 3 && (
+
+ )}
+
+
+ View your recent transactions
+
+
+
+ {isLoadingHistory ? (
+
+
+ Loading history...
+
+ ) : historyEntries.length === 0 ? (
+
+ No transaction history yet
+
+ ) : (
+
+ {(isHistoryExpanded ? historyEntries : historyEntries.slice(0, 3)).map((entry) => (
+
+
+
+
+ {getHistoryIcon(entry.type)}
+
+
+
+
+ {getHistoryLabel(entry.type)}
+
+ {entry.state && (
+
+ {entry.state}
+
+ )}
+
+
+ {new URL(entry.mintUrl).hostname}
+
+
+ {new Date(entry.createdAt).toLocaleString()}
+
+
+
+
+
+ {entry.type === 'send' || entry.type === 'melt' ? '-' : '+'}
+ {entry.amount.toLocaleString()} {entry.unit}
+
+
+
+
+ ))}
+
+ )}
+
+
+
+ {/* ========================================================================
+ SECTION: Proof Breakdown Modal
+ ======================================================================== */}
+ {showProofBreakdown && proofBreakdown && (
+
+
+
+
+
+
+ Token Breakdown
+
+
+ {new URL(proofBreakdown.mintUrl).hostname}
+
+
+
+
+
+ {formatAmount(proofBreakdown.totalBalance)}
+
+
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.
+
+
+
+
+ )}
+
+ );
+}
diff --git a/src/hooks/useCashu.ts b/src/hooks/useCashu.ts
new file mode 100644
index 0000000..cc0bde8
--- /dev/null
+++ b/src/hooks/useCashu.ts
@@ -0,0 +1,523 @@
+import { useState, useEffect, useCallback, useRef } from 'react';
+import { useLocalStorage } from './useLocalStorage';
+import * as bip39 from '@scure/bip39';
+import { wordlist } from '@scure/bip39/wordlists/english';
+
+// Types for the hook interface
+export interface CashuBalance {
+ [mintUrl: string]: number;
+}
+
+export interface CashuMint {
+ url: string;
+ name?: string;
+ info?: any;
+}
+
+export interface CashuMintQuote {
+ quote: string;
+ request: string;
+ expiry: number;
+}
+
+export interface CashuMeltQuote {
+ quote: string;
+ request: string;
+ expiry: number;
+}
+
+export interface CashuToken {
+ mint: string;
+ proofs: any[];
+}
+
+export interface CashuState {
+ isInitialized: boolean;
+ isLoading: boolean;
+ error: string | null;
+ balances: CashuBalance;
+ mints: CashuMint[];
+ mnemonic: string | null;
+}
+
+export interface HistoryEntry {
+ id: string;
+ type: 'mint' | 'melt' | 'send' | 'receive';
+ mintUrl: string;
+ amount: number;
+ unit: string;
+ createdAt: number;
+ metadata?: any;
+ quoteId?: string;
+ state?: string;
+ paymentRequest?: string;
+ token?: any;
+}
+
+export interface CashuActions {
+ // Wallet operations
+ receive: (token: string | CashuToken) => Promise