From cb655b2d2febc9aba69aa44740d6b03aee1f84e2 Mon Sep 17 00:00:00 2001 From: salviega Date: Sun, 24 Sep 2023 06:04:19 -0500 Subject: [PATCH] :zap: Was added dynamic routing --- src/components/home/Events.tsx | 4 +++- src/functions/dto/index.ts | 17 +++++++++++++++++ src/pages/events/[id]/index.tsx | 14 ++++++++------ src/pages/index.tsx | 12 ------------ 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/components/home/Events.tsx b/src/components/home/Events.tsx index 9029b25..f824955 100644 --- a/src/components/home/Events.tsx +++ b/src/components/home/Events.tsx @@ -19,6 +19,8 @@ export default function Events(props: Props): React.ReactNode { const { isLoading } = props const { t } = useTranslation() + const eventId: string = 'mC8cCmWH5Ws8IZQy' + return ( <> (initialEvent) const [isBuyTicketLoading, setIsBuyTicketLoading] = useState(false) - const [hasTicket, setHasTicket] = useState(false) const [isLoading, setIsLoading] = useState(true) + const [hasTicket, setHasTicket] = useState(false) const [meetdAppEventContract, setMeetdAppEventContract] = useState(null) const [owner, setOwner] = useState(undefined) @@ -49,7 +49,8 @@ function Event(): JSX.Element { const router = useRouter() // TODO: generate nanoId - const slug: string | string[] | undefined = router.query?.id + const splitedPath: string[] = router.asPath.split('/') + const id = splitedPath[splitedPath.length - 1] const { address } = useAccount() const { chain } = useNetwork() @@ -124,7 +125,7 @@ function Event(): JSX.Element { } const fetchEventInformation = async () => { - setTimeout(async () => { + try { const rpcProvider: ethers.providers.JsonRpcProvider = new ethers.providers.JsonRpcProvider(PROVIDER) @@ -134,8 +135,7 @@ function Event(): JSX.Element { rpcProvider ) as MeetdAppFactory - const eventId: string = 'mC8cCmWH5Ws8IZQy' - const bytesEventId = ethers.utils.toUtf8Bytes(eventId) + const bytesEventId = ethers.utils.toUtf8Bytes(id as string) const hashBytes32EventId = ethers.utils.keccak256(bytesEventId) const eventContractAdress: string = @@ -172,7 +172,9 @@ function Event(): JSX.Element { setMeetdAppEventContract(eventContract) setIsLoading(false) - }, 1000) + } catch (error) { + router.push('/404') + } } useEffect(() => { diff --git a/src/pages/index.tsx b/src/pages/index.tsx index a49dbe9..bf8e082 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -32,18 +32,6 @@ export default function Home() { useEffect(() => { fetchActiveEvents() - // const ethereum = (window as any).ethereum - - // if ( - // typeof ethereum !== 'undefined' && - // typeof ethereum === 'object' && - // typeof ethereum.web3 !== 'undefined' - // ) { - // // MetaMask is installed and web3 is available - // } else { - // // MetaMask is not installed or web3 is not available - // console.log('MetaMask no está instalado en este navegador.') - // } }, []) return (