"use client"; /** * Receive — show address + QR so others can send to this mavi wallet. * Address is public metadata (no unlock required). */ import Link from "next/link"; import QRCode from "qrcode"; import { useEffect, useState } from "react"; import { MaviWalletLogo } from "@/components/wallet/wallet-logos"; import { Button, buttonVariants } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { EmptyState } from "@/components/ui/empty-state"; import { ErrorBanner } from "@/components/ui/error-banner"; import { hasVault, readVault, shortAddress } from "@/lib/mavi/storage"; import { cn } from "@/lib/utils"; export function ReceivePanel() { const [mounted, setMounted] = useState(false); const [address, setAddress] = useState(null); const [qrDataUrl, setQrDataUrl] = useState(null); const [copied, setCopied] = useState(false); const [error, setError] = useState(null); const [shareOk, setShareOk] = useState(false); useEffect(() => { setMounted(true); setShareOk(typeof navigator !== "undefined" && Boolean(navigator.share)); if (!hasVault()) { setAddress(null); return; } const vault = readVault(); setAddress(vault?.address ?? null); }, []); useEffect(() => { if (!address) { setQrDataUrl(null); return; } let cancelled = false; void QRCode.toDataURL(address, { width: 240, margin: 2, color: { dark: "#0a0a0a", light: "#ffffff", }, errorCorrectionLevel: "M", }) .then((url) => { if (!cancelled) setQrDataUrl(url); }) .catch(() => { if (!cancelled) { setError("Could not draw the QR code. You can still copy the address."); } }); return () => { cancelled = true; }; }, [address]); function onCopy() { if (!address) return; void navigator.clipboard.writeText(address).then(() => { setCopied(true); setTimeout(() => setCopied(false), 1600); }); } async function onShare() { if (!address || !navigator.share) return; try { await navigator.share({ title: "mavi wallet address", text: address, }); } catch { /* user cancelled */ } } if (!mounted) { return ( Loading… ); } if (!address) { return ( Create mavi wallet Import recovery phrase } /> ); } return (
Receive
Share this address so someone can send to your mavi wallet. Anyone with the address can send; only you control spending with your password and recovery phrase.
{error ? {error} : null}
{qrDataUrl ? ( // eslint-disable-next-line @next/next/no-img-element {`QR ) : (
Drawing QR…
)}

Scan with a wallet camera · short form{" "} {shortAddress(address)}

Your address

{address}

{shareOk ? ( ) : null} Back to mavi
); }