mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 16:33:36 +00:00
Added simple functions instead of inline expressions for AI Agents
This commit is contained in:
1 parent
f909795887
commit
ad6e0c9f8d
3 files changed
+79
-15
No files matched your search
@@ -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"
|
||||
/>
|
||||
|
||||
|
||||
@@ -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({
|
||||
<div className="space-y-8">
|
||||
{!activeMintUrl && mode !== 'bitcoin' && (
|
||||
<div className="text-sm text-muted-foreground bg-muted p-3 rounded">
|
||||
{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)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -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({
|
||||
<button
|
||||
onClick={toggleMode}
|
||||
className="p-3 rounded-full bg-background hover:bg-background/80 transition-colors flex items-center justify-center"
|
||||
title={mode === 'tokens' ? 'Switch to Lightning' : mode === 'lightning' ? 'Switch to Bitcoin' : 'Switch to Cashu Tokens'}
|
||||
title={getButtonTitle(mode)}
|
||||
>
|
||||
{mode === 'tokens' ? (
|
||||
<Coins className="h-6 w-6" />
|
||||
@@ -128,12 +175,12 @@ export function WalletHeader({
|
||||
<button
|
||||
onClick={() => setShowSats(!showSats)}
|
||||
className="text-6xl font-bold tabular-nums hover:opacity-80 transition-opacity cursor-pointer"
|
||||
title={`Click to show in ${showSats ? 'USD' : 'sats'}`}
|
||||
title={getToggleTitle(showSats)}
|
||||
>
|
||||
<span className="text-muted-foreground italic">
|
||||
{showSats ? '₿' : '$'}
|
||||
{getBalanceSymbol(showSats)}
|
||||
</span>
|
||||
{showSats ? totalBalance.toLocaleString() : (btcUsdRate ? `${(totalBalance / 100000000 * btcUsdRate).toFixed(2)}` : totalBalance.toLocaleString())}
|
||||
{formatBalance(totalBalance, showSats, btcUsdRate)}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user