'use client'; import React, { useState, useRef } from 'react'; import Link from 'next/link'; import { QRCodeSVG } from 'qrcode.react'; import { Bitcoin, Download, Check, Sparkles, Wallet, } from 'lucide-react'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { Select } from '@/components/ui/Select'; import { cn } from '@/lib/utils'; // Brand Colors const BRAND = { paleGrey: '#EBEBDF', richBlue: '#1A1265', richBlueLight: '#2A2275', }; // Crypto Options const CRYPTO_CURRENCIES = [ { value: 'bitcoin', label: 'Bitcoin (BTC)', color: '#F7931A', prefix: 'bitcoin:' }, { value: 'ethereum', label: 'Ethereum (ETH)', color: '#627EEA', prefix: 'ethereum:' }, { value: 'usdt', label: 'Tether (USDT)', color: '#26A17B', prefix: '' }, // Commonly ERC20/TRC20 - keeping raw for safety { value: 'solana', label: 'Solana (SOL)', color: '#14F195', prefix: 'solana:' }, ]; // QR Color Options const QR_COLORS = [ { name: 'Bitcoin Orange', value: '#F7931A' }, { name: 'Ethereum Blue', value: '#627EEA' }, { name: 'Tether Green', value: '#26A17B' }, { name: 'Classic Black', value: '#000000' }, { name: 'Dark Blue', value: '#1A1265' }, { name: 'Emerald', value: '#10B981' }, { name: 'Rose', value: '#F43F5E' }, ]; // Frame Options const FRAME_OPTIONS = [ { id: 'none', label: 'No Frame' }, { id: 'scanme', label: 'Scan Me' }, { id: 'pay', label: 'Pay Now' }, { id: 'donate', label: 'Donate' }, ]; export default function CryptoGenerator() { const [currency, setCurrency] = useState('bitcoin'); const [address, setAddress] = useState(''); const [amount, setAmount] = useState(''); const [qrMode, setQrMode] = useState<'universal' | 'wallet'>('universal'); const [qrColor, setQrColor] = useState('#F7931A'); const [frameType, setFrameType] = useState('none'); const qrRef = useRef(null); // Generate URL based on selected mode const getUrl = () => { if (!address.trim()) return 'https://www.qrmaster.net'; const cleanAddr = address.trim(); if (qrMode === 'wallet') { // Wallet Direct Mode - Uses crypto URI scheme // Only works when scanning FROM a wallet app (Coinbase, Trust Wallet, etc.) const prefixes: Record = { bitcoin: 'bitcoin:', ethereum: 'ethereum:', solana: 'solana:', usdt: '', // USDT doesn't have a standard URI }; const prefix = prefixes[currency] || ''; if (!prefix) return cleanAddr; // USDT fallback let uri = `${prefix}${cleanAddr}`; if (amount) uri += `?amount=${amount}`; return uri; } else { // Universal Mode - Blockchain explorer links // Works with ANY phone camera switch (currency) { case 'bitcoin': return `https://blockchair.com/bitcoin/address/${cleanAddr}`; case 'ethereum': return `https://etherscan.io/address/${cleanAddr}`; case 'solana': return `https://solscan.io/account/${cleanAddr}`; case 'usdt': return `https://etherscan.io/token/0xdac17f958d2ee523a2206206994597c13d831ec7?a=${cleanAddr}`; default: return cleanAddr; } } }; const handleDownload = async (format: 'png' | 'svg') => { if (!qrRef.current) return; try { if (format === 'png') { const { toPng } = await import('html-to-image'); const dataUrl = await toPng(qrRef.current, { cacheBust: true, pixelRatio: 3 }); const link = document.createElement('a'); link.download = `${currency}-qr-code.png`; link.href = dataUrl; link.click(); } else { const svgData = qrRef.current.querySelector('svg')?.outerHTML; if (svgData) { const blob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = `${currency}-qr-code.svg`; link.click(); } } } catch (err) { console.error('Download failed', err); } }; const getFrameLabel = () => { const frame = FRAME_OPTIONS.find(f => f.id === frameType); return frame?.id !== 'none' ? frame?.label : null; }; return (
{/* Main Generator Card */}
{/* LEFT: Input Section */}
{/* Crypto Details */}

Wallet Details

setAddress(e.target.value)} className="h-12 text-base rounded-xl border-slate-200 focus:border-slate-900 focus:ring-slate-900 font-mono text-sm" />
setAmount(e.target.value)} className="h-12 text-base rounded-xl border-slate-200 focus:border-slate-900 focus:ring-slate-900" />
{/* QR Mode Toggle */}

{qrMode === 'universal' ? "Works with any phone camera. Opens blockchain explorer." : "Requires scanning from a wallet app. Enables direct payment."}

{/* Design Options */}

Design Options

{/* Color Picker */}
{QR_COLORS.map((c) => ( ))}
{/* Frame Selector */}
{FRAME_OPTIONS.map((frame) => ( ))}
{/* RIGHT: Preview Section */}
{/* QR Card with Frame */}
{/* Frame Label */} {getFrameLabel() && (
{getFrameLabel()}
)} {/* QR Code */}
{address.trim() ? ( ) : (

Enter wallet address

to generate QR code

)}
{/* Info Preview */}

{currency}

{address || 'Wallet Address'}
{/* Download Buttons */}

Scanning copies the wallet address or opens a crypto app.

{/* Upsell Banner */}

Accept Crypto for Business?

Create professional, branded payment pages for your store.

); }