This commit is contained in:
lemonknowsall committed 2025-10-23 09:34:15 -07:00
1 parent e3cebf3a34
commit fabbb0b50e
3 files changed
+151 -52

No files matched your search

+26 -4
View File
@@ -12,7 +12,7 @@ import { useWalletTransactions } from '@/hooks/cashu/useWalletTransactions';
import { useHistoryManager } from '@/hooks/cashu/useHistoryManager';
import { useNsecAccess } from '@/hooks/useNsecAccess';
import { useBitcoinBalance, useBitcoinTransactionHistory } from '@/hooks/useBitcoinBalance';
import { nostrPubkeyToBitcoinAddress, npubToBitcoinAddress, fetchUTXOs, getFeeRates, createBitcoinTransaction, broadcastTransaction, UTXO } from '@/lib/bitcoin';
import { nostrPubkeyToBitcoinAddress, npubToBitcoinAddress, fetchUTXOs, getFeeRates, createBitcoinTransaction, broadcastTransaction, calculateMaxSendAmount, UTXO } from '@/lib/bitcoin';
import { QRModal } from '@/components/ui/qr-modal';
import { WalletHeader } from './WalletHeader';
import { TransactionCard } from './PaymentCard';
@@ -183,6 +183,17 @@ export function CashuWallet() {
const [utxoDropdownOpen, setUtxoDropdownOpen] = useState(false);
const [selectedUtxo, setSelectedUtxo] = useState<UTXO | null>(null);
const [isLoadingUtxos, setIsLoadingUtxos] = useState(false);
const [feeRate, setFeeRate] = useState<number>(1);
// Calculate max send amount
const bitcoinMaxAmount = utxos.length > 0 ? calculateMaxSendAmount(utxos, feeRate) : 0;
// Handle Send Max
const handleSendMax = () => {
if (bitcoinMaxAmount > 0) {
setBitcoinAmount(bitcoinMaxAmount.toString());
}
};
// Handle drawer close with state reset
const handleSendDrawerClose = (open: boolean) => {
@@ -259,13 +270,17 @@ export function CashuWallet() {
getFeeRates()
]);
// Check if this is a Send Max transaction
const isSendMax = amountSats === bitcoinMaxAmount && bitcoinMaxAmount > 0;
// Create and sign transaction
const { txHex, fee } = await createBitcoinTransaction(
privateKey,
recipientAddress,
amountSats,
utxos,
feeRates.fastestFee
feeRates.fastestFee,
isSendMax
);
// Broadcast transaction
@@ -316,8 +331,12 @@ export function CashuWallet() {
setIsLoadingUtxos(true);
try {
const fetchedUtxos = await fetchUTXOs(bitcoinAddress);
const [fetchedUtxos, feeRates] = await Promise.all([
fetchUTXOs(bitcoinAddress),
getFeeRates()
]);
setUtxos(fetchedUtxos);
setFeeRate(feeRates.fastestFee);
} catch (error) {
console.error('Error fetching UTXOs:', error);
toast({
@@ -529,9 +548,10 @@ export function CashuWallet() {
<div className="max-w-4xl mx-auto">
<button
onClick={() => setShowHistoryModal(true)}
className="w-full py-2 px-4 flex justify-center border-t border-muted hover:bg-muted/30 transition-colors"
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>
@@ -619,6 +639,8 @@ export function CashuWallet() {
pendingBitcoinRecipient={pendingBitcoinRecipient}
setPendingBitcoinRecipient={setPendingBitcoinRecipient}
hasNsecAccess={hasNsecAccess}
bitcoinMaxAmount={bitcoinMaxAmount}
onSendMax={handleSendMax}
/>
</div>
</DrawerContent>