=> {
queryKey: "balance",
queryFn: fetchBalance,
onError: error => {
- displayError("Failed to fetch balance", error)
+ showError && displayError("Failed to fetch balance", error)
},
})
}
diff --git a/pages/status.tsx b/pages/status.tsx
new file mode 100644
index 0000000..03a9c2f
--- /dev/null
+++ b/pages/status.tsx
@@ -0,0 +1,130 @@
+import { useFetchBalance, useFetchMetas } from "../lib/ghostcloud"
+import { useEffect, useState } from "react"
+import useWeb3AuthStore from "../store/web3-auth"
+import useOpenLoginSession from "../hooks/useOpenLoginSession"
+import {
+ Box,
+ Card,
+ Container,
+ Flex,
+ Heading,
+ Icon,
+ Spinner,
+ Text,
+ useTheme,
+} from "@chakra-ui/react"
+import { useRouter } from "next/router"
+import { IoIosCheckmarkCircle, IoIosWarning } from "react-icons/io"
+
+interface StatusCardProps {
+ error: boolean
+ msg: string
+}
+
+const StatusCard = ({ error, msg }: StatusCardProps) => {
+ const theme = useTheme()
+
+ return (
+
+
+
+
+
+
+ {msg}
+
+
+
+ )
+}
+
+const Status = () => {
+ const store = useWeb3AuthStore()
+ const isConnected = store.isConnected()
+ const router = useRouter()
+ const [
+ {
+ data: metas,
+ error: metaError,
+ isLoading: isMetaLoading,
+ refetch: refetchMetas,
+ },
+ ] = useFetchMetas(false)
+ const { pagination: { total = 0 } = {} } = metas || {}
+ const [hasMetaError, setHasMetaError] = useState(false)
+ const [hasBalanceError, setHasBalanceError] = useState(false)
+ const [updated, setUpdated] = useState("")
+ const hasSession = useOpenLoginSession()
+ const { error: balanceError } = useFetchBalance(false)
+
+ // Redirect if not logged in
+ useEffect(() => {
+ if (!isMetaLoading && !isConnected && !hasSession) {
+ router.push("/")
+ }
+ }, [isConnected, isMetaLoading, hasSession, router])
+
+ // Ensure that we get metas on refresh once we are connected
+ useEffect(() => {
+ if (hasSession && isConnected && !metas?.meta) {
+ refetchMetas()
+ setUpdated(new Date().toLocaleString())
+ }
+ }, [hasSession, isConnected, metas, refetchMetas])
+
+ useEffect(() => {
+ setUpdated(new Date().toLocaleString())
+ setHasBalanceError(!!balanceError)
+ }, [balanceError])
+
+ useEffect(() => {
+ setUpdated(new Date().toLocaleString())
+ setHasMetaError(!!metaError)
+ }, [metaError])
+
+ if (!hasSession && !isConnected && isMetaLoading) {
+ return (
+
+
+
+ )
+ }
+
+ return (
+
+
+
+
+ System Status
+
+ Last Updated: {updated}
+
+
+
+ {metas?.meta && metas.meta.length > 0 && (
+ 1 ? "s" : ""
+ } Active`
+ }
+ />
+ )}
+
+
+
+ )
+}
+export default Status