From 0925bb9f1cb7ddaa123f78940284d8839e5e40b9 Mon Sep 17 00:00:00 2001 From: lemonknowsall Date: Mon, 27 Oct 2025 14:42:19 -0700 Subject: [PATCH] ln decoder for qr code scan and mobile qr modal fix --- src/components/wallet/CashuWallet.tsx | 6 ++-- src/components/wallet/PaymentCard.tsx | 10 +++++-- src/components/wallet/WalletModals.tsx | 40 +++++++++++++++----------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/components/wallet/CashuWallet.tsx b/src/components/wallet/CashuWallet.tsx index 1d9e81a..826a2e7 100644 --- a/src/components/wallet/CashuWallet.tsx +++ b/src/components/wallet/CashuWallet.tsx @@ -12,6 +12,7 @@ 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'; @@ -367,11 +368,12 @@ export function CashuWallet() { setLightningInvoice(result.value); setPendingInvoice(result.value); // Decode invoice amount - setDecodedInvoiceAmount(100); // Placeholder - would need actual decoding + const amount = decodeBolt11Amount(result.value); + setDecodedInvoiceAmount(amount); setShowSendModal(true); toast({ title: "Lightning Invoice Scanned", - description: "Invoice ready to pay", + description: amount ? `${amount} sats` : "Invoice ready to pay", }); break; } diff --git a/src/components/wallet/PaymentCard.tsx b/src/components/wallet/PaymentCard.tsx index 4df26b7..d66a9bb 100644 --- a/src/components/wallet/PaymentCard.tsx +++ b/src/components/wallet/PaymentCard.tsx @@ -17,6 +17,12 @@ const getOperationMessage = (operation: string, mode: string): string => { } }; +// Helper function to truncate long addresses (show first 12, last 12 with ellipsis in middle) +const truncateAddress = (address: string): string => { + if (address.length <= 26) return address; // "first 12" + "..." + "last 12" = 26 + return address.slice(0, 12) + '...' + address.slice(-12); +}; + interface TransactionCardProps { mode: 'tokens' | 'lightning' | 'bitcoin'; operation: 'send' | 'receive'; @@ -180,7 +186,7 @@ export function TransactionCard({
Sending to:{' '} - {pendingBitcoinRecipient} + {truncateAddress(pendingBitcoinRecipient)}