mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 16:33:36 +00:00
772 lines
27 KiB
TypeScript
772 lines
27 KiB
TypeScript
import { useState, useEffect, useRef } from 'react';
|
|
import { nip19 } from 'nostr-tools';
|
|
import { useCashu } from '@/hooks/cashu/useCashu';
|
|
import { useLightningAddress } from '@/hooks/useLightningAddress';
|
|
import { useNpubCash, type NpubCashUserInfo } from '@/hooks/useNpubCash';
|
|
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
|
import { useToast } from '@/hooks/useToast';
|
|
import { useQRCode, type QRScanResult } from '@/hooks/useQRCode';
|
|
import { useCopyToClipboard } from '@/hooks/useCopyToClipboard';
|
|
import { useMintManager } from '@/hooks/cashu/useMintManager';
|
|
import { useWalletTransactions } from '@/hooks/cashu/useWalletTransactions';
|
|
import { useHistoryManager } from '@/hooks/cashu/useHistoryManager';
|
|
import { useBitcoinBalance, useBitcoinTransactionHistory, useBitcoinOperations } from '@/hooks/useBitcoinBalance';
|
|
import { useNsecAccess } from '@/hooks/useNsecAccess';
|
|
import { decodeBolt11Amount } from '@/lib/bolt11Decoder';
|
|
import { nostrPubkeyToBitcoinAddress } from '@/lib/bitcoin';
|
|
import { QRModal } from '@/components/ui/qr-modal';
|
|
import { WalletHeader } from './WalletHeader';
|
|
import { TransactionCard } from './PaymentCard';
|
|
import { WalletModals } from './WalletModals';
|
|
import { Drawer, DrawerContent, DrawerHeader, DrawerTitle } from '@/components/ui/drawer';
|
|
import { TransactionHistory } from './TransactionHistory';
|
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
|
import { ChevronUp, Send, Download, ScanLine } from 'lucide-react';
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
export function CashuWallet() {
|
|
// ============================================================================
|
|
// CORE HOOKS
|
|
// ============================================================================
|
|
|
|
const {
|
|
coco,
|
|
repositories,
|
|
isInitialized,
|
|
isLoading,
|
|
error,
|
|
balances,
|
|
mints,
|
|
mnemonic,
|
|
getEncodedToken,
|
|
refreshMints,
|
|
} = useCashu();
|
|
|
|
const { user } = useCurrentUser();
|
|
const { getInvoice: getLightningInvoice, isLoading: isResolvingAddress } = useLightningAddress();
|
|
const { toast } = useToast();
|
|
const { generateQRCode, isScanning, startScanning, stopScanning, error: qrError, classifyQRCode, setModalOpen } = useQRCode();
|
|
const { copy: copyToClipboard } = useCopyToClipboard();
|
|
const { hasNsecAccess } = useNsecAccess();
|
|
|
|
// Bitcoin hooks - including balance and transaction history
|
|
const bitcoinAddress = user?.pubkey ? nostrPubkeyToBitcoinAddress(user.pubkey) : null;
|
|
const { data: bitcoinBalanceData, isLoading: isBitcoinBalanceLoading } = useBitcoinBalance(bitcoinAddress);
|
|
|
|
// Bitcoin operations hook
|
|
const {
|
|
utxos,
|
|
isConsolidating,
|
|
bitcoinMaxAmount,
|
|
fetchBitcoinUtxos,
|
|
handleSendMax,
|
|
handleBitcoinSend,
|
|
handleBitcoinReceive,
|
|
handleConsolidateUtxos,
|
|
} = useBitcoinOperations(bitcoinAddress);
|
|
|
|
const {
|
|
setMint: setNpubCashMint,
|
|
getUserInfo: getNpubCashUserInfo,
|
|
syncQuotesWithWallet,
|
|
isLoggedIn: isNpubCashLoggedIn,
|
|
isLoading: isNpubCashLoading,
|
|
error: npubCashError,
|
|
clearError: clearNpubCashError
|
|
} = useNpubCash();
|
|
|
|
// Wrapper to handle return type mismatch
|
|
const handleSetNpubCashMint = (mintUrl: string): Promise<boolean> => {
|
|
return setNpubCashMint(mintUrl);
|
|
};
|
|
|
|
// ============================================================================
|
|
// DOMAIN HOOKS
|
|
// ============================================================================
|
|
|
|
const {
|
|
activeMintUrl,
|
|
setActiveMintUrl,
|
|
mintUrl,
|
|
setMintUrl,
|
|
mintDropdownOpen,
|
|
setMintDropdownOpen,
|
|
handleAddMint,
|
|
handleRemoveMintClick,
|
|
handleConfirmRemoveMint,
|
|
mintToRemove,
|
|
showRemoveMintModal,
|
|
setShowRemoveMintModal,
|
|
getCleanMintLabel,
|
|
handleShowDenominations,
|
|
} = useMintManager({
|
|
coco,
|
|
mints,
|
|
repositories,
|
|
isNpubCashLoggedIn,
|
|
setNpubCashMint: handleSetNpubCashMint,
|
|
refreshMints,
|
|
});
|
|
|
|
// Wrapper for setActiveMintUrl to handle the async nature
|
|
const handleSetActiveMintSync = (url: string | null) => {
|
|
setActiveMintUrl(url);
|
|
};
|
|
|
|
const {
|
|
tokenInput,
|
|
setTokenInput,
|
|
quoteAmount,
|
|
setQuoteAmount,
|
|
sendAmount,
|
|
setSendAmount,
|
|
lightningInvoice,
|
|
setLightningInvoice,
|
|
lightningAddressInput,
|
|
setLightningAddressInput,
|
|
lightningAddressAmount,
|
|
setLightningAddressAmount,
|
|
pendingLightningAddress,
|
|
setPendingLightningAddress,
|
|
decodedInvoiceAmount,
|
|
setDecodedInvoiceAmount,
|
|
pendingInvoice,
|
|
setPendingInvoice,
|
|
sentToken,
|
|
setSentToken,
|
|
sentTokenQRCode,
|
|
showInvoiceModal,
|
|
setShowInvoiceModal,
|
|
currentInvoice,
|
|
handleReceive,
|
|
handleSend,
|
|
handleConfirmInvoicePayment,
|
|
handleRestoreFromSeedPhrase,
|
|
isRestoring,
|
|
mintQuoteUnsubscribeRef,
|
|
} = useWalletTransactions({
|
|
coco,
|
|
activeMintUrl,
|
|
generateQRCode,
|
|
getEncodedToken,
|
|
getLightningInvoice,
|
|
});
|
|
|
|
const {
|
|
historyEntries,
|
|
isLoadingHistory,
|
|
} = useHistoryManager({
|
|
coco,
|
|
isInitialized,
|
|
});
|
|
|
|
// Bitcoin transaction history
|
|
const {
|
|
data: bitcoinTransactions = [],
|
|
isLoading: isBitcoinTransactionsLoading
|
|
} = useBitcoinTransactionHistory(bitcoinAddress);
|
|
|
|
// ============================================================================
|
|
// UI STATE
|
|
// ============================================================================
|
|
|
|
const [showSats, setShowSats] = useState(true);
|
|
const [mode, setMode] = useState<'tokens' | 'lightning' | 'bitcoin'>('lightning');
|
|
const [showProofBreakdown, setShowProofBreakdown] = useState(false);
|
|
const [proofBreakdown, setProofBreakdown] = useState<{
|
|
mintUrl: string;
|
|
denominations: { [key: number]: number };
|
|
totalBalance: number;
|
|
} | null>(null);
|
|
const [showLightningAddressQR, setShowLightningAddressQR] = useState(false);
|
|
const [lightningAddressQRCode, setLightningAddressQRCode] = useState<string>('');
|
|
const [npubCashUserInfo, setNpubCashUserInfo] = useState<NpubCashUserInfo | null>(null);
|
|
const [showSendModal, setShowSendModal] = useState(false);
|
|
const [showReceiveModal, setShowReceiveModal] = useState(false);
|
|
const [showHistoryModal, setShowHistoryModal] = useState(false);
|
|
const [showQRScanner, setShowQRScanner] = useState(false);
|
|
|
|
// Bitcoin state
|
|
const [bitcoinAmount, setBitcoinAmount] = useState('');
|
|
const [bitcoinRecipient, setBitcoinRecipient] = useState('');
|
|
const [pendingBitcoinRecipient, setPendingBitcoinRecipient] = useState<string | null>(null);
|
|
const [showBitcoinAddressQR, setShowBitcoinAddressQR] = useState(false);
|
|
const [bitcoinAddressQRCode, setBitcoinAddressQRCode] = useState('');
|
|
const [showSeedPhraseInfo, setShowSeedPhraseInfo] = useState(false);
|
|
const [showConsolidationModal, setShowConsolidationModal] = useState(false);
|
|
|
|
// UTXO state
|
|
const [utxoDropdownOpen, setUtxoDropdownOpen] = useState(false);
|
|
|
|
|
|
// Handle drawer close with state reset
|
|
const handleSendDrawerClose = (open: boolean) => {
|
|
setShowSendModal(open);
|
|
if (!open) {
|
|
// Reset all send-related state when drawer closes
|
|
setSendAmount('');
|
|
setLightningInvoice('');
|
|
setLightningAddressInput('');
|
|
setLightningAddressAmount('');
|
|
setPendingLightningAddress(null);
|
|
setDecodedInvoiceAmount(null);
|
|
setPendingInvoice(null);
|
|
// Reset Bitcoin state
|
|
setBitcoinAmount('');
|
|
setBitcoinRecipient('');
|
|
setPendingBitcoinRecipient(null);
|
|
}
|
|
};
|
|
|
|
const handleReceiveDrawerClose = (open: boolean) => {
|
|
setShowReceiveModal(open);
|
|
if (!open) {
|
|
// Reset all receive-related state when drawer closes
|
|
setTokenInput('');
|
|
setQuoteAmount('');
|
|
}
|
|
};
|
|
|
|
// Ref to track if we've fetched npub.cash user info
|
|
const hasCheckedNpubCashRef = useRef(false);
|
|
|
|
// ============================================================================
|
|
// COMPUTED VALUES
|
|
// ============================================================================
|
|
|
|
const totalBalance: number = mode === 'bitcoin'
|
|
? (bitcoinBalanceData?.balance || 0)
|
|
: (Object.values(balances) as number[]).reduce((sum: number, balance: number) => sum + balance, 0);
|
|
|
|
// ============================================================================
|
|
// EFFECTS - Error Handling
|
|
// ============================================================================
|
|
|
|
useEffect(() => {
|
|
if (error) {
|
|
toast({
|
|
variant: "destructive",
|
|
title: "Wallet Error",
|
|
description: error.message,
|
|
});
|
|
}
|
|
}, [error, toast]);
|
|
|
|
useEffect(() => {
|
|
if (npubCashError) {
|
|
toast({
|
|
variant: "destructive",
|
|
title: "Npub.cash Error",
|
|
description: npubCashError,
|
|
});
|
|
clearNpubCashError();
|
|
}
|
|
}, [npubCashError, clearNpubCashError, toast]);
|
|
|
|
// ============================================================================
|
|
// EFFECTS - NPub.cash Integration
|
|
// ============================================================================
|
|
|
|
useEffect(() => {
|
|
if (!isNpubCashLoggedIn) {
|
|
hasCheckedNpubCashRef.current = false;
|
|
setNpubCashUserInfo(null);
|
|
return;
|
|
}
|
|
|
|
if (!isInitialized || hasCheckedNpubCashRef.current || isNpubCashLoading) return;
|
|
|
|
const fetchUserInfo = async () => {
|
|
hasCheckedNpubCashRef.current = true;
|
|
|
|
const userInfo = await getNpubCashUserInfo();
|
|
if (!userInfo) return;
|
|
|
|
setNpubCashUserInfo(userInfo);
|
|
|
|
// Sync mint from npub.cash if different from active mint
|
|
if (userInfo.mint_url && userInfo.mint_url !== activeMintUrl) {
|
|
const mintExists = mints.some(m => m.url === userInfo.mint_url);
|
|
|
|
if (!mintExists && coco) {
|
|
try {
|
|
await coco.mint.addMint(userInfo.mint_url);
|
|
setTimeout(() => setActiveMintUrl(userInfo.mint_url, false), 500);
|
|
} catch {
|
|
// Silent failure - user can manually add mint if needed
|
|
}
|
|
} else if (mintExists) {
|
|
setActiveMintUrl(userInfo.mint_url, false);
|
|
}
|
|
}
|
|
};
|
|
|
|
fetchUserInfo();
|
|
}, [isNpubCashLoggedIn, isInitialized, isNpubCashLoading, getNpubCashUserInfo, activeMintUrl, mints, coco, setActiveMintUrl]);
|
|
|
|
// Set up automatic quote sync subscription when logged into npub.cash
|
|
useEffect(() => {
|
|
if (!isNpubCashLoggedIn || !coco || !isInitialized) return;
|
|
|
|
let unsubscribe: (() => void) | null = null;
|
|
|
|
const setupSync = async () => {
|
|
unsubscribe = await syncQuotesWithWallet(coco);
|
|
};
|
|
|
|
setupSync();
|
|
|
|
return () => {
|
|
if (unsubscribe) {
|
|
unsubscribe();
|
|
}
|
|
};
|
|
}, [isNpubCashLoggedIn, coco, isInitialized, syncQuotesWithWallet, toast]);
|
|
|
|
// ============================================================================
|
|
// EFFECTS - UTXO Fetching
|
|
// ============================================================================
|
|
|
|
useEffect(() => {
|
|
if (mode === 'bitcoin' && bitcoinAddress) {
|
|
fetchBitcoinUtxos();
|
|
}
|
|
}, [mode, bitcoinAddress, fetchBitcoinUtxos]);
|
|
|
|
// Start/stop QR scanner when modal opens/closes
|
|
useEffect(() => {
|
|
if (showQRScanner) {
|
|
setModalOpen?.(true);
|
|
startScanning(handleQRScanResult);
|
|
} else {
|
|
setModalOpen?.(false);
|
|
stopScanning();
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [showQRScanner, startScanning, stopScanning, setModalOpen]);
|
|
|
|
// ============================================================================
|
|
// EFFECTS - Cleanup
|
|
// ============================================================================
|
|
|
|
useEffect(() => {
|
|
return () => {
|
|
if (mintQuoteUnsubscribeRef.current) {
|
|
mintQuoteUnsubscribeRef.current();
|
|
mintQuoteUnsubscribeRef.current = null;
|
|
}
|
|
};
|
|
}, [mintQuoteUnsubscribeRef]);
|
|
|
|
// Handle QR scanner results
|
|
const handleQRScanResult = async (result: QRScanResult) => {
|
|
try {
|
|
await stopScanning();
|
|
setShowQRScanner(false);
|
|
|
|
switch (result.type) {
|
|
case 'lightning_invoice': {
|
|
setMode('lightning');
|
|
setLightningInvoice(result.value);
|
|
setPendingInvoice(result.value);
|
|
// Decode invoice amount
|
|
const amount = decodeBolt11Amount(result.value);
|
|
setDecodedInvoiceAmount(amount);
|
|
setShowSendModal(true);
|
|
toast({
|
|
title: "Lightning Invoice Scanned",
|
|
description: amount ? `${amount} sats` : "Invoice ready to pay",
|
|
});
|
|
break;
|
|
}
|
|
case 'lightning_address': {
|
|
setMode('lightning');
|
|
setLightningAddressInput(result.value);
|
|
setPendingLightningAddress(result.value);
|
|
setShowSendModal(true);
|
|
toast({
|
|
title: "Lightning Address Scanned",
|
|
description: "Enter amount to send",
|
|
});
|
|
break;
|
|
}
|
|
case 'cashu_token': {
|
|
setMode('tokens');
|
|
setTokenInput(result.value);
|
|
setShowReceiveModal(true);
|
|
toast({
|
|
title: "Cashu Token Scanned",
|
|
description: "Token ready to redeem",
|
|
});
|
|
break;
|
|
}
|
|
case 'bitcoin_address': {
|
|
setMode('bitcoin');
|
|
setBitcoinRecipient(result.value);
|
|
setPendingBitcoinRecipient(result.value);
|
|
setShowSendModal(true);
|
|
toast({
|
|
title: "Bitcoin Address Scanned",
|
|
description: "Enter amount to send",
|
|
});
|
|
break;
|
|
}
|
|
case 'npub': {
|
|
// Convert npub to bitcoin address
|
|
try {
|
|
const decoded = nip19.decode(result.value);
|
|
if (decoded.type === 'npub') {
|
|
const address = nostrPubkeyToBitcoinAddress(decoded.data);
|
|
setMode('bitcoin');
|
|
setBitcoinRecipient(address);
|
|
setPendingBitcoinRecipient(address);
|
|
setShowSendModal(true);
|
|
toast({
|
|
title: "Nostr npub Scanned",
|
|
description: "Enter amount to send",
|
|
});
|
|
}
|
|
} catch (err) {
|
|
toast({
|
|
variant: "destructive",
|
|
title: "Invalid npub",
|
|
description: "Could not decode npub",
|
|
});
|
|
}
|
|
break;
|
|
}
|
|
default: {
|
|
toast({
|
|
variant: "destructive",
|
|
title: "Unknown QR Code",
|
|
description: result.value,
|
|
});
|
|
}
|
|
}
|
|
} catch (err) {
|
|
console.error('Error handling QR scan:', err);
|
|
}
|
|
};
|
|
|
|
// Handle paste from clipboard
|
|
const handlePasteQRCode = async () => {
|
|
try {
|
|
const text = await navigator.clipboard.readText();
|
|
if (!text || !text.trim()) {
|
|
toast({
|
|
variant: "destructive",
|
|
title: "Clipboard Empty",
|
|
description: "No text found in clipboard",
|
|
});
|
|
return;
|
|
}
|
|
|
|
const result = classifyQRCode(text.trim());
|
|
await handleQRScanResult(result);
|
|
} catch (err) {
|
|
toast({
|
|
variant: "destructive",
|
|
title: "Paste Failed",
|
|
description: "Could not read from clipboard",
|
|
});
|
|
console.error('Error pasting from clipboard:', err);
|
|
}
|
|
};
|
|
|
|
// ============================================================================
|
|
// RENDER
|
|
// ============================================================================
|
|
|
|
return (
|
|
<>
|
|
<div className="max-w-4xl mx-auto pt-16 pb-32 px-3 sm:px-4 relative">
|
|
|
|
{/* 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}
|
|
mnemonic={mnemonic}
|
|
onCopyToClipboard={copyToClipboard}
|
|
onShowLightningAddressQR={(qr) => {
|
|
setLightningAddressQRCode(qr);
|
|
setShowLightningAddressQR(true);
|
|
}}
|
|
onShowBitcoinAddressQR={(qr) => {
|
|
setBitcoinAddressQRCode(qr);
|
|
setShowBitcoinAddressQR(true);
|
|
}}
|
|
onShowSeedPhraseInfo={() => setShowSeedPhraseInfo(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}
|
|
// UTXOSelector props
|
|
utxos={utxos}
|
|
utxoDropdownOpen={utxoDropdownOpen}
|
|
setUtxoDropdownOpen={setUtxoDropdownOpen}
|
|
onShowConsolidationModal={() => setShowConsolidationModal(true)}
|
|
isConsolidating={isConsolidating}
|
|
/>
|
|
|
|
|
|
{/* Action Buttons and Transaction History Container */}
|
|
<div className="fixed bottom-0 left-0 right-0 pb-8 pb-safe">
|
|
{/* Action Buttons */}
|
|
<div className="flex gap-8 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={() => setShowQRScanner(true)}
|
|
disabled={isLoading || isNpubCashLoading}
|
|
className="h-20 w-20 rounded-full bg-muted transition-all duration-200 hover:scale-105 [&_svg]:size-6"
|
|
>
|
|
<ScanLine 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">
|
|
<button
|
|
onClick={() => setShowHistoryModal(true)}
|
|
className="w-full py-2 px-4 flex flex-col items-center gap-1 border-t border-muted hover:bg-muted/30 transition-colors"
|
|
>
|
|
<ChevronUp className="h-5 w-5 text-muted-foreground" />
|
|
<span className="text-xs text-muted-foreground font-medium">History</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Modals */}
|
|
<>
|
|
<WalletModals
|
|
showProofBreakdown={showProofBreakdown}
|
|
setShowProofBreakdown={setShowProofBreakdown}
|
|
proofBreakdown={proofBreakdown}
|
|
showRemoveMintModal={showRemoveMintModal}
|
|
setShowRemoveMintModal={setShowRemoveMintModal}
|
|
mintToRemove={mintToRemove}
|
|
onConfirmRemoveMint={handleConfirmRemoveMint}
|
|
isLoading={isLoading || isNpubCashLoading}
|
|
showConsolidationModal={showConsolidationModal}
|
|
setShowConsolidationModal={setShowConsolidationModal}
|
|
utxos={utxos}
|
|
onConfirmConsolidation={handleConsolidateUtxos}
|
|
isConsolidating={isConsolidating}
|
|
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}
|
|
showSeedPhraseInfo={showSeedPhraseInfo}
|
|
setShowSeedPhraseInfo={setShowSeedPhraseInfo}
|
|
onRestoreFromSeedPhrase={handleRestoreFromSeedPhrase}
|
|
isRestoring={isRestoring}
|
|
mints={mints}
|
|
activeMintUrl={activeMintUrl}
|
|
showQRScanner={showQRScanner}
|
|
setShowQRScanner={setShowQRScanner}
|
|
stopScanning={stopScanning}
|
|
qrError={qrError}
|
|
onPasteQRCode={handlePasteQRCode}
|
|
/>
|
|
|
|
{/* Bottom Drawer Modals */}
|
|
<Drawer open={showSendModal} onOpenChange={handleSendDrawerClose}>
|
|
<DrawerContent className="min-h-[40vh] max-w-4xl mx-auto">
|
|
<DrawerHeader>
|
|
<DrawerTitle className="text-center text-3xl font-bold">Send</DrawerTitle>
|
|
</DrawerHeader>
|
|
<div className="px-4 pb-6 pb-safe-bottom">
|
|
<TransactionCard
|
|
mode={mode}
|
|
operation="send"
|
|
sendAmount={sendAmount}
|
|
setSendAmount={setSendAmount}
|
|
lightningInvoice={lightningInvoice}
|
|
setLightningInvoice={setLightningInvoice}
|
|
lightningAddressInput={lightningAddressInput}
|
|
setLightningAddressInput={setLightningAddressInput}
|
|
lightningAddressAmount={lightningAddressAmount}
|
|
setLightningAddressAmount={setLightningAddressAmount}
|
|
pendingLightningAddress={pendingLightningAddress}
|
|
setPendingLightningAddress={setPendingLightningAddress}
|
|
decodedInvoiceAmount={decodedInvoiceAmount}
|
|
setDecodedInvoiceAmount={setDecodedInvoiceAmount}
|
|
pendingInvoice={pendingInvoice}
|
|
setPendingInvoice={setPendingInvoice}
|
|
tokenInput=""
|
|
setTokenInput={() => {}}
|
|
quoteAmount=""
|
|
setQuoteAmount={() => {}}
|
|
activeMintUrl={activeMintUrl}
|
|
onSend={() => {
|
|
if (mode === 'bitcoin') {
|
|
handleBitcoinSend(
|
|
bitcoinAmount,
|
|
pendingBitcoinRecipient,
|
|
setBitcoinAmount,
|
|
setBitcoinRecipient,
|
|
setPendingBitcoinRecipient,
|
|
setShowSendModal
|
|
);
|
|
} else {
|
|
const wasPendingBefore = pendingLightningAddress !== null && pendingLightningAddress !== '';
|
|
handleSend();
|
|
if (mode === 'tokens' || wasPendingBefore) {
|
|
setShowSendModal(false);
|
|
}
|
|
}
|
|
}}
|
|
onReceive={() => {}}
|
|
onConfirmInvoice={() => {
|
|
handleConfirmInvoicePayment();
|
|
setShowSendModal(false);
|
|
}}
|
|
isResolvingAddress={isResolvingAddress}
|
|
isLoading={isLoading || isNpubCashLoading || isBitcoinBalanceLoading}
|
|
// Bitcoin props
|
|
bitcoinAddress={bitcoinAddress || ''}
|
|
bitcoinAmount={bitcoinAmount}
|
|
setBitcoinAmount={setBitcoinAmount}
|
|
bitcoinRecipient={bitcoinRecipient}
|
|
setBitcoinRecipient={setBitcoinRecipient}
|
|
pendingBitcoinRecipient={pendingBitcoinRecipient}
|
|
setPendingBitcoinRecipient={setPendingBitcoinRecipient}
|
|
hasNsecAccess={hasNsecAccess}
|
|
bitcoinMaxAmount={bitcoinMaxAmount}
|
|
onSendMax={() => handleSendMax(setBitcoinAmount)}
|
|
/>
|
|
</div>
|
|
</DrawerContent>
|
|
</Drawer>
|
|
|
|
<Drawer open={showReceiveModal} onOpenChange={handleReceiveDrawerClose}>
|
|
<DrawerContent className="min-h-[40vh] max-w-4xl mx-auto">
|
|
<DrawerHeader>
|
|
<DrawerTitle className="text-center text-3xl font-bold">Receive</DrawerTitle>
|
|
</DrawerHeader>
|
|
<div className="px-4 pb-6 pb-safe-bottom">
|
|
<TransactionCard
|
|
mode={mode}
|
|
operation="receive"
|
|
sendAmount=""
|
|
setSendAmount={() => {}}
|
|
lightningInvoice=""
|
|
setLightningInvoice={() => {}}
|
|
lightningAddressInput=""
|
|
setLightningAddressInput={() => {}}
|
|
lightningAddressAmount=""
|
|
setLightningAddressAmount={() => {}}
|
|
pendingLightningAddress={null}
|
|
setPendingLightningAddress={() => {}}
|
|
decodedInvoiceAmount={null}
|
|
setDecodedInvoiceAmount={() => {}}
|
|
pendingInvoice={null}
|
|
setPendingInvoice={() => {}}
|
|
tokenInput={tokenInput}
|
|
setTokenInput={setTokenInput}
|
|
quoteAmount={quoteAmount}
|
|
setQuoteAmount={setQuoteAmount}
|
|
activeMintUrl={activeMintUrl}
|
|
onSend={() => {}}
|
|
onReceive={() => {
|
|
if (mode === 'bitcoin') {
|
|
handleBitcoinReceive(setBitcoinAddressQRCode, setShowBitcoinAddressQR);
|
|
setShowReceiveModal(false);
|
|
} else {
|
|
handleReceive();
|
|
setShowReceiveModal(false);
|
|
}
|
|
}}
|
|
isResolvingAddress={false}
|
|
isLoading={isLoading || isNpubCashLoading || isBitcoinBalanceLoading}
|
|
// Bitcoin props
|
|
bitcoinAddress={bitcoinAddress || ''}
|
|
bitcoinAmount=""
|
|
setBitcoinAmount={() => {}}
|
|
bitcoinRecipient=""
|
|
setBitcoinRecipient={() => {}}
|
|
pendingBitcoinRecipient={null}
|
|
setPendingBitcoinRecipient={() => {}}
|
|
hasNsecAccess={hasNsecAccess}
|
|
/>
|
|
</div>
|
|
</DrawerContent>
|
|
</Drawer>
|
|
|
|
<Drawer open={showHistoryModal} onOpenChange={setShowHistoryModal}>
|
|
<DrawerContent className="max-h-[80vh] max-w-4xl mx-auto">
|
|
<DrawerHeader>
|
|
<DrawerTitle className="text-center text-3xl font-bold">Transactions</DrawerTitle>
|
|
</DrawerHeader>
|
|
<ScrollArea className="h-[80vh] px-4 pb-4">
|
|
<TransactionHistory
|
|
entries={mode === 'bitcoin' ? [] : historyEntries}
|
|
isLoading={mode === 'bitcoin' ? isBitcoinTransactionsLoading : isLoadingHistory}
|
|
bitcoinTransactions={mode === 'bitcoin' ? bitcoinTransactions : []}
|
|
isBitcoinLoading={isBitcoinTransactionsLoading}
|
|
showSats={showSats}
|
|
/>
|
|
</ScrollArea>
|
|
</DrawerContent>
|
|
</Drawer>
|
|
|
|
{/* Bitcoin Address QR Modal */}
|
|
<QRModal
|
|
isOpen={showBitcoinAddressQR}
|
|
onClose={() => setShowBitcoinAddressQR(false)}
|
|
title="Bitcoin Address"
|
|
description="Scan this QR code to send Bitcoin to your address"
|
|
qrCodeUrl={bitcoinAddressQRCode}
|
|
content={bitcoinAddress || ''}
|
|
icon="qr"
|
|
/>
|
|
</>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|