import React, { useState, useRef, useContext } from "react"; import { isAddress } from "@ethersproject/address"; import { Link, useHistory } from "react-router-dom"; 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 { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faQrcode } from "@fortawesome/free-solid-svg-icons/faQrcode"; import { Dialog } from "@headlessui/react"; import useKeyboardShortcut from "use-keyboard-shortcut"; import PriceBox from "./PriceBox"; import { RuntimeContext } from "./useRuntime"; const Title: React.FC = () => { const { provider } = useContext(RuntimeContext); const [search, setSearch] = useState(); const [canSubmit, setCanSubmit] = useState(false); const history = useHistory(); const handleChange: React.ChangeEventHandler = (e) => { setCanSubmit(e.target.value.trim().length > 0); setSearch(e.target.value.trim()); }; const handleSubmit: React.FormEventHandler = (e) => { e.preventDefault(); if (!canSubmit) { return; } history.push(`/search?q=${search}`); }; const searchRef = useRef(null); useKeyboardShortcut(["/"], () => { searchRef.current?.focus(); }); const [isScanning, setScanning] = useState(false); const onScan = () => { setScanning(true); }; 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.log("Not an ETH address"); return; } history.push(`/search?q=${text}`); setScanning(false); } }; return ( <> setScanning(false)} >
Point an ETH address QR code to camera
An otter scanning Otterscan
{provider?.network.chainId === 1 && }
); }; export default React.memo(Title);