import React, { useContext, useState, useEffect } from "react"; import { useParams } from "react-router-dom"; import { Spinner } from "react-bootstrap"; import { NetworkContext } from "src/services/network/networkProvider"; import { isValidAddr } from "src/utils/Utils"; import AccountDetailsPage from "./AccountDetailsPage/AccountDetailsPage"; import ContractDetailsPage from "./ContractDetailsPage/ContractDetailsPage"; import NotFoundPage from "../../ErrorPages/NotFoundPage"; const AddressDetailsPage: React.FC = () => { const { addr } = useParams<{ addr: string }>(); const networkContext = useContext(NetworkContext); if (!networkContext) { return (
); } const { dataService } = networkContext; const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [isContract, setIsContract] = useState(null); // Fetch data useEffect(() => { if (!dataService) return; let isContractRes: boolean; const getData = async () => { try { setIsLoading(true); isContractRes = await dataService.isContractAddr(addr); setIsContract(isContractRes); } catch (e) { console.log(e); if (isValidAddr(addr)) { setIsContract(false); } else { // TODO: Type of error is unknown and not necessarily compatible // with strings setError("Error occurred - please see console"); console.error(e); // setError(e); } } finally { setIsLoading(false); } }; getData(); return () => { setIsContract(null); setError(null); }; }, [addr, dataService]); return ( <> {isLoading ? (
) : null} {error ? ( ) : ( <> {isContract !== null ? ( isContract ? ( ) : ( ) ) : null} )} ); }; export default AddressDetailsPage;