diff --git a/apps/frontend/app/numeric-event/page.tsx b/apps/frontend/app/numeric-event/page.tsx new file mode 100644 index 0000000..bbfb98f --- /dev/null +++ b/apps/frontend/app/numeric-event/page.tsx @@ -0,0 +1,61 @@ +'use client'; + +import { useState, useEffect } from 'react'; +import { useRouter } from 'next/navigation'; +import { getNumericEvent as fetchNumericEvent } from '@/lib/oracle'; +import { checkMetamaskLogin } from '@/lib/metamask'; + +export default function NumberEventPage() { + const router = useRouter(); + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + const checkLogin = async () => { + const isLoggedIn = await checkMetamaskLogin(); + if (!isLoggedIn) { + router.push('/login'); // redirect to login page + } else { + setIsLoading(false); // Metamask login is complete + } + }; + + checkLogin(); + }, [router]); + + const [event, setEvent] = useState(''); + + const fetchData = async () => { + const metamaskAccount = window.ethereum.selectedAddress; + try { + const eventContent = await fetchNumericEvent(metamaskAccount || ''); + setEvent(eventContent); + } catch (error) { + console.error('發生錯誤:', error); + } + }; + + if (isLoading) return null; // wait for Metamask login to complete + + return ( +
+
+

Numeric Event

+
+
+ +
+
+ {event && ( +

+ {event} +

+ )} +
+
+ ); +} diff --git a/apps/frontend/app/string-event/page.tsx b/apps/frontend/app/string-event/page.tsx index f15255b..a5db67a 100644 --- a/apps/frontend/app/string-event/page.tsx +++ b/apps/frontend/app/string-event/page.tsx @@ -24,7 +24,6 @@ export default function StringEventPage() { const [event, setEvent] = useState(''); - const fetchData = async () => { const metamaskAccount = window.ethereum.selectedAddress; try {