From bea63c75aa0d0539704958537245446014b4eec5 Mon Sep 17 00:00:00 2001 From: lemonknowsall Date: Sat, 18 Oct 2025 00:22:50 -0700 Subject: [PATCH] transaction history drawer and separate mint display --- src/App.tsx | 2 +- src/components/WalletModal.tsx | 16 +- src/components/auth/LoginIcon.tsx | 2 +- src/components/wallet/ActionButtons.tsx | 6 +- src/components/wallet/BalanceDisplay.tsx | 111 +---------- src/components/wallet/CashuWallet.tsx | 145 +++++++++------ src/components/wallet/MintDisplay.tsx | 182 +++++++++++++++++++ src/components/wallet/ReceiveCard.tsx | 15 +- src/components/wallet/SendCard.tsx | 20 +- src/components/wallet/TransactionHistory.tsx | 127 ++++++------- 10 files changed, 348 insertions(+), 278 deletions(-) create mode 100644 src/components/wallet/MintDisplay.tsx diff --git a/src/App.tsx b/src/App.tsx index eb5704c..fe0eaf6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -31,7 +31,7 @@ const queryClient = new QueryClient({ }); const defaultConfig: AppConfig = { - theme: "light", + theme: "system", relayUrl: "wss://relay.primal.net", }; diff --git a/src/components/WalletModal.tsx b/src/components/WalletModal.tsx index 29ac146..49b4cd9 100644 --- a/src/components/WalletModal.tsx +++ b/src/components/WalletModal.tsx @@ -95,7 +95,7 @@ const WalletContent = forwardRef {/* Primary Payment Method - Cashu */}
-

Primary Payment Method

+

Primary Wallet

@@ -116,19 +116,13 @@ const WalletContent = forwardRef
-
- Cashu tokens are used first for Lightning zaps. Set up your Cashu wallet for instant payments. -
{/* Lightning Fallback Methods */}
-

Lightning Fallback Methods

-
- Used when Cashu balance is insufficient or unavailable -
+

Other Options

{/* WebLN */}
@@ -233,7 +227,7 @@ const WalletContent = forwardRef

- Set up your Cashu wallet for instant payments, or install a WebLN extension/connect NWC wallet for Lightning fallback. + Set up your Cashu wallet for instant payments, or install a WebLN extension/connect NWC wallet for Lightning

@@ -367,7 +361,7 @@ export function LightningWalletModal({ children, className }: LightningWalletMod Payment Settings - Manage Cashu wallet and Lightning fallback methods for zaps. + Manage wallet methods for zaps
@@ -423,7 +417,7 @@ export function LightningWalletModal({ children, className }: LightningWalletMod Payment Settings - Manage Cashu wallet and Lightning fallback methods for zaps. + Manage wallet methods for zaps diff --git a/src/components/auth/LoginIcon.tsx b/src/components/auth/LoginIcon.tsx index 5c0d918..c0bb030 100644 --- a/src/components/auth/LoginIcon.tsx +++ b/src/components/auth/LoginIcon.tsx @@ -31,7 +31,7 @@ export function LoginIcon() { className="h-8 w-8 p-0" title="Log in" > - + +
@@ -25,7 +25,7 @@ export function ActionButtons({ onSendClick, onReceiveClick, isLoading }: Action size="icon" onClick={onSendClick} disabled={isLoading} - className="h-20 w-20 rounded-full bg-muted border-2 shadow-lg hover:shadow-xl transition-all duration-200 hover:scale-105 [&_svg]:size-6" + className="h-20 w-20 rounded-full bg-muted transition-all duration-200 hover:scale-105 [&_svg]:size-6" > diff --git a/src/components/wallet/BalanceDisplay.tsx b/src/components/wallet/BalanceDisplay.tsx index 0677a21..310af0c 100644 --- a/src/components/wallet/BalanceDisplay.tsx +++ b/src/components/wallet/BalanceDisplay.tsx @@ -1,39 +1,18 @@ -import { Button } from '@/components/ui/button'; -import { Input } from '@/components/ui/input'; -import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; -import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; -import { Wallet, ChevronDown, Plus, X, QrCode, Copy, Check } from 'lucide-react'; +import { QrCode, Copy, Check } from 'lucide-react'; import { useState, useEffect } from 'react'; import { exchangeRateService } from '@/lib/exchangeRateService'; -interface CashuMint { - url: string; - name?: string; -} - interface BalanceDisplayProps { totalBalance: number; balances: { [key: string]: number }; showSats: boolean; setShowSats: (showSats: boolean) => void; - 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; // Lightning address props userPubkey?: string; npubCashUsername?: string; onCopyToClipboard: (text: string) => Promise; onShowLightningAddressQR: (qrCode: string) => void; generateQRCode: (text: string) => Promise; - // Dropdown state - mintDropdownOpen: boolean; - setMintDropdownOpen: (open: boolean) => void; } export function BalanceDisplay({ @@ -41,22 +20,11 @@ export function BalanceDisplay({ balances, showSats, setShowSats, - activeMintUrl, - setActiveMintUrl, - mints, - mintUrl, - setMintUrl, - onAddMint, - onRemoveMint, - onShowDenominations, - getCleanMintLabel, userPubkey, npubCashUsername, onCopyToClipboard, onShowLightningAddressQR, generateQRCode, - mintDropdownOpen, - setMintDropdownOpen, }: BalanceDisplayProps) { const [lightningAddressCopied, setLightningAddressCopied] = useState(false); const [btcUsdRate, setBtcUsdRate] = useState(null); @@ -84,7 +52,7 @@ export function BalanceDisplay({
- - {/* Active Mint Dropdown */} -
- {activeMintUrl && ( - - )} - - - - - - {mints.length === 0 && ( - No mints connected - )} - {mints - .filter((mint) => mint.url) - .map((mint, index) => ( - setActiveMintUrl(mint.url)} - > -
- {getCleanMintLabel(mint)} - - {convertCurrency(balances[mint.url] || 0, showSats)} - -
- -
- ))} - -
-
- setMintUrl(e.target.value)} - className="h-8" - /> - -
-
-
-
-
{/* Lightning Address */} {userPubkey && ( diff --git a/src/components/wallet/CashuWallet.tsx b/src/components/wallet/CashuWallet.tsx index dcc1bd8..e661421 100644 --- a/src/components/wallet/CashuWallet.tsx +++ b/src/components/wallet/CashuWallet.tsx @@ -12,6 +12,7 @@ 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 { Drawer, DrawerContent, DrawerHeader, DrawerTitle } from '@/components/ui/drawer'; @@ -21,6 +22,7 @@ import { TransactionHistory } from './TransactionHistory'; import { ProofBreakdownModal } from './ProofBreakdownModal'; import { RemoveMintModal } from './RemoveMintModal'; import { LoginIcon } from '@/components/auth/LoginIcon'; +import { ChevronUp } from 'lucide-react'; export function CashuWallet() { // ============================================================================ @@ -163,6 +165,7 @@ export function CashuWallet() { const [npubCashUserInfo, setNpubCashUserInfo] = useState(null); const [showSendModal, setShowSendModal] = useState(false); const [showReceiveModal, setShowReceiveModal] = useState(false); + const [showHistoryModal, setShowHistoryModal] = useState(false); // Ref to track if we've fetched npub.cash user info const hasCheckedNpubCashRef = useRef(false); @@ -277,7 +280,7 @@ export function CashuWallet() { return ( <> -
+
{/* Mode Toggle */}
@@ -289,60 +292,74 @@ export function CashuWallet() {
- {/* Balance Display */} - handleShowDenominations(mintUrl, setShowProofBreakdown, setProofBreakdown)} - getCleanMintLabel={getCleanMintLabel} - userPubkey={user?.pubkey} - npubCashUsername={user?.pubkey ? (npubCashUserInfo?.name || nip19.npubEncode(user.pubkey)) : undefined} - onCopyToClipboard={copyToClipboard} - onShowLightningAddressQR={(qr) => { - setLightningAddressQRCode(qr); - setShowLightningAddressQR(true); - }} - generateQRCode={generateQRCode} - mintDropdownOpen={mintDropdownOpen} - setMintDropdownOpen={setMintDropdownOpen} - /> - - {/* 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" + {/* Centered Balance and Mint Display */} +
+ {/* Balance Display */} + { + setLightningAddressQRCode(qr); + setShowLightningAddressQR(true); + }} + generateQRCode={generateQRCode} /> - )} - {/* Transaction History */} - + {/* 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 */} +
+ +
+
{/* Modals */} <> @@ -414,9 +431,9 @@ export function CashuWallet() { {/* Bottom Drawer Modals */} - + - + Send
- + - + Receive
+ + + + + Transactions + +
+ +
+
+
diff --git a/src/components/wallet/MintDisplay.tsx b/src/components/wallet/MintDisplay.tsx new file mode 100644 index 0000000..1de58b6 --- /dev/null +++ b/src/components/wallet/MintDisplay.tsx @@ -0,0 +1,182 @@ +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/ReceiveCard.tsx b/src/components/wallet/ReceiveCard.tsx index 7fc7a62..2e1f065 100644 --- a/src/components/wallet/ReceiveCard.tsx +++ b/src/components/wallet/ReceiveCard.tsx @@ -27,10 +27,7 @@ export function ReceiveCard({
{/* Title */}
-

- Receive -

-

+

{mode === 'tokens' ? 'Enter Cashu token to redeem' : 'Deposit funds with Lightning' @@ -58,14 +55,13 @@ export function ReceiveCard({ } }} disabled={!activeMintUrl} - autoFocus - className="w-full h-16 !text-xl text-center border-0 bg-transparent focus:ring-0 focus:ring-offset-0" + className="w-full h-16 !text-base text-center border bg-background focus:ring-2 focus:ring-ring focus:ring-offset-2" />

- - {/* Transactions List - Only shown when expanded */} - {isExpanded && ( -
- {isLoading ? ( -
- - Loading history... -
- ) : ( - <> - {entries.map((entry) => ( -
-
-
-
- {getTransactionTypeIcon(entry.type)} -
-
-
- - {getHistoryLabel(entry.type)} - -
-
- {new URL(entry.mintUrl).hostname} -
-
- {new Date(entry.createdAt).toLocaleString()} -
-
+
+ {isLoading ? ( +
+ + Loading history... +
+ ) : entries.length === 0 ? ( +
+ No transactions yet +
+ ) : ( + <> + {entries.map((entry) => ( +
+
+
+
+ {getTransactionTypeIcon(entry.type)} +
+
+
+ + {getHistoryLabel(entry.type)} +
-
-
-
- {entry.type === 'send' || entry.type === 'melt' ? '-' : '+'} - {entry.amount.toLocaleString()} {entry.unit} -
- {entry.type === 'melt' && ( -
- + fees -
- )} -
-
- {getDirectionIcon(entry.type)} -
+
+ {new URL(entry.mintUrl).hostname} +
+
+ {new Date(entry.createdAt).toLocaleString()}
- ))} - - )} -
+
+
+
+ {entry.type === 'send' || entry.type === 'melt' ? '-' : '+'} + {entry.amount.toLocaleString()} {entry.unit} +
+ {entry.type === 'melt' && ( +
+ + fees +
+ )} +
+
+ {getDirectionIcon(entry.type)} +
+
+
+
+ ))} + )}
);