mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-05 16:33:36 +00:00
add lightning address and qr modal
This commit is contained in:
1 parent
346ba70710
commit
1701cce6b0
2 files changed
+62
-1
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import { useCashu, type HistoryEntry } from '@/hooks/useCashu';
|
||||
import { useCashuMints } from '@/hooks/cashu/useCashuMints';
|
||||
import { useLightningAddress } from '@/hooks/useLightningAddress';
|
||||
import { useNpubCash } from '@/hooks/useNpubCash';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { useQRCode } from '@/hooks/useQRCode';
|
||||
import { useCopyToClipboard } from '@/hooks/useCopyToClipboard';
|
||||
@@ -15,6 +17,8 @@ import { TransactionHistory } from '@/components/wallet/TransactionHistory';
|
||||
import { ProofBreakdownModal } from '@/components/wallet/ProofBreakdownModal';
|
||||
import { RemoveMintModal } from '@/components/wallet/RemoveMintModal';
|
||||
import { LoginArea } from '@/components/auth/LoginArea';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { QrCode, Copy, Check } from 'lucide-react';
|
||||
|
||||
export function CashuWallet() {
|
||||
// ============================================================================
|
||||
@@ -47,6 +51,8 @@ export function CashuWallet() {
|
||||
const { getCleanMintLabel } = useCashuMints(null);
|
||||
|
||||
const { setMint: setNpubCashMint, isLoggedIn: isNpubCashLoggedIn } = useNpubCash();
|
||||
|
||||
const { user } = useCurrentUser();
|
||||
|
||||
const { getInvoice: getLightningInvoice, isLoading: isResolvingAddress } = useLightningAddress();
|
||||
|
||||
@@ -98,6 +104,9 @@ export function CashuWallet() {
|
||||
|
||||
const [showLightningQR, setShowLightningQR] = useState(false);
|
||||
const [lightningQRCode, setLightningQRCode] = useState<string>('');
|
||||
const [showLightningAddressQR, setShowLightningAddressQR] = useState(false);
|
||||
const [lightningAddressQRCode, setLightningAddressQRCode] = useState<string>('');
|
||||
const [lightningAddressCopied, setLightningAddressCopied] = useState(false);
|
||||
|
||||
const [showInvoiceModal, setShowInvoiceModal] = useState(false);
|
||||
const [currentInvoice, setCurrentInvoice] = useState<{
|
||||
@@ -666,6 +675,46 @@ export function CashuWallet() {
|
||||
getCleanMintLabel={getCleanMintLabel}
|
||||
/>
|
||||
|
||||
{/* ========================================================================
|
||||
SECTION: Lightning Address
|
||||
======================================================================== */}
|
||||
{user?.pubkey && (
|
||||
<div className="mb-4 flex items-center justify-center gap-2">
|
||||
<button
|
||||
onClick={async () => {
|
||||
const npub = nip19.npubEncode(user.pubkey);
|
||||
const address = `${npub}@npub.cash`;
|
||||
await copyToClipboard(address);
|
||||
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-sm font-mono transition-colors h-[34px]"
|
||||
title="Click to copy Lightning address"
|
||||
>
|
||||
<span className="truncate max-w-[250px] sm:max-w-none">
|
||||
{nip19.npubEncode(user.pubkey)}@npub.cash
|
||||
</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 npub = nip19.npubEncode(user.pubkey);
|
||||
const address = `${npub}@npub.cash`;
|
||||
const qr = await generateQRCode(address);
|
||||
setLightningAddressQRCode(qr);
|
||||
setShowLightningAddressQR(true);
|
||||
}}
|
||||
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>
|
||||
)}
|
||||
|
||||
{/* ========================================================================
|
||||
SECTION: Receive & Send Cards
|
||||
@@ -747,6 +796,16 @@ export function CashuWallet() {
|
||||
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 ? `${nip19.npubEncode(user.pubkey)}@npub.cash` : ''}
|
||||
icon="zap"
|
||||
/>
|
||||
|
||||
{currentInvoice && (
|
||||
<QRModal
|
||||
isOpen={showInvoiceModal}
|
||||
|
||||
@@ -125,7 +125,9 @@ export function QRModal({
|
||||
onClick={handleCopy}
|
||||
title="Click to copy full content"
|
||||
>
|
||||
{content.length > 20 ? `${content.substring(0, 20)}...` : content}
|
||||
{content.length > 33
|
||||
? `${content.substring(0, 15)}...${content.substring(content.length - 15)}`
|
||||
: content}
|
||||
<div className="absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
{copied ? (
|
||||
<Check className="h-4 w-4 text-green-600" />
|
||||
|
||||
Reference in new issue
Block a user