From ad6e0c9f8dc3fc6db460311f7103ed322b9e7a3f Mon Sep 17 00:00:00 2001 From: lemonknowsall Date: Mon, 20 Oct 2025 23:42:16 -0700 Subject: [PATCH] Added simple functions instead of inline expressions for AI Agents --- src/components/wallet/MintModals.tsx | 9 +++- src/components/wallet/PaymentCard.tsx | 18 +++++-- src/components/wallet/WalletHeader.tsx | 67 ++++++++++++++++++++++---- 3 files changed, 79 insertions(+), 15 deletions(-) diff --git a/src/components/wallet/MintModals.tsx b/src/components/wallet/MintModals.tsx index 37c225c..da7dde8 100644 --- a/src/components/wallet/MintModals.tsx +++ b/src/components/wallet/MintModals.tsx @@ -6,6 +6,13 @@ import { QRModal } from '@/components/ui/qr-modal'; import { nip19 } from 'nostr-tools'; import { useToast } from '@/hooks/useToast'; +// Helper function to prevent complex template literals +const getLightningAddress = (userPubkey?: string, npubCashUserInfo?: { name?: string } | null): string => { + if (!userPubkey) return ''; + const username = npubCashUserInfo?.name || nip19.npubEncode(userPubkey); + return `${username}@npubx.cash`; +}; + interface ProofBreakdown { mintUrl: string; denominations: { [key: number]: number }; @@ -207,7 +214,7 @@ export function WalletModals({ 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` : ''} + content={getLightningAddress(userPubkey, npubCashUserInfo)} icon="zap" /> diff --git a/src/components/wallet/PaymentCard.tsx b/src/components/wallet/PaymentCard.tsx index 425b38a..5c16830 100644 --- a/src/components/wallet/PaymentCard.tsx +++ b/src/components/wallet/PaymentCard.tsx @@ -4,6 +4,19 @@ import { Slider } from '@/components/ui/slider'; import { Send, Download, ArrowRight, Zap, X } from 'lucide-react'; import { useState, useEffect } from 'react'; +// Helper function to prevent complex inline ternary operators +const getOperationMessage = (operation: string, mode: string): string => { + if (operation === 'send') { + return mode === 'tokens' + ? 'Select a mint to send tokens' + : 'Select a mint to pay Lightning invoices'; + } else { + return mode === 'tokens' + ? 'Select a mint to receive tokens' + : 'Select a mint to create Lightning invoice'; + } +}; + interface TransactionCardProps { mode: 'tokens' | 'lightning' | 'bitcoin'; operation: 'send' | 'receive'; @@ -199,10 +212,7 @@ export function TransactionCard({
{!activeMintUrl && mode !== 'bitcoin' && (
- {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') - } + {getOperationMessage(operation, mode)}
)} diff --git a/src/components/wallet/WalletHeader.tsx b/src/components/wallet/WalletHeader.tsx index cfd5b0f..51f8ad8 100644 --- a/src/components/wallet/WalletHeader.tsx +++ b/src/components/wallet/WalletHeader.tsx @@ -38,6 +38,57 @@ interface WalletHeaderProps { setDropdownOpen: (open: boolean) => void; } +// Helper functions to prevent syntax errors in complex expressions +// These functions break down complex inline logic to make the code more maintainable +// and less prone to syntax errors when AI agents edit this file +const formatBalance = (balance: number, showSats: boolean, btcUsdRate?: number | null): string => { + if (showSats) { + return balance.toLocaleString(); + } + + if (btcUsdRate) { + const usdAmount = (balance / 100000000 * btcUsdRate).toFixed(2); + return usdAmount; + } + + return balance.toLocaleString(); +}; + +const getBalanceSymbol = (showSats: boolean): string => { + return showSats ? '₿' : '$'; +}; + +const getToggleTitle = (showSats: boolean): string => { + return `Click to show in ${showSats ? 'USD' : 'sats'}`; +}; + +const getModeTitle = (mode: string): string => { + switch (mode) { + case 'tokens': return 'Cashu'; + case 'lightning': return 'Lightning'; + case 'bitcoin': return 'Bitcoin'; + default: return 'Unknown'; + } +}; + +const getModeDescription = (mode: string): string => { + switch (mode) { + case 'tokens': return 'Send and receive with Cashu eCash'; + case 'lightning': return 'Send and receive with Lightning'; + case 'bitcoin': return 'Send and receive with on-chain Bitcoin'; + default: return ''; + } +}; + +const getButtonTitle = (mode: string): string => { + switch (mode) { + case 'tokens': return 'Switch to Lightning'; + case 'lightning': return 'Switch to Bitcoin'; + case 'bitcoin': return 'Switch to Cashu Tokens'; + default: return 'Switch Mode'; + } +}; + export function WalletHeader({ totalBalance, balances, @@ -88,12 +139,8 @@ export function WalletHeader({ setMode(newMode); toast({ - title: `${newMode === 'tokens' ? 'Cashu' : newMode === 'lightning' ? 'Lightning' : 'Bitcoin'} Enabled!`, - description: newMode === 'tokens' - ? 'Send and receive with Cashu eCash' - : newMode === 'lightning' - ? 'Send and receive with Lightning' - : 'Send and receive with on-chain Bitcoin', + title: `${getModeTitle(newMode)} Enabled!`, + description: getModeDescription(newMode) }); }; @@ -105,7 +152,7 @@ export function WalletHeader({