From ed3586d35c9c61c26c0b3009bf04b67db0948f11 Mon Sep 17 00:00:00 2001 From: Manish Gupta Date: Tue, 23 Jul 2024 13:47:34 -0400 Subject: [PATCH] refactor - new refactor layout group, master context start --- app/(refactor)/refactor/contexts/Master.tsx | 71 +++++++ app/(refactor)/refactor/layout.tsx | 193 ++++++++++++++++++++ app/(refactor)/refactor/page.tsx | 15 ++ app/(refactor)/refactor/providers.tsx | 59 ++++++ 4 files changed, 338 insertions(+) create mode 100644 app/(refactor)/refactor/contexts/Master.tsx create mode 100644 app/(refactor)/refactor/layout.tsx create mode 100644 app/(refactor)/refactor/page.tsx create mode 100644 app/(refactor)/refactor/providers.tsx diff --git a/app/(refactor)/refactor/contexts/Master.tsx b/app/(refactor)/refactor/contexts/Master.tsx new file mode 100644 index 00000000..376b98e0 --- /dev/null +++ b/app/(refactor)/refactor/contexts/Master.tsx @@ -0,0 +1,71 @@ +"use client"; +import { MasterURL } from "@/lib/urls"; +import { MasterResponse } from "@/types/api/MasterResponse"; +import { createContext, useContext, useState } from "react"; +import useSWR from "swr"; + +type MasterContextType = { + data: MasterResponse; + formatMetric: (value: number, unit: string, unitType?: string) => string; +}; + +const MasterContext = createContext({ + data: {} as MasterResponse, + formatMetric: () => "MasterProvider: formatMetric not found", +}); + +export const MasterProvider = ({ children }: { children: React.ReactNode }) => { + const { data, isLoading, error } = useSWR(MasterURL); + + const formatMetric = (value: number, metric: string, unitType: string = "value") => { + + if (metric === "gas_fees_usd") { + metric = "fees"; + unitType = "usd"; + } + + if (!data) { + return `MasterProvider: data not found`; + } + + const metricInfo = data.metrics[metric]; + + if (!metricInfo) { + return `MasterProvider: metricInfo not found: ${metric}`; + } + + const unit = metricInfo.units[unitType]; + + if (!unit) { + return `MasterProvider: unitType not found: ${unitType}`; + } + + const { currency, prefix, suffix, decimals, decimals_tooltip, agg, agg_tooltip } = unit; + + return `${prefix || ""}${value.toLocaleString("en-GB", { + minimumFractionDigits: decimals, + maximumFractionDigits: decimals, + })}${suffix || ""}`; + } + + if (error) return
Failed to load
+ if (!data) return
Loading...
+ + return ( + + {children} + + ); +}; + +export const useMaster = () => { + const ctx = useContext(MasterContext); + + if (!ctx) { + throw new Error("useMaster must be used within a MasterProvider"); + } + + return ctx; +} diff --git a/app/(refactor)/refactor/layout.tsx b/app/(refactor)/refactor/layout.tsx new file mode 100644 index 00000000..8f626c79 --- /dev/null +++ b/app/(refactor)/refactor/layout.tsx @@ -0,0 +1,193 @@ +import { Raleway, Inter, Roboto_Mono } from "next/font/google"; +import { Metadata } from "next"; +import { Graph } from "schema-dts"; +import Head from "../../(layout)/head"; +import "../../background.css"; +import "../../globals.css"; +import { Providers } from "./providers"; +import { MasterProvider } from "./contexts/Master"; + + +const jsonLd: Graph = { + "@context": "https://schema.org", + "@graph": [ + { + "@type": "Organization", + "@id": `https://www.growthepie.xyz/#organization`, + name: "growthepie", + url: "https://www.growthepie.xyz", + logo: "https://www.growthepie.xyz/logo_full.png", + sameAs: [ + "https://twitter.com/growthepie_eth", + "https://mirror.xyz/blog.growthepie.eth", + "https://github.com/growthepie", + ], + }, + { + "@type": "WebSite", + "@id": `https://www.growthepie.xyz/#website`, + url: `https://www.growthepie.xyz/`, + name: "growthepie", + description: + "At growthepie, our mission is to provide comprehensive and accurate analytics of layer 2 solutions for the Ethereum ecosystem, acting as a trusted data aggregator from reliable sources such as L2Beat and DefiLlama, while also developing our own metrics.", + publisher: { + "@type": "Organization", + name: "growthepie", + logo: { + "@type": "ImageObject", + url: `https://www.growthepie.xyz/logo_full.png`, + }, + }, + }, + ], +}; + +// const jsonLdWebSite: WithContext = { +// "@context": "https://schema.org", +// "@type": "WebSite", +// url: "https://www.growthepie.xyz", +// name: "growthepie", +// description: +// "At growthepie, our mission is to provide comprehensive and accurate analytics of layer 2 solutions for the Ethereum ecosystem, acting as a trusted data aggregator from reliable sources such as L2Beat and DefiLlama, while also developing our own metrics.", +// publisher: { +// "@type": "Organization", +// name: "growthepie", +// logo: { +// "@type": "ImageObject", +// url: "https://www.growthepie.xyz/logo_full.png", +// }, +// }, +// }; + +// const jsonLd = [jsonLdOrg, jsonLdWebSite]; +export const viewport = { + width: "device-width", + initialScale: "1.0", + themeColor: "dark", +}; + +const gtpMain = { + title: { + absolute: + "Growing Ethereum’s Ecosystem Together - Layer 2 User Base - growthepie", + template: "%s - growthepie", + }, + description: + "At growthepie, our mission is to provide comprehensive and accurate analytics of layer 2 solutions for the Ethereum ecosystem, acting as a trusted data aggregator from reliable sources such as L2Beat and DefiLlama, while also developing our own metrics.", +}; + +const gtpLabels = { + title: { + absolute: "Ethereum Layer 2 Labels - growthepie", + template: "%s - growthepie", + }, + description: + "Labels for Ethereum Layer 2 solutions - growthepie. A comprehensive list of labels for Ethereum Layer 2 solutions.", +}; + +const isLabels = + process.env.NEXT_PUBLIC_VERCEL_URL && + process.env.NEXT_PUBLIC_VERCEL_URL.includes("labels."); + +const host = isLabels ? "labels.growthepie.xyz" : "www.growthepie.xyz"; + +const title = isLabels ? gtpLabels.title : gtpMain.title; +const description = isLabels ? gtpLabels.description : gtpMain.description; + +export const metadata: Metadata = { + metadataBase: new URL(`https://${host}`), + title, + description, + openGraph: { + title: "growthepie", + description: "Growing Ethereum’s Ecosystem Together", + url: `https://${host}`, + images: [ + { + url: `https://${host}/gtp_og.png`, + width: 1200, + height: 627, + alt: "growthepie.xyz", + }, + ], + locale: "en_US", + type: "website", + }, + twitter: { + card: "summary_large_image", + title: "growthepie.xyz", + description: "Growing Ethereum’s Ecosystem Together", + site: "@growthepie_eth", + siteId: "1636391104689094656", + creator: "@growthepie_eth", + creatorId: "1636391104689094656", + images: [`https://${host}/gtp_og.png`], + }, + robots: { + index: true, + follow: true, + nocache: true, + googleBot: { + index: true, + follow: true, + noimageindex: false, + "max-video-preview": -1, + "max-image-preview": "large", + "max-snippet": -1, + }, + }, +}; + +// If loading a variable font, you don't need to specify the font weight +const raleway = Raleway({ + subsets: ["latin"], + variable: "--font-raleway", + display: "swap", +}); + +const inter = Inter({ + subsets: ["latin"], + variable: "--font-inter", + display: "swap", +}); + +const robotoMono = Roboto_Mono({ + subsets: ["latin"], + variable: "--font-roboto-mono", + display: "swap", +}); + +export default function RootLayout({ + children, +}: { + children: React.ReactNode; +}) { + return ( + + + +
+
+
+
+
+
+