import { useState } from 'react'; import { Loader2, Plus, RefreshCw, TriangleAlert, Zap } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { toneFill } from '@/components/Data/tone'; import { formatTimestamp, truncateMiddle } from './format'; import { INVOICE_STATE_TONE } from './shared'; import { Amount } from './Amount'; import { CopyField } from './CopyField'; import { EmptyWallet, UnsupportedSection } from './EmptyWallet'; import { useSelectedWallet } from './useSelectedWallet'; import { errorMessage, usePermissions, useInvoices, useReceiveAddress } from './useWalletData'; import { CreateInvoiceDialog } from './dialogs/CreateInvoiceDialog'; // Receiving. Works while locked — deriving an address needs the account xpub, not the seed, which is why // this whole screen is usable in the wallet's resting state. // // The address is fetched with `?peek=true`: it returns the current unused address without advancing the // derivation index. Rendering must never burn an address, so advancing is an explicit button. export const ReceiveView = () => { const { walletId, isLoading } = useSelectedWallet(); const { capabilities } = usePermissions(walletId); const canOnchain = capabilities.includes('onchainReceive'); const canLightning = capabilities.includes('lightningReceive'); const { address, addressType, isLoading: addressLoading, error: addressError, next, } = useReceiveAddress(walletId, canOnchain); const { invoices } = useInvoices(walletId, canLightning, 10); const [invoiceOpen, setInvoiceOpen] = useState(false); if (!walletId) return ; if (!canOnchain && !canLightning) return ; return (
{canOnchain && (

On-chain address

{addressLoading && !address ? (
Deriving an address…
) : address ? ( <>

{addressType ? `${addressType} · ` : ''}Reuse costs you privacy, not money — take a fresh one for each payer.

) : addressError ? ( // Deriving an address needs the chain source, so this fails whenever the Esplora endpoint is // down or rate-limiting. Showing "no address available" for that sent the last debugging // session looking at derivation code when the answer was a 429 in the response body.

{errorMessage(addressError, 'Could not derive an address')}

Addresses are derived locally, but the wallet checks the chain to find an unused one. Check{' '} Settings → Chain source.

) : (

No address available.

)}
)} {canLightning && (

Lightning invoices

{invoices.length === 0 ? (

No invoices yet.

) : (
    {invoices.map((inv) => (
  • {inv.memo || truncateMiddle(inv.paymentHash, 12, 8)} {inv.state} {/* msat stays a string all the way to the DOM — see format.ts. */}
    created {formatTimestamp(inv.createdAt)} {inv.settledAt ? ` · settled ${formatTimestamp(inv.settledAt)}` : ''}
    {inv.state === 'open' && }
  • ))}
)}
)} {invoiceOpen && }
); };