import { useState, useEffect } from 'react'; import { QRCodeSVG } from 'qrcode.react'; import { KycApiService } from '../services/kycApiService'; // @ts-ignore - optional dependency, may not be installed in some consumers import { toast, ToastContainer } from 'react-toastify'; // @ts-ignore - import styles only when package is present import 'react-toastify/dist/ReactToastify.css'; import '../index.css'; interface QRCodePageProps { onClose?: () => void; onNavigate?: (view: 'qr' | 'mobileroute') => void; mobileBaseUrl?: string; sessionId?: string; apiBaseUrl?: string; serverKey?: string; } function QRCodePage({ onClose, mobileBaseUrl = 'https://kyc-sdk.astraprotocol.com', sessionId, apiBaseUrl, serverKey }: QRCodePageProps = {}) { const [qrUrl, setQrUrl] = useState(''); const [copied, setCopied] = useState(false); useEffect(() => { // Get search params from current URL const searchParams = new URLSearchParams(window.location.search); // Add required params to query string for mobile route if (sessionId) { searchParams.set('sessionId', sessionId); } if (apiBaseUrl) { searchParams.set('apiBaseUrl', apiBaseUrl); } if (serverKey) { searchParams.set('serverKey', serverKey); } const mobileRoute = '/mobileroute'; const queryString = searchParams.toString(); const fullUrl = `${mobileBaseUrl}${mobileRoute}${queryString ? `?${queryString}` : ''}`; setQrUrl(fullUrl); }, [mobileBaseUrl, sessionId, apiBaseUrl, serverKey]); const handleCopyUrl = async () => { if (qrUrl) { try { await navigator.clipboard.writeText(qrUrl); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch (err) { console.error('Failed to copy:', err); } } }; // const handleClose = () => { // if (onClose) { // onClose(); // } // }; const handleCheckResult = async () => { if (!apiBaseUrl || !sessionId || !serverKey) { toast.warn('Missing configuration to check KYC result.'); return; } try { const svc = new KycApiService({ apiBaseUrl, sessionId, serverKey }); const payload = await svc.getResult(); // support both array and object shapes const first = Array.isArray(payload?.data) ? payload.data.length > 0 ? payload.data[0] : null : payload?.data || null; if (first && (first.kyc_status === 'verified' || first.kyc_status === 'success')) { const redirect = first.redirect_url || first.redirectUrl || null; if (redirect) { window.location.href = redirect; return; } } toast.warn('Please complete your KYC first.'); } catch (error: any) { const msg = error?.message || 'Result fetch failed'; console.error('getResult:error', msg); toast.error(`Result fetch failed: ${msg}`); } }; return ( <>
{/* Background pattern overlay */}
{/* */}

Continue on Mobile

Scan this QR on your phone to capture your face and document

{qrUrl && (
)}

Or open:

{qrUrl}
); } export default QRCodePage;