import React, { useMemo } from "react"; import { useLocation } from "react-router-dom"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons/faTriangleExclamation"; import { faFaucetDrip } from "@fortawesome/free-solid-svg-icons/faFaucetDrip"; import ExternalLink from "./components/ExternalLink"; import ContentFrame from "./ContentFrame"; import StandardFrame from "./StandardFrame"; import StandardSubtitle from "./StandardSubtitle"; import { useChainInfo } from "./useChainInfo"; const Faucets: React.FC = () => { const { network, faucets } = useChainInfo(); const loc = useLocation(); const urls = useMemo(() => { const s = new URLSearchParams(loc.search); const address = s.get("address"); const _urls: string[] = network === "testnet" ? faucets.map((u) => // eslint-disable-next-line no-template-curly-in-string address !== null ? u.replaceAll("${ADDRESS}", address) : u ) : []; // Shuffle faucets to avoid UI bias for (let i = _urls.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [_urls[i], _urls[j]] = [_urls[j], _urls[i]]; } return _urls; }, [network, faucets, loc]); return ( Faucets
{urls.length > 0 && (
The following external links come from https://github.com/ethereum-lists/chains and are *NOT* endorsed by us. Use at your own risk.
)} {/* Display the shuffling notice only if there are 1+ faucets */} {urls.length > 1 && (
The faucet links below are shuffled on page load.
)} {urls.length > 0 ? (
{urls.map((url) => (
{url}
))}
) : (
There are no registered faucets.
)}
); }; export default Faucets;