import React from "react"; import { useNavigate } from "react-router-dom"; import { isAddress } from "@ethersproject/address"; import { QrReader } from "@blackbox-vision/react-qr-reader"; import { OnResultFunction } from "@blackbox-vision/react-qr-reader/dist-types/types"; import { BarcodeFormat } from "@zxing/library"; import { Dialog } from "@headlessui/react"; type CameraScannerProps = { turnOffScan: () => void; }; const CameraScanner: React.FC = ({ turnOffScan }) => { const navigate = useNavigate(); const evaluateScan: OnResultFunction = (result, error, codeReader) => { console.log("scan"); if (!error && result?.getBarcodeFormat() === BarcodeFormat.QR_CODE) { const text = result.getText(); console.log(`Scanned: ${text}`); if (!isAddress(text)) { console.warn("Not an ETH address"); return; } navigate(`/search?q=${text}`); turnOffScan(); } }; return (
Point an ETH address QR code to camera
); }; export default CameraScanner;