|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog" |
| 4 | +import { Button } from "@/components/ui/button" |
| 5 | +import { Badge } from "@/components/ui/badge" |
| 6 | +import { Copy, CheckCircle2, AlertTriangle } from "lucide-react" |
| 7 | +import QRCodeSVG from "react-qr-code" |
| 8 | +import { Address } from "viem" |
| 9 | +import { useState } from "react" |
| 10 | + |
| 11 | +interface ReceiveModalProps { |
| 12 | + open: boolean |
| 13 | + onOpenChange: (open: boolean) => void |
| 14 | + address: Address | undefined |
| 15 | +} |
| 16 | + |
| 17 | +export function ReceiveModal({ open, onOpenChange, address }: ReceiveModalProps) { |
| 18 | + const [copied, setCopied] = useState(false) |
| 19 | + |
| 20 | + const handleCopy = async () => { |
| 21 | + if (!address) return |
| 22 | + |
| 23 | + await navigator.clipboard.writeText(address) |
| 24 | + setCopied(true) |
| 25 | + setTimeout(() => setCopied(false), 2000) |
| 26 | + } |
| 27 | + |
| 28 | + if (!address) return null |
| 29 | + |
| 30 | + return ( |
| 31 | + <Dialog open={open} onOpenChange={onOpenChange}> |
| 32 | + <DialogContent className="sm:max-w-md"> |
| 33 | + <DialogHeader> |
| 34 | + <DialogTitle className="text-2xl font-bold">Receive Funds</DialogTitle> |
| 35 | + <DialogDescription> |
| 36 | + Scan the QR code or copy your wallet address to receive funds |
| 37 | + </DialogDescription> |
| 38 | + </DialogHeader> |
| 39 | + |
| 40 | + <div className="flex flex-col items-center gap-6 py-4"> |
| 41 | + {/* QR Code */} |
| 42 | + <div className="p-4 bg-white rounded-xl shadow-sm border-2 border-muted"> |
| 43 | + <QRCodeSVG |
| 44 | + value={address} |
| 45 | + size={200} |
| 46 | + level="H" |
| 47 | + /> |
| 48 | + </div> |
| 49 | + |
| 50 | + {/* Wallet Address */} |
| 51 | + <div className="w-full space-y-3"> |
| 52 | + <div className="flex items-center justify-between gap-2 p-3 rounded-lg bg-muted/50 border"> |
| 53 | + <code className="text-xs sm:text-sm font-mono break-all flex-1"> |
| 54 | + {address} |
| 55 | + </code> |
| 56 | + <Button |
| 57 | + variant="ghost" |
| 58 | + size="icon" |
| 59 | + className="shrink-0 size-8" |
| 60 | + onClick={handleCopy} |
| 61 | + > |
| 62 | + {copied ? ( |
| 63 | + <CheckCircle2 className="size-4 text-green-500" /> |
| 64 | + ) : ( |
| 65 | + <Copy className="size-4" /> |
| 66 | + )} |
| 67 | + </Button> |
| 68 | + </div> |
| 69 | + |
| 70 | + {/* Network Warning */} |
| 71 | + <div className="flex items-start gap-2 p-3 rounded-lg bg-amber-50 dark:bg-amber-950/20 border border-amber-200 dark:border-amber-900"> |
| 72 | + <AlertTriangle className="size-5 text-amber-600 dark:text-amber-500 shrink-0 mt-0.5" /> |
| 73 | + <div className="space-y-1"> |
| 74 | + <p className="text-sm font-semibold text-amber-900 dark:text-amber-100"> |
| 75 | + Important Notice |
| 76 | + </p> |
| 77 | + <p className="text-xs text-amber-800 dark:text-amber-200"> |
| 78 | + Only send assets on the <Badge variant="outline" className="text-[10px] px-1.5 py-0 font-semibold">Ethereum Network</Badge> to this address. |
| 79 | + Sending assets from other networks may result in permanent loss of funds. |
| 80 | + </p> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + </div> |
| 85 | + </DialogContent> |
| 86 | + </Dialog> |
| 87 | + ) |
| 88 | +} |
0 commit comments