Skip to content

Commit

Permalink
WIP: Landing page overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
manishiwa committed Sep 12, 2023
1 parent 753add4 commit bf7d80a
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/fundamentals/[metric]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MetricsResponse } from "@/types/api/MetricsResponse";
import Heading from "@/components/layout/Heading";
import Subheading from "@/components/layout/Subheading";
import ComparisonChart from "@/components/layout/ComparisonChart";
import { useSessionStorage } from "usehooks-ts";
import { useLocalStorage, useSessionStorage } from "usehooks-ts";
import useSWR from "swr";
import MetricsTable from "@/components/layout/MetricsTable";
import { MetricsURLs } from "@/lib/urls";
Expand All @@ -18,7 +18,7 @@ import Container from "@/components/layout/Container";
import ShowLoading from "@/components/layout/ShowLoading";

const Chain = ({ params }: { params: any }) => {
const [showUsd, setShowUsd] = useSessionStorage("showUsd", true);
const [showUsd, setShowUsd] = useLocalStorage("showUsd", true);
const [errorCode, setErrorCode] = useState<number | null>(null);

const {
Expand Down
107 changes: 103 additions & 4 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import LoadingAnimation from "@/components/layout/LoadingAnimation";
import { useSessionStorage } from "usehooks-ts";
import Container from "@/components/layout/Container";
import ShowLoading from "@/components/layout/ShowLoading";
import ChainComponent from "@/components/charts/ChainComponent";
import { ChainURLs, BlockspaceURLs } from "@/lib/urls";
import ContractCard from "@/components/layout/ContractCard";
import { ChainResponse } from "@/types/api/ChainResponse";
import { ChainOverviewResponse } from "@/types/api/ChainOverviewResponse";

export default function Home() {
const isLargeScreen = useMediaQuery("(min-width: 768px)");
Expand All @@ -43,6 +48,20 @@ export default function Home() {
isValidating: masterValidating,
} = useSWR<MasterResponse>(MasterURL);

const {
data: chainData,
error: chainError,
isValidating: chainValidating,
isLoading: chainLoading,
} = useSWR<ChainResponse>(ChainURLs["arbitrum"]);

const {
data: blockspaceData,
error: blockspaceError,
isValidating: blockspaceValidating,
isLoading: blockspaceLoading,
} = useSWR<any>(BlockspaceURLs["chain-overview"]);

const [data, setData] = useState<any>(null);

const [selectedTimeInterval, setSelectedTimeInterval] = useState("weekly");
Expand Down Expand Up @@ -83,15 +102,64 @@ export default function Home() {
/>
{/* )} */}
<Container className="flex flex-col flex-1 w-full mt-[65px]">
<Heading className="font-bold text-[30px] leading-snug md:text-[36px] mb-[28px] lg:mb-[30px]">
Growing Ethereum’s Ecosystem Together
<Heading className="font-bold text-[30px] leading-snug md:text-[36px] mb-[28px] lg:mb-[30px] max-w-[900px]">
Mastering Ethereum Layer-2s: Your Gateway to Curated Analytics and
Knowledge
</Heading>
{data && landing && master && <TopAnimation />}
</Container>
<Container className="flex flex-col flex-1 w-full">
<div className="flex space-x-2 mt-[30px] items-center">
<Icon
icon="gtp:fundamentals"
className="w-[30px] h-[30px] md:w-9 md:h-9"
/>
<Heading className="text-[20px] md:text-[30px] leading-snug font-bold">
Most Recent Metrics
</Heading>
</div>
</Container>
{chainData && (
<Container className="mt-[30px] relative">
<div className="grid grid-flow-col grid-rows-1 grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-x-[10px] overflow-y-hidden overflow-x-hidden 2xl:overflow-x-hidden w-full p-0 pb-9 scrollbar-thin scrollbar-thumb-forest-900 scrollbar-track-forest-500/5 scrollbar-thumb-rounded-full scrollbar-track-rounded-full">
<ChainComponent
data={chainData.data}
chain={"arbitrum"}
category={"txcount"}
selectedTimespan={"90d"}
selectedScale="linear"
/>
<ChainComponent
data={chainData.data}
chain={"arbitrum"}
category={"stables_mcap"}
selectedTimespan={"90d"}
selectedScale="linear"
/>
<ChainComponent
data={chainData.data}
chain={"arbitrum"}
category={"fees"}
selectedTimespan={"90d"}
selectedScale="linear"
/>
</div>
<div className="absolute bottom-2 2xl:bottom-2 left-[40px] md:left-[70px]">
<Link
className="flex space-x-2 items-center"
href="/chains/arbitrum"
>
Compare <Icon icon="feather:chevron-right" className="w-6 h-6" />{" "}
</Link>
</div>
</Container>
)}
<Container className="flex flex-col flex-1 w-full">
{/* {data && landing && master && <TopAnimation />} */}
{/* <Subheading className="text-sm leading-snug">
Compare Ethereum&apos;s Layer-2 solutions and better understand
the metrics to grow the ecosystem.
</Subheading> */}
<div className="flex mt-0 lg:mt-[100px] mb-[25px] md:mb-[32px] space-x-2 items-center">
<div className="flex mt-[25px] lg:mt-[70px] mb-[25px] md:mb-[32px] space-x-2 items-center">
<Icon
icon="gtp:gtp-pie"
className="w-[30px] h-[30px] md:w-9 md:h-9"
Expand Down Expand Up @@ -143,6 +211,37 @@ export default function Home() {
</Container>
</>
)}
<Container className="flex flex-col flex-1 w-full">
<div className="flex space-x-2 mt-[30px] items-center">
<Icon
icon="gtp:package"
className="w-[30px] h-[30px] md:w-9 md:h-9"
/>
<Heading className="text-[20px] md:text-[30px] leading-snug font-bold">
Blockspace
</Heading>
</div>
<Subheading className="text-base leading-normal md:leading-snug mt-[30px] mb-[15px] px-[5px] lg:px-[45px]">
Top 6 gas-consuming contracts across all tracked Layer-2s.
</Subheading>
{blockspaceData && (
<div className="grid grid-rows-6 grid-cols-1 lg:grid-rows-3 lg:grid-cols-2 xl:grid-rows-2 xl:grid-cols-3 gap-x-[10px] gap-y-[15px]">
{new Array(6).fill(0).map((_, i) => (
<ContractCard
key={i}
data={
blockspaceData.data.chains.all_l2s.overview.max.defi.contracts
.data[i]
}
types={
blockspaceData.data.chains.all_l2s.overview.max.defi.contracts
.types
}
/>
))}
</div>
)}
</Container>
<Container>
<div className="flex gap-x-0 md:gap-x-12 w-full ml-0 mt-[15px] md:mt-[90px]">
<div className="flex flex-col md:w-1/2 lg:w-2/3">
Expand Down
6 changes: 3 additions & 3 deletions components/charts/ChainComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ export default function ChainComponent({

return (
<div key={category} className="w-full h-fit relative">
<div className="w-[431px] h-[176px] relative">
<div className="w-full h-[176px] relative">
<div className="absolute w-full h-full bg-forest-50 dark:bg-[#1F2726] rounded-[15px]"></div>
<div className="absolute w-full h-[142px] top-[49px]">
<HighchartsReact
Expand Down Expand Up @@ -1043,7 +1043,7 @@ export default function ChainComponent({
</div>
</div>

{!zoomed
{/* {!zoomed
? (category === "stables_mcap" || category === "txcosts") && (
<div
className={`w-full h-[15px] absolute -bottom-[15px] text-[10px] text-forest-600/80 dark:text-forest-500/80 ${
Expand Down Expand Up @@ -1098,7 +1098,7 @@ export default function ChainComponent({
})}
</div>
</div>
)}
)} */}
</div>
);
}
10 changes: 5 additions & 5 deletions components/layout/ChainChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ export default function ChainChart({

{data && (
<div
className="grid grid-rows-8 lg:grid-rows-4 lg:grid-cols-2 lg:grid-flow-col gap-y-0 gap-x-[15px]"
className="grid grid-rows-8 lg:grid-rows-4 lg:grid-cols-2 lg:grid-flow-row gap-y-0 gap-x-[15px]"
// style={{
// gridRow: `span ${Math.ceil(enabledFundamentalsKeys.length / 2)}`,
// }}
Expand Down Expand Up @@ -1149,7 +1149,7 @@ export default function ChainChart({
<div className="absolute right-[15px] h-[15px] border-r border-forest-500 dark:border-forest-600 pr-0.5 align-bottom flex items-end"></div>
</div>
{!zoomed
? (key === "stables_mcap" || key === "txcosts") && (
? (key === "profit" || key === "txcosts") && (
<div
className={`w-full h-[15px] absolute -bottom-[15px] text-[10px] text-forest-600/80 dark:text-forest-500/80 ${
key === "txcosts" ? "hidden lg:block" : ""
Expand Down Expand Up @@ -1177,7 +1177,7 @@ export default function ChainChart({
</div>
</div>
)
: (key === "stables_mcap" || key === "txcosts") &&
: (key === "profit" || key === "txcosts") &&
intervalShown && (
<div
className={`w-full h-[15px] absolute -bottom-[15px] text-[10px] text-forest-600/80 dark:text-forest-500/80 ${
Expand Down Expand Up @@ -1399,7 +1399,7 @@ export default function ChainChart({
<div className="absolute right-[15px] h-[15px] border-r border-forest-500 dark:border-forest-600 pr-0.5 align-bottom flex items-end"></div>
</div>
{!zoomed
? (key === "stables_mcap" || key === "txcosts") && (
? (key === "profit" || key === "txcosts") && (
<div
className={`w-full h-[15px] absolute -bottom-[15px] text-[10px] text-forest-600/80 dark:text-forest-500/80 ${
key === "txcosts" ? "hidden lg:block" : ""
Expand Down Expand Up @@ -1427,7 +1427,7 @@ export default function ChainChart({
</div>
</div>
)
: (key === "stables_mcap" || key === "txcosts") &&
: (key === "profit" || key === "txcosts") &&
intervalShown && (
<div
className={`w-full h-[15px] absolute -bottom-[15px] text-[10px] text-forest-600/80 dark:text-forest-500/80 ${
Expand Down
147 changes: 147 additions & 0 deletions components/layout/ContractCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
"use client";

import HighchartsReact from "highcharts-react-official";
import Highcharts from "highcharts";
import highchartsAnnotations from "highcharts/modules/annotations";

import {
useState,
useEffect,
useMemo,
useRef,
useCallback,
useLayoutEffect,
} from "react";
import { useLocalStorage, useWindowSize, useIsMounted } from "usehooks-ts";
import fullScreen from "highcharts/modules/full-screen";
import _merge from "lodash/merge";
import { useTheme } from "next-themes";
import { Icon } from "@iconify/react";
import Image from "next/image";
import d3 from "d3";
import { AllChainsByKeys } from "@/lib/chains";
import { debounce, forEach } from "lodash";

import { navigationItems } from "@/lib/navigation";
import { useUIContext } from "@/contexts/UIContext";
import { useMediaQuery } from "usehooks-ts";
import ChartWatermark from "@/components/layout/ChartWatermark";
import { ChainsData } from "@/types/api/ChainResponse";

const COLORS = {
GRID: "rgb(215, 223, 222)",
PLOT_LINE: "rgb(215, 223, 222)",
LABEL: "rgb(215, 223, 222)",
LABEL_HOVER: "#6c7696",
TOOLTIP_BG: "#1b2135",
ANNOTATION_BG: "rgb(215, 223, 222)",
};

type ContractInfo = {
address: string;
project_name: string;
name: string;
main_category_key: string;
sub_category_key: string;
chain: string;
gas_fees_absolute_eth: number;
gas_fees_absolute_usd: number;
gas_fees_share: number;
txcount_absolute: number;
txcount_share: number;
};

export default function ContractCard({
data,
types,
}: {
data: any[];
types: string[];
}) {
const { theme } = useTheme();

const [showUsd, setShowUsd] = useLocalStorage("showUsd", true);

return (
<div className="group flex flex-col px-[22px] py-[14px] rounded-[15px] bg-forest-50 dark:bg-[#1F2726] hover:cursor-pointer hover:bg-forest-100 hover:dark:bg-forest-800">
<div className="flex flex-row justify-between items-center w-full">
<div className="flex flex-row items-center">
<div className="flex flex-col">
<div className="flex items-center space-x-1.5">
<div className="relative">
{/* <div
className={`w-[22px] h-[22px] rounded-full ${
AllChainsByKeys[data.chain].backgrounds[
theme === "dark" ? "light" : "dark"
][1]
}`}
></div> */}
<Icon
icon={`gtp:${data[types.indexOf("chain")].replace(
"_",
"-",
)}-logo-monochrome`}
className="w-5 h-5 text-white"
style={{
color:
AllChainsByKeys[data[types.indexOf("chain")]].colors[
theme
][0],
}}
/>
</div>
<div className="break-inside-avoid text-xs md:text-sm">
{AllChainsByKeys[data[types.indexOf("chain")]].label}
</div>
</div>
</div>
</div>
<div className="flex flex-row items-center space-x-1 text-sm">
<>
{showUsd ? (
<>
<div>$</div>
<div>
{Intl.NumberFormat(undefined, {
maximumFractionDigits: 2,
minimumFractionDigits: 2,
}).format(data[types.indexOf("gas_fees_absolute_usd")])}
</div>
</>
) : (
<>
<div>Ξ</div>
<div>
{Intl.NumberFormat(undefined, {
maximumFractionDigits: 2,
minimumFractionDigits: 2,
}).format(data[types.indexOf("gas_fees_absolute_eth")])}{" "}
ETH
</div>
</>
)}
</>
</div>
</div>
<div className="w-full text-[30px] font-bold">
{data[types.indexOf("project_name")]}
</div>
<div className="flex flex-row justify-between items-center w-full">
<div className="flex flex-row items-center space-x-1 text-xs md:text-sm">
<div className="flex flex-row items-center space-x-1">
{data[types.indexOf("main_category_key")]} &gt;{" "}
{data[types.indexOf("sub_category_key")]}
</div>
</div>
<Icon
icon="feather:info"
className="w-6 h-6 block group-hover:hidden"
/>
<Icon
icon="feather:chevron-right"
className="w-6 h-6 hidden group-hover:block"
/>
</div>
</div>
);
}
4 changes: 2 additions & 2 deletions components/layout/LandingChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Highcharts, {
AxisLabelsFormatterContextObject,
} from "highcharts/highstock";
import { useState, useEffect, useMemo, useRef, useCallback } from "react";
import { useSessionStorage } from "usehooks-ts";
import { useLocalStorage, useSessionStorage } from "usehooks-ts";
import { useTheme } from "next-themes";
import { merge } from "lodash";
import { Switch } from "../Switch";
Expand Down Expand Up @@ -218,7 +218,7 @@ export default function LandingChart({

const { theme } = useTheme();

const [showUsd, setShowUsd] = useSessionStorage("showUsd", true);
const [showUsd, setShowUsd] = useLocalStorage("showUsd", true);

const [selectedTimespan, setSelectedTimespan] = useState("max");

Expand Down

0 comments on commit bf7d80a

Please sign in to comment.