mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-03 08:07:21 +00:00
header spacing and styling
This commit is contained in:
1 parent
bea63c75aa
commit
6d35028424
14 files changed
+1016
-955
No files matched your search
@@ -301,7 +301,7 @@ const SignupDialog: React.FC<SignupDialogProps> = ({ isOpen, onClose, onComplete
|
||||
{getTitle()}
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className='px-6 pt-2 pb-4 space-y-4 overflow-y-scroll flex-1'>
|
||||
<div className='px-6 pt-2 pb-4 space-y-4 flex-1'>
|
||||
{/* Welcome Step - New engaging introduction */}
|
||||
{step === 'welcome' && (
|
||||
<div className='text-center space-y-4'>
|
||||
|
||||
@@ -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 (
|
||||
<div className="flex gap-20 justify-center py-8">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={onReceiveClick}
|
||||
disabled={isLoading}
|
||||
className="h-20 w-20 rounded-full bg-muted transition-all duration-200 hover:scale-105 [&_svg]:size-6"
|
||||
>
|
||||
<Download className="h-12 w-12" />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={onSendClick}
|
||||
disabled={isLoading}
|
||||
className="h-20 w-20 rounded-full bg-muted transition-all duration-200 hover:scale-105 [&_svg]:size-6"
|
||||
>
|
||||
<Send className="h-12 w-12" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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<void>;
|
||||
onShowLightningAddressQR: (qrCode: string) => void;
|
||||
generateQRCode: (text: string) => Promise<string>;
|
||||
}
|
||||
|
||||
export function BalanceDisplay({
|
||||
totalBalance,
|
||||
balances,
|
||||
showSats,
|
||||
setShowSats,
|
||||
userPubkey,
|
||||
npubCashUsername,
|
||||
onCopyToClipboard,
|
||||
onShowLightningAddressQR,
|
||||
generateQRCode,
|
||||
}: BalanceDisplayProps) {
|
||||
const [lightningAddressCopied, setLightningAddressCopied] = useState(false);
|
||||
const [btcUsdRate, setBtcUsdRate] = useState<number | null>(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 (
|
||||
<div className="text-center py-2">
|
||||
<div className="flex items-center justify-center gap-3">
|
||||
<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'}`}
|
||||
>
|
||||
<span className="text-muted-foreground italic">
|
||||
{showSats ? '₿' : '$'}
|
||||
</span>
|
||||
{showSats ? totalBalance.toLocaleString() : (btcUsdRate ? `${(totalBalance / 100000000 * btcUsdRate).toFixed(2)}` : totalBalance.toLocaleString())}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Lightning Address */}
|
||||
{userPubkey && (
|
||||
<div className="mt-3 flex items-center justify-center gap-2">
|
||||
<button
|
||||
onClick={async () => {
|
||||
const lightningAddress = `${npubCashUsername}@npubx.cash`;
|
||||
await onCopyToClipboard(lightningAddress);
|
||||
setLightningAddressCopied(true);
|
||||
setTimeout(() => setLightningAddressCopied(false), 2000);
|
||||
}}
|
||||
className="flex items-center gap-2 px-3 py-1.5 bg-muted hover:bg-muted/80 rounded-md border text-base font-mono transition-colors h-[34px]"
|
||||
title="Click to copy Lightning address"
|
||||
>
|
||||
<span className="truncate max-w-[250px] sm:max-w-none">
|
||||
{(() => {
|
||||
const lightningAddress = `${npubCashUsername}@npubx.cash`;
|
||||
return lightningAddress.length > 33
|
||||
? `${lightningAddress.substring(0, 15)}...${lightningAddress.substring(lightningAddress.length - 15)}`
|
||||
: lightningAddress;
|
||||
})()}
|
||||
</span>
|
||||
{lightningAddressCopied ? (
|
||||
<Check className="h-4 w-4 text-green-600 flex-shrink-0" />
|
||||
) : (
|
||||
<Copy className="h-4 w-4 text-muted-foreground flex-shrink-0" />
|
||||
)}
|
||||
</button>
|
||||
<button
|
||||
onClick={async () => {
|
||||
const lightningAddress = `${npubCashUsername}@npubx.cash`;
|
||||
const qr = await generateQRCode(lightningAddress);
|
||||
onShowLightningAddressQR(qr);
|
||||
}}
|
||||
className="flex items-center justify-center px-2 py-1.5 hover:bg-muted rounded-md transition-colors h-[34px]"
|
||||
title="Show QR Code"
|
||||
>
|
||||
<QrCode className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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() {
|
||||
<>
|
||||
<div className="max-w-4xl mx-auto pt-16 pb-32 px-3 sm:px-4 relative">
|
||||
|
||||
{/* Mode Toggle */}
|
||||
<div className="absolute top-3 left-3 sm:left-4 z-10">
|
||||
<ModeToggle mode={mode} setMode={setMode} />
|
||||
</div>
|
||||
|
||||
{/* Login Icon */}
|
||||
<div className="absolute top-3 right-3 sm:right-4 z-10">
|
||||
<LoginIcon />
|
||||
</div>
|
||||
|
||||
{/* Centered Balance and Mint Display */}
|
||||
<div className="flex flex-col items-center pt-10 space-y-2">
|
||||
{/* Balance Display */}
|
||||
<BalanceDisplay
|
||||
totalBalance={totalBalance}
|
||||
balances={balances}
|
||||
showSats={showSats}
|
||||
setShowSats={setShowSats}
|
||||
userPubkey={user?.pubkey}
|
||||
npubCashUsername={user?.pubkey ? (npubCashUserInfo?.name || nip19.npubEncode(user.pubkey)) : undefined}
|
||||
onCopyToClipboard={copyToClipboard}
|
||||
onShowLightningAddressQR={(qr) => {
|
||||
setLightningAddressQRCode(qr);
|
||||
setShowLightningAddressQR(true);
|
||||
}}
|
||||
generateQRCode={generateQRCode}
|
||||
/>
|
||||
{/* Wallet Header (includes mode toggle, login icon, balance, lightning address, and mint selector) */}
|
||||
<WalletHeader
|
||||
totalBalance={totalBalance}
|
||||
balances={balances}
|
||||
showSats={showSats}
|
||||
setShowSats={setShowSats}
|
||||
mode={mode}
|
||||
setMode={setMode}
|
||||
userPubkey={user?.pubkey}
|
||||
npubCashUsername={user?.pubkey ? (npubCashUserInfo?.name || nip19.npubEncode(user.pubkey)) : undefined}
|
||||
onCopyToClipboard={copyToClipboard}
|
||||
onShowLightningAddressQR={(qr) => {
|
||||
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 */}
|
||||
<MintDisplay
|
||||
balances={balances}
|
||||
showSats={showSats}
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Action Buttons and Transaction History Container */}
|
||||
<div className="fixed bottom-0 left-0 right-0 pb-8 pb-safe">
|
||||
{/* Action Buttons */}
|
||||
<ActionButtons
|
||||
onSendClick={() => setShowSendModal(true)}
|
||||
onReceiveClick={() => setShowReceiveModal(true)}
|
||||
isLoading={isLoading || isNpubCashLoading}
|
||||
/>
|
||||
|
||||
{/* Sent Token Display */}
|
||||
{sentToken && (
|
||||
<QRModal
|
||||
isOpen={!!sentToken}
|
||||
onClose={() => setSentToken(null)}
|
||||
title="Cashu Token"
|
||||
description="Share this token with the recipient to send them your sats"
|
||||
qrCodeUrl={sentTokenQRCode}
|
||||
content={sentToken}
|
||||
icon="qr"
|
||||
/>
|
||||
)}
|
||||
<div className="flex gap-20 justify-center py-8">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => setShowReceiveModal(true)}
|
||||
disabled={isLoading || isNpubCashLoading}
|
||||
className="h-20 w-20 rounded-full bg-muted transition-all duration-200 hover:scale-105 [&_svg]:size-6"
|
||||
>
|
||||
<Download className="h-12 w-12" />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => setShowSendModal(true)}
|
||||
disabled={isLoading || isNpubCashLoading}
|
||||
className="h-20 w-20 rounded-full bg-muted transition-all duration-200 hover:scale-105 [&_svg]:size-6"
|
||||
>
|
||||
<Send className="h-12 w-12" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Transaction History Button */}
|
||||
<div className="max-w-4xl mx-auto">
|
||||
@@ -363,70 +347,30 @@ export function CashuWallet() {
|
||||
|
||||
{/* Modals */}
|
||||
<>
|
||||
<ProofBreakdownModal
|
||||
isOpen={showProofBreakdown}
|
||||
onClose={() => setShowProofBreakdown(false)}
|
||||
breakdown={proofBreakdown}
|
||||
/>
|
||||
|
||||
<QRModal
|
||||
isOpen={showLightningQR}
|
||||
onClose={() => setShowLightningQR(false)}
|
||||
title="Lightning Address QR Code"
|
||||
description="Scan to send Lightning payments"
|
||||
qrCodeUrl={lightningQRCode}
|
||||
content={''}
|
||||
icon="qr"
|
||||
/>
|
||||
|
||||
<QRModal
|
||||
isOpen={showLightningAddressQR}
|
||||
onClose={() => 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 && (
|
||||
<QRModal
|
||||
isOpen={showInvoiceModal}
|
||||
onClose={() => {
|
||||
// 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}
|
||||
/>
|
||||
)}
|
||||
|
||||
<RemoveMintModal
|
||||
isOpen={showRemoveMintModal}
|
||||
onClose={() => setShowRemoveMintModal(false)}
|
||||
mint={mintToRemove}
|
||||
onConfirm={handleConfirmRemoveMint}
|
||||
<WalletModals
|
||||
showProofBreakdown={showProofBreakdown}
|
||||
setShowProofBreakdown={setShowProofBreakdown}
|
||||
proofBreakdown={proofBreakdown}
|
||||
showRemoveMintModal={showRemoveMintModal}
|
||||
setShowRemoveMintModal={setShowRemoveMintModal}
|
||||
mintToRemove={mintToRemove}
|
||||
onConfirmRemoveMint={handleConfirmRemoveMint}
|
||||
isLoading={isLoading || isNpubCashLoading}
|
||||
showLightningQR={showLightningQR}
|
||||
setShowLightningQR={setShowLightningQR}
|
||||
lightningQRCode={lightningQRCode}
|
||||
showLightningAddressQR={showLightningAddressQR}
|
||||
setShowLightningAddressQR={setShowLightningAddressQR}
|
||||
lightningAddressQRCode={lightningAddressQRCode}
|
||||
userPubkey={user?.pubkey}
|
||||
npubCashUserInfo={npubCashUserInfo}
|
||||
currentInvoice={currentInvoice}
|
||||
showInvoiceModal={showInvoiceModal}
|
||||
setShowInvoiceModal={setShowInvoiceModal}
|
||||
mintQuoteUnsubscribeRef={mintQuoteUnsubscribeRef}
|
||||
sentToken={sentToken}
|
||||
setSentToken={setSentToken}
|
||||
sentTokenQRCode={sentTokenQRCode}
|
||||
/>
|
||||
|
||||
{/* Bottom Drawer Modals */}
|
||||
@@ -436,8 +380,9 @@ export function CashuWallet() {
|
||||
<DrawerTitle className="text-center text-3xl font-bold">Send</DrawerTitle>
|
||||
</DrawerHeader>
|
||||
<div className="px-4 pb-4">
|
||||
<SendCard
|
||||
<TransactionCard
|
||||
mode={mode}
|
||||
operation="send"
|
||||
sendAmount={sendAmount}
|
||||
setSendAmount={setSendAmount}
|
||||
lightningInvoice={lightningInvoice}
|
||||
@@ -448,16 +393,19 @@ export function CashuWallet() {
|
||||
setLightningAddressAmount={setLightningAddressAmount}
|
||||
pendingLightningAddress={pendingLightningAddress}
|
||||
setPendingLightningAddress={setPendingLightningAddress}
|
||||
tokenInput=""
|
||||
setTokenInput={() => {}}
|
||||
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() {
|
||||
<DrawerTitle className="text-center text-3xl font-bold">Receive</DrawerTitle>
|
||||
</DrawerHeader>
|
||||
<div className="px-4 pb-4">
|
||||
<ReceiveCard
|
||||
<TransactionCard
|
||||
mode={mode}
|
||||
operation="receive"
|
||||
sendAmount=""
|
||||
setSendAmount={() => {}}
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
@@ -493,12 +454,12 @@ export function CashuWallet() {
|
||||
<DrawerHeader>
|
||||
<DrawerTitle className="text-center text-3xl font-bold">Transactions</DrawerTitle>
|
||||
</DrawerHeader>
|
||||
<div className="px-4 pb-4 overflow-y-auto flex-1">
|
||||
<ScrollArea className="h-[90vh] px-4 pb-4">
|
||||
<TransactionHistory
|
||||
entries={historyEntries}
|
||||
isLoading={isLoadingHistory}
|
||||
/>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</DrawerContent>
|
||||
</Drawer>
|
||||
</>
|
||||
|
||||
@@ -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<number | null>(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 (
|
||||
<div className="w-full max-w-[400px] mx-auto space-y-4">
|
||||
{/* Mint Selector Dropdown */}
|
||||
<div>
|
||||
<DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" className="w-full justify-between rounded-full bg-muted hover:bg-muted/80 border-muted text-base">
|
||||
<div className="flex items-center justify-between w-full">
|
||||
{activeMint ? (
|
||||
<>
|
||||
<div className="flex items-center gap-2 min-w-0 flex-1">
|
||||
<Check className="h-5 w-5 text-primary flex-shrink-0" />
|
||||
<span className="truncate font-medium">{getCleanMintLabel(activeMint)}</span>
|
||||
</div>
|
||||
<span className="text-muted-foreground font-medium">
|
||||
{convertCurrency(activeBalance, showSats)}
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="text-muted-foreground">Select a mint</span>
|
||||
)}
|
||||
</div>
|
||||
<ChevronDown className="h-5 w-5 ml-2" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-[var(--radix-dropdown-menu-trigger-width)] bg-muted border-muted">
|
||||
{mints
|
||||
.filter((mint) => mint.url)
|
||||
.map((mint, index) => {
|
||||
const isActive = activeMintUrl === mint.url;
|
||||
const balance = balances[mint.url] || 0;
|
||||
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={`mint-${mint.url || `unknown-${index}`}`}
|
||||
onClick={() => setActiveMintUrl(mint.url)}
|
||||
className="flex items-center justify-between p-3 text-base"
|
||||
>
|
||||
<div className="flex items-center gap-3 flex-1 min-w-0">
|
||||
{isActive && (
|
||||
<div className="flex-shrink-0">
|
||||
<Check className="h-5 w-5 text-primary" />
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="font-medium truncate">
|
||||
{getCleanMintLabel(mint)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
<span className="px-3 py-1 text-sm font-medium text-muted-foreground">
|
||||
{convertCurrency(balance, showSats)}
|
||||
</span>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onRemoveMint(mint);
|
||||
}}
|
||||
className="p-1 rounded hover:bg-destructive hover:text-destructive-foreground transition-colors"
|
||||
title="Remove mint"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
{mints.length > 0 && <DropdownMenuSeparator />}
|
||||
<DropdownMenuItem asChild>
|
||||
<div className="flex gap-2 p-2">
|
||||
<Input
|
||||
placeholder="mint.example.com"
|
||||
value={mintUrl}
|
||||
onChange={(e) => 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()}
|
||||
/>
|
||||
<Button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onAddMint();
|
||||
}}
|
||||
disabled={!mintUrl.trim()}
|
||||
size="sm"
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1" />
|
||||
Add
|
||||
</Button>
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 && (
|
||||
<div
|
||||
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
|
||||
onClick={() => setShowProofBreakdown(false)}
|
||||
>
|
||||
<Card
|
||||
className="w-full max-w-md border-0 shadow-lg bg-background"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<CardHeader className="relative">
|
||||
<Button
|
||||
onClick={() => setShowProofBreakdown(false)}
|
||||
className="absolute top-2 right-2"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
<CardTitle className="flex items-center pr-8">
|
||||
<Coins className="h-5 w-5 mr-2" />
|
||||
Token Breakdown
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{new URL(proofBreakdown.mintUrl).hostname}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="text-center py-2">
|
||||
<div className="text-2xl font-bold text-primary">
|
||||
{proofBreakdown.totalBalance.toLocaleString()} sats
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">Total Balance</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="text-sm font-medium text-muted-foreground">Denominations:</div>
|
||||
{Object.entries(proofBreakdown.denominations)
|
||||
.sort(([a], [b]) => parseInt(a) - parseInt(b))
|
||||
.map(([amount, count]) => (
|
||||
<div key={amount} className="flex items-center justify-between p-2 bg-muted/30 rounded">
|
||||
<div className="flex items-center gap-2">
|
||||
<Coins className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="font-medium">{parseInt(amount).toLocaleString()} sats</span>
|
||||
</div>
|
||||
<Badge variant="secondary" className="bg-primary/10 text-primary">
|
||||
× {count}
|
||||
</Badge>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="text-xs text-muted-foreground bg-muted/30 p-3 rounded">
|
||||
💡 Tip: If you can't pay an invoice, try sending tokens to yourself to get different denominations.
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Remove Mint Modal */}
|
||||
{showRemoveMintModal && mintToRemove && (
|
||||
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-[100] p-4">
|
||||
<Card className="w-full max-w-md border-0 shadow-lg bg-background">
|
||||
<CardHeader className="relative">
|
||||
<Button
|
||||
onClick={() => setShowRemoveMintModal(false)}
|
||||
className="absolute top-2 right-2"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
<CardTitle className="flex items-center pr-8">
|
||||
<AlertTriangle className="h-5 w-5 mr-2 text-destructive" />
|
||||
Remove Mint
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Are you sure you want to remove this mint from your wallet?
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="bg-muted p-4 rounded-lg border">
|
||||
<div className="font-medium">{mintToRemove.name || new URL(mintToRemove.url).hostname}</div>
|
||||
</div>
|
||||
|
||||
<div className="text-sm text-muted-foreground bg-muted/30 p-3 rounded space-y-2">
|
||||
<div>⚠️ This will remove the mint and all associated data. Any tokens from this mint will no longer be accessible.</div>
|
||||
<div>💡 You can always add this mint back later if needed.</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 justify-end">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={() => setShowRemoveMintModal(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={onConfirmRemoveMint}
|
||||
disabled={isLoading}
|
||||
>
|
||||
{isLoading ? (
|
||||
<>
|
||||
<RefreshCw className="h-4 w-4 mr-2 animate-spin" />
|
||||
Removing...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<X className="h-4 w-4 mr-2" />
|
||||
Remove Mint
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* QR Modals */}
|
||||
<QRModal
|
||||
isOpen={showLightningQR}
|
||||
onClose={() => setShowLightningQR(false)}
|
||||
title="Lightning Address QR Code"
|
||||
description="Scan to send Lightning payments"
|
||||
qrCodeUrl={lightningQRCode}
|
||||
content={''}
|
||||
icon="qr"
|
||||
/>
|
||||
|
||||
<QRModal
|
||||
isOpen={showLightningAddressQR}
|
||||
onClose={() => 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 && (
|
||||
<QRModal
|
||||
isOpen={showInvoiceModal}
|
||||
onClose={() => {
|
||||
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 && (
|
||||
<QRModal
|
||||
isOpen={!!sentToken}
|
||||
onClose={() => setSentToken(null)}
|
||||
title="Cashu Token"
|
||||
description="Share this token with the recipient to send them your sats"
|
||||
qrCodeUrl={sentTokenQRCode}
|
||||
content={sentToken}
|
||||
icon="qr"
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -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<number | null>(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 (
|
||||
<div className="flex gap-2 items-center min-w-0">
|
||||
<DropdownMenu open={dropdownOpen} onOpenChange={setDropdownOpen}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" className="justify-between rounded-full bg-muted hover:bg-muted/80 border text-base flex-1 h-[40px] px-3 min-w-0">
|
||||
<div className="flex items-center justify-between w-full min-w-0">
|
||||
{activeMint ? (
|
||||
<>
|
||||
<div className="flex items-center gap-2 min-w-0 flex-1">
|
||||
<Check className="h-5 w-5 text-primary flex-shrink-0" />
|
||||
<span className="truncate font-medium min-w-0 flex-1">{getCleanMintLabel(activeMint)}</span>
|
||||
</div>
|
||||
<span className="text-muted-foreground font-medium flex-shrink-0 ml-2">
|
||||
{formatBalance(activeBalance)}
|
||||
</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="text-muted-foreground truncate min-w-0 flex-1">Select a mint</span>
|
||||
)}
|
||||
</div>
|
||||
<ChevronDown className="h-5 w-5 ml-2 flex-shrink-0" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="w-[var(--radix-dropdown-menu-trigger-width)] bg-muted border shadow-none">
|
||||
{mints
|
||||
.filter((mint) => mint.url)
|
||||
.map((mint, index) => {
|
||||
const isActive = activeMintUrl === mint.url;
|
||||
const balance = balances[mint.url] || 0;
|
||||
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={`mint-${mint.url || `unknown-${index}`}`}
|
||||
onClick={() => setActiveMintUrl(mint.url)}
|
||||
className="flex items-center justify-between p-3 text-base"
|
||||
>
|
||||
<div className="flex items-center gap-3 flex-1 min-w-0">
|
||||
{isActive && (
|
||||
<div className="flex-shrink-0">
|
||||
<Check className="h-5 w-5 text-primary" />
|
||||
</div>
|
||||
)}
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="font-medium truncate">
|
||||
{getCleanMintLabel(mint)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
<span className="px-3 py-1 text-sm font-medium text-muted-foreground">
|
||||
{formatBalance(balance)}
|
||||
</span>
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onRemoveMint(mint);
|
||||
}}
|
||||
className="p-1 rounded hover:bg-destructive hover:text-destructive-foreground transition-colors"
|
||||
title="Remove mint"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
{mints.length > 0 && <DropdownMenuSeparator />}
|
||||
<DropdownMenuItem asChild>
|
||||
<div className="flex gap-2 p-2">
|
||||
<Input
|
||||
placeholder="mint.example.com"
|
||||
value={mintUrl}
|
||||
onChange={(e) => 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()}
|
||||
/>
|
||||
<Button
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onAddMint();
|
||||
}}
|
||||
disabled={!mintUrl.trim()}
|
||||
size="sm"
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-1" />
|
||||
Add
|
||||
</Button>
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{activeMint && (
|
||||
<div className="flex flex-col gap-1">
|
||||
<button
|
||||
onClick={() => onShowDenominations(activeMint.url)}
|
||||
className="flex items-center justify-center px-2 py-1.5 hover:bg-muted rounded-md transition-colors h-[40px] w-[42px] flex-shrink-0"
|
||||
title="View token breakdown"
|
||||
>
|
||||
<Wallet className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<button
|
||||
onClick={toggleMode}
|
||||
className="px-3 py-2 rounded-lg bg-background hover:bg-background/80 transition-colors flex items-center justify-center"
|
||||
title={mode === 'tokens' ? 'Switch to Lightning' : 'Switch to Cashu Tokens'}
|
||||
>
|
||||
{mode === 'tokens' ? (
|
||||
<Coins className="h-6 w-6" />
|
||||
) : (
|
||||
<Zap className="h-6 w-6" />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="space-y-8">
|
||||
{/* Title */}
|
||||
<div className="text-center">
|
||||
<p className="text-base text-muted-foreground mt-2">
|
||||
{operation === 'send' ? (
|
||||
mode === 'tokens'
|
||||
? 'Generate Cashu token to send'
|
||||
: pendingLightningAddress ? (
|
||||
<span className="inline-block px-3 py-1.5 bg-primary/10 border border-primary/20 rounded-md">
|
||||
<span className="font-bold text-primary">Sending to:</span>{' '}
|
||||
<span className="font-semibold text-foreground">{pendingLightningAddress}</span>
|
||||
</span>
|
||||
) : 'Pay invoices or addresses'
|
||||
) : (
|
||||
mode === 'tokens'
|
||||
? 'Enter Cashu token to redeem'
|
||||
: 'Deposit funds with Lightning'
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="space-y-4">
|
||||
{!activeMintUrl && (
|
||||
<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')
|
||||
}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{operation === 'send' ? (
|
||||
// Send Mode
|
||||
mode === 'tokens' ? (
|
||||
// Cashu Token Send
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
placeholder="Amount (sats)"
|
||||
type="number"
|
||||
value={sendAmount}
|
||||
onChange={(e) => 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]"
|
||||
/>
|
||||
<div className="flex justify-center mt-4">
|
||||
<Button
|
||||
onClick={onSend}
|
||||
disabled={!sendAmount || !activeMintUrl || isLoading}
|
||||
className="h-12 px-12 rounded-full"
|
||||
size="lg"
|
||||
>
|
||||
<Send className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : pendingLightningAddress ? (
|
||||
// Lightning Address Amount Input
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
placeholder="Amount (sats)"
|
||||
type="number"
|
||||
value={lightningAddressAmount}
|
||||
onChange={(e) => 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]"
|
||||
/>
|
||||
<div className="flex justify-center gap-2 mt-4">
|
||||
<Button
|
||||
onClick={onSend}
|
||||
disabled={!lightningAddressAmount || !activeMintUrl || isResolvingAddress || isLoading}
|
||||
className="h-12 px-12 rounded-full"
|
||||
size="lg"
|
||||
>
|
||||
{isResolvingAddress ? (
|
||||
<Loader2 className="h-5 w-5 animate-spin" />
|
||||
) : (
|
||||
<Zap className="h-5 w-5" />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => {
|
||||
setPendingLightningAddress(null);
|
||||
setLightningAddressAmount('');
|
||||
}}
|
||||
className="h-12 w-12 rounded-full"
|
||||
title="Cancel"
|
||||
>
|
||||
<X className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
// Lightning Invoice/Address Input
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
placeholder="lnbc... or [email protected]"
|
||||
value={lightningInvoice || lightningAddressInput}
|
||||
onChange={(e) => {
|
||||
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"
|
||||
/>
|
||||
<div className="flex justify-center mt-4">
|
||||
<Button
|
||||
onClick={onSend}
|
||||
disabled={(!lightningInvoice.trim() && !lightningAddressInput.trim()) || !activeMintUrl || isLoading}
|
||||
className="h-12 px-12 rounded-full"
|
||||
size="lg"
|
||||
>
|
||||
<Zap className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
// Receive Mode
|
||||
mode === 'tokens' ? (
|
||||
// Cashu Token Receive
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
placeholder="cashuBo2Ft..."
|
||||
value={tokenInput}
|
||||
onChange={(e) => 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"
|
||||
/>
|
||||
<div className="flex justify-center mt-4">
|
||||
<Button
|
||||
onClick={onReceive}
|
||||
disabled={!tokenInput.trim() || !activeMintUrl || isLoading}
|
||||
className="h-12 px-12 rounded-full"
|
||||
size="lg"
|
||||
>
|
||||
<Download className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
// Lightning Invoice Receive
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
placeholder="Amount (sats)"
|
||||
type="number"
|
||||
value={quoteAmount}
|
||||
onChange={(e) => 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]"
|
||||
/>
|
||||
<div className="flex justify-center mt-4">
|
||||
<Button
|
||||
onClick={onReceive}
|
||||
disabled={!quoteAmount || !activeMintUrl || isLoading}
|
||||
className="h-12 px-12 rounded-full"
|
||||
size="lg"
|
||||
>
|
||||
<Zap className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<div
|
||||
className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4"
|
||||
onClick={onClose}
|
||||
>
|
||||
<Card
|
||||
className="w-full max-w-md border-0 shadow-lg bg-background"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<CardHeader className="relative">
|
||||
<Button
|
||||
onClick={onClose}
|
||||
className="absolute top-2 right-2"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
<CardTitle className="flex items-center pr-8">
|
||||
<Coins className="h-5 w-5 mr-2" />
|
||||
Token Breakdown
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
{new URL(breakdown.mintUrl).hostname}
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="text-center py-2">
|
||||
<div className="text-2xl font-bold text-primary">
|
||||
{breakdown.totalBalance.toLocaleString()} sats
|
||||
</div>
|
||||
<div className="text-sm text-muted-foreground">Total Balance</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="text-sm font-medium text-muted-foreground">Denominations:</div>
|
||||
{Object.entries(breakdown.denominations)
|
||||
.sort(([a], [b]) => parseInt(a) - parseInt(b))
|
||||
.map(([amount, count]) => (
|
||||
<div key={amount} className="flex items-center justify-between p-2 bg-muted/30 rounded">
|
||||
<div className="flex items-center gap-2">
|
||||
<Coins className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="font-medium">{parseInt(amount).toLocaleString()} sats</span>
|
||||
</div>
|
||||
<Badge variant="secondary" className="bg-primary/10 text-primary">
|
||||
× {count}
|
||||
</Badge>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="text-xs text-muted-foreground bg-muted/30 p-3 rounded">
|
||||
💡 Tip: If you can't pay an invoice, try sending tokens to yourself to get different denominations.
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="space-y-8">
|
||||
{/* Title */}
|
||||
<div className="text-center">
|
||||
<p className="text-base text-muted-foreground mt-2">
|
||||
{mode === 'tokens'
|
||||
? 'Enter Cashu token to redeem'
|
||||
: 'Deposit funds with Lightning'
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="space-y-4">
|
||||
{mode === 'tokens' ? (
|
||||
<>
|
||||
{!activeMintUrl && (
|
||||
<div className="text-sm text-muted-foreground bg-muted p-3 rounded">
|
||||
Select a mint to receive tokens
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
placeholder="cashuBo2Ft..."
|
||||
value={tokenInput}
|
||||
onChange={(e) => 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"
|
||||
/>
|
||||
<div className="flex justify-center mt-4">
|
||||
<Button
|
||||
onClick={onReceive}
|
||||
disabled={!tokenInput.trim() || !activeMintUrl || isLoading}
|
||||
className="h-12 px-12 rounded-full"
|
||||
size="lg"
|
||||
>
|
||||
<Download className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{!activeMintUrl && (
|
||||
<div className="text-sm text-muted-foreground bg-muted p-3 rounded">
|
||||
Select a mint to create Lightning invoice
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
placeholder="Amount (sats)"
|
||||
type="number"
|
||||
value={quoteAmount}
|
||||
onChange={(e) => 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]"
|
||||
/>
|
||||
<div className="flex justify-center mt-4">
|
||||
<Button
|
||||
onClick={onReceive}
|
||||
disabled={!quoteAmount || !activeMintUrl || isLoading}
|
||||
className="h-12 px-12 rounded-full"
|
||||
size="lg"
|
||||
>
|
||||
<Zap className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="fixed inset-0 bg-black/50 flex items-center justify-center z-[100] p-4">
|
||||
<Card className="w-full max-w-md border-0 shadow-lg bg-background">
|
||||
<CardHeader className="relative">
|
||||
<Button
|
||||
onClick={onClose}
|
||||
className="absolute top-2 right-2"
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
<CardTitle className="flex items-center pr-8">
|
||||
<AlertTriangle className="h-5 w-5 mr-2 text-destructive" />
|
||||
Remove Mint
|
||||
</CardTitle>
|
||||
<CardDescription>
|
||||
Are you sure you want to remove this mint from your wallet?
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="bg-muted p-4 rounded-lg border">
|
||||
<div className="font-medium">{mint.name || new URL(mint.url).hostname}</div>
|
||||
</div>
|
||||
|
||||
<div className="text-sm text-muted-foreground bg-muted/30 p-3 rounded space-y-2">
|
||||
<div>⚠️ This will remove the mint and all associated data. Any tokens from this mint will no longer be accessible.</div>
|
||||
<div>💡 You can always add this mint back later if needed.</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 justify-end">
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={onClose}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
onClick={onConfirm}
|
||||
disabled={isLoading}
|
||||
>
|
||||
{isLoading ? (
|
||||
<>
|
||||
<RefreshCw className="h-4 w-4 mr-2 animate-spin" />
|
||||
Removing...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<X className="h-4 w-4 mr-2" />
|
||||
Remove Mint
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<div className="space-y-8">
|
||||
{/* Title */}
|
||||
<div className="text-center">
|
||||
<p className="text-base text-muted-foreground mt-2">
|
||||
{mode === 'tokens'
|
||||
? 'Generate Cashu token to send'
|
||||
: pendingLightningAddress
|
||||
? (
|
||||
<span className="inline-block px-3 py-1.5 bg-primary/10 border border-primary/20 rounded-md">
|
||||
<span className="font-bold text-primary">Sending to:</span>{' '}
|
||||
<span className="font-semibold text-foreground">{pendingLightningAddress}</span>
|
||||
</span>
|
||||
)
|
||||
: 'Pay invoices or addresses'
|
||||
}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="space-y-4">
|
||||
{mode === 'tokens' ? (
|
||||
<>
|
||||
{!activeMintUrl && (
|
||||
<div className="text-sm text-muted-foreground bg-muted p-3 rounded">
|
||||
Select a mint to send tokens
|
||||
</div>
|
||||
)}
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
placeholder="Amount (sats)"
|
||||
type="number"
|
||||
value={sendAmount}
|
||||
onChange={(e) => 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]"
|
||||
/>
|
||||
<div className="flex justify-center mt-4">
|
||||
<Button
|
||||
onClick={onSend}
|
||||
disabled={!sendAmount || !activeMintUrl || isLoading}
|
||||
className="h-12 px-12 rounded-full"
|
||||
size="lg"
|
||||
>
|
||||
<Send className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{!activeMintUrl && (
|
||||
<div className="text-sm text-muted-foreground bg-muted p-3 rounded">
|
||||
Select a mint to pay Lightning invoices
|
||||
</div>
|
||||
)}
|
||||
{pendingLightningAddress ? (
|
||||
// Step 2: Show amount input for Lightning address
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
placeholder="Amount (sats)"
|
||||
type="number"
|
||||
value={lightningAddressAmount}
|
||||
onChange={(e) => 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]"
|
||||
/>
|
||||
<div className="flex justify-center gap-2 mt-4">
|
||||
<Button
|
||||
onClick={onSend}
|
||||
disabled={!lightningAddressAmount || !activeMintUrl || isResolvingAddress || isLoading}
|
||||
className="h-12 px-12 rounded-full"
|
||||
size="lg"
|
||||
>
|
||||
{isResolvingAddress ? (
|
||||
<Loader2 className="h-5 w-5 animate-spin" />
|
||||
) : (
|
||||
<Zap className="h-5 w-5" />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => {
|
||||
setPendingLightningAddress(null);
|
||||
setLightningAddressAmount('');
|
||||
}}
|
||||
className="h-12 w-12 rounded-full"
|
||||
title="Cancel"
|
||||
>
|
||||
<X className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
// Step 1: Show invoice/address input
|
||||
<div className="space-y-3">
|
||||
<Input
|
||||
placeholder="lnbc... or [email protected]"
|
||||
value={lightningInvoice || lightningAddressInput}
|
||||
onChange={(e) => {
|
||||
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"
|
||||
/>
|
||||
<div className="flex justify-center mt-4">
|
||||
<Button
|
||||
onClick={onSend}
|
||||
disabled={(!lightningInvoice.trim() && !lightningAddressInput.trim()) || !activeMintUrl || isLoading}
|
||||
className="h-12 px-12 rounded-full"
|
||||
size="lg"
|
||||
>
|
||||
<Zap className="h-5 w-5" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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<void>;
|
||||
onShowLightningAddressQR: (qrCode: string) => void;
|
||||
generateQRCode: (text: string) => Promise<string>;
|
||||
// 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<number | null>(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 (
|
||||
<div className="flex flex-col items-center pt-10 space-y-2">
|
||||
{/* Mode Toggle */}
|
||||
<div className="absolute top-3 left-3 sm:left-4 z-10">
|
||||
<button
|
||||
onClick={toggleMode}
|
||||
className="px-3 py-2 rounded-lg bg-background hover:bg-background/80 transition-colors flex items-center justify-center"
|
||||
title={mode === 'tokens' ? 'Switch to Lightning' : 'Switch to Cashu Tokens'}
|
||||
>
|
||||
{mode === 'tokens' ? (
|
||||
<Coins className="h-6 w-6" />
|
||||
) : (
|
||||
<Zap className="h-6 w-6" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Login Icon */}
|
||||
<div className="absolute top-3 right-3 sm:right-4 z-10">
|
||||
<LoginIcon />
|
||||
</div>
|
||||
|
||||
{/* Balance Display */}
|
||||
<div className="text-center py-2">
|
||||
<div className="flex items-center justify-center gap-3">
|
||||
<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'}`}
|
||||
>
|
||||
<span className="text-muted-foreground italic">
|
||||
{showSats ? '₿' : '$'}
|
||||
</span>
|
||||
{showSats ? totalBalance.toLocaleString() : (btcUsdRate ? `${(totalBalance / 100000000 * btcUsdRate).toFixed(2)}` : totalBalance.toLocaleString())}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Lightning Address and Mint Selector Grid */}
|
||||
<div className="mt-3 px-4">
|
||||
<div className="w-full max-w-[400px] mx-auto">
|
||||
<div className="grid grid-cols-1 gap-3">
|
||||
{/* Lightning Address Row */}
|
||||
{userPubkey && (
|
||||
<div className="flex gap-2 items-center min-w-0">
|
||||
<button
|
||||
onClick={async () => {
|
||||
const lightningAddress = `${npubCashUsername}@npubx.cash`;
|
||||
await onCopyToClipboard(lightningAddress);
|
||||
setLightningAddressCopied(true);
|
||||
setTimeout(() => setLightningAddressCopied(false), 2000);
|
||||
}}
|
||||
className="flex items-center gap-2 px-3 py-1.5 bg-muted hover:bg-muted/80 rounded-md border text-base font-mono transition-colors flex-1 h-[40px] min-w-0"
|
||||
title="Click to copy Lightning address"
|
||||
>
|
||||
<div className="min-w-0 flex-1 flex items-center">
|
||||
<span className="truncate min-w-0 flex-1">
|
||||
{npubCashUsername || ''}
|
||||
</span>
|
||||
<span className="flex-shrink-0 text-muted-foreground">
|
||||
@npubx.cash
|
||||
</span>
|
||||
</div>
|
||||
{lightningAddressCopied ? (
|
||||
<Check className="h-4 w-4 text-green-600 flex-shrink-0" />
|
||||
) : (
|
||||
<Copy className="h-4 w-4 text-muted-foreground flex-shrink-0" />
|
||||
)}
|
||||
</button>
|
||||
<button
|
||||
onClick={async () => {
|
||||
const lightningAddress = `${npubCashUsername}@npubx.cash`;
|
||||
const qr = await generateQRCode(lightningAddress);
|
||||
onShowLightningAddressQR(qr);
|
||||
}}
|
||||
className="flex items-center justify-center px-2 py-1.5 hover:bg-muted rounded-md transition-colors h-[40px] w-[42px] flex-shrink-0"
|
||||
title="Show QR Code"
|
||||
>
|
||||
<QrCode className="h-4 w-4" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Mint Selector Row */}
|
||||
<MintSelector
|
||||
balances={balances}
|
||||
showSats={showSats}
|
||||
activeMintUrl={activeMintUrl}
|
||||
setActiveMintUrl={setActiveMintUrl}
|
||||
mints={mints}
|
||||
mintUrl={mintUrl}
|
||||
setMintUrl={setMintUrl}
|
||||
onAddMint={onAddMint}
|
||||
onRemoveMint={onRemoveMint}
|
||||
onShowDenominations={onShowDenominations}
|
||||
getCleanMintLabel={getCleanMintLabel}
|
||||
dropdownOpen={dropdownOpen}
|
||||
setDropdownOpen={setDropdownOpen}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user