SkateSpots/src/lib/wallet/qrCodeGenerator.ts
shakespeare.diy ebbf2d6326 fix: remove orphaned canvas code from RiderCardPage causing ctx/Printer is not defined crash
The drawCardToCanvas function had an old version of the card rendering logic
that leaked outside the function body (lines 505-731 were orphaned code).
This code referenced local variables (ctx, p, data, qrX, qrSize, PAD, etc.)
that only existed inside the function, causing ReferenceError at module load time
and crashing the entire app with a blank screen.

Also added missing lucide-react imports (Printer, Loader2, Share2, Download,
Check, Copy, Award, Zap, Info, Palette, Shield, ChevronUp, ChevronDown) that
were used in the JSX but not imported, causing the secondary Printer is not
defined ReferenceError.

Co-authored-by: shakespeare.diy <assistant@shakespeare.diy>
2026-06-16 17:02:59 +07:00

24 lines
688 B
TypeScript

/**
* Generate a QR code data URL from text
* qrcode imported lazily to avoid canvas crash at module load
* @param text - Text to encode in QR code
* @returns Promise resolving to data URL
*/
export async function generateQRCode(text: string): Promise<string> {
try {
const { default: QRCode } = await import('qrcode');
const dataUrl = await QRCode.toDataURL(text, {
width: 300,
margin: 2,
color: {
dark: '#000000',
light: '#FFFFFF',
},
errorCorrectionLevel: 'M',
});
return dataUrl;
} catch (err) {
console.error('[QR] Failed to generate QR code:', err);
throw new Error('Failed to generate QR code');
}
}