Skip to content

Commit 2be6e65

Browse files
authored
Merge pull request #235 from ethereum/what-is-ethereum-stats
Enable What is Ethereum stats
2 parents aac0b3c + c24d0cd commit 2be6e65

File tree

1 file changed

+43
-48
lines changed

1 file changed

+43
-48
lines changed

src/pages/what-is-ethereum.tsx

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { GetStaticProps } from "next"
1+
import { GetStaticProps, InferGetStaticPropsType } from "next"
22
import { useRouter } from "next/router"
33
import { SSRConfig, useTranslation } from "next-i18next"
44
import { serverSideTranslations } from "next-i18next/serverSideTranslations"
5+
import { MdInfoOutline } from "react-icons/md"
56
import {
67
Box,
78
type BoxProps,
@@ -10,19 +11,21 @@ import {
1011
type FlexProps,
1112
Heading,
1213
type HeadingProps,
14+
Icon,
1315
ListItem,
1416
UnorderedList,
1517
} from "@chakra-ui/react"
1618

17-
// import { GATSBY_FUNCTIONS_PATH } from "@/lib/constants" // TODO!
18-
// import useFetchStat, {
19-
// defaultFormatter,
20-
// IFetchStat,
21-
// } from "../hooks/useFetchStat" // TODO!
22-
import type { ChildOnlyProp, Lang } from "@/lib/types"
19+
import type { ChildOnlyProp, Lang, MetricReturnData } from "@/lib/types"
2320

2421
import AdoptionChart from "@/components/AdoptionChart"
25-
import { Banner, BannerImage } from "@/components/BannerGrid"
22+
import {
23+
Banner,
24+
BannerBody,
25+
BannerGrid,
26+
BannerGridCell,
27+
BannerImage,
28+
} from "@/components/BannerGrid"
2629
import Button from "@/components/Buttons/Button"
2730
import ButtonLink from "@/components/Buttons/ButtonLink"
2831
import Callout from "@/components/Callout"
@@ -36,16 +39,20 @@ import Text from "@/components/OldText"
3639
import PageMetadata from "@/components/PageMetadata"
3740
import { StandaloneQuizWidget } from "@/components/Quiz/QuizWidget"
3841
import Slider, { EmblaSlide } from "@/components/Slider"
42+
import StatErrorMessage from "@/components/StatErrorMessage"
3943
import Tabs from "@/components/Tabs"
44+
import Tooltip from "@/components/Tooltip"
4045
import Translation from "@/components/Translation"
4146

4247
import { getLastDeployDate } from "@/lib/utils/getLastDeployDate"
4348
import { trackCustomEvent } from "@/lib/utils/matomo"
49+
import { runOnlyOnce } from "@/lib/utils/runOnlyOnce"
4450
import {
4551
getLocaleForNumberFormat,
4652
getRequiredNamespacesForPage,
4753
} from "@/lib/utils/translations"
4854

55+
import { fetchTxCount } from "@/lib/api/fetchTxCount"
4956
import developers from "@/public/developers-eth-blocks.png"
5057
import community from "@/public/enterprise.png"
5158
import diffEthAndBtc from "@/public/eth.png"
@@ -55,7 +62,6 @@ import whatAreSmartContracts from "@/public/infrastructure_transparent.png"
5562
import whoRunsEthereum from "@/public/run-a-node/ethereum-inside.png"
5663
import stats from "@/public/upgrades/newrings.png"
5764
import hero from "@/public/what-is-ethereum.png"
58-
import ogImage from "@/public/what-is-ethereum.png"
5965

6066
const Slogan = (props: ChildOnlyProp) => (
6167
<Text
@@ -163,18 +169,6 @@ const ButtonRow = (props: ChildOnlyProp) => (
163169
<Flex align="center" mt={4} mb={6} wrap="wrap" gap={4} {...props} />
164170
)
165171

166-
// const Stat: React.FC<{ stat: IFetchStat }> = ({ stat }) => {
167-
// const isLoading = !stat.value
168-
169-
// return stat.hasError ? (
170-
// <StatErrorMessage fontSize="1rem" />
171-
// ) : isLoading ? (
172-
// <StatLoadingMessage fontSize="1rem" />
173-
// ) : (
174-
// <>{stat.formattedValue}</>
175-
// )
176-
// }
177-
178172
const NoWrapText = (props: ChildOnlyProp) => (
179173
<Text as="span" whiteSpace="nowrap" {...props} />
180174
)
@@ -183,9 +177,17 @@ const Image400 = ({ src }: Pick<ImageProps, "src">) => (
183177
<Image src={src} alt="" width={400} />
184178
)
185179

180+
const cachedFetchTxCount = runOnlyOnce(fetchTxCount)
181+
182+
type Props = SSRConfig & {
183+
data: MetricReturnData
184+
}
185+
186186
export const getStaticProps = (async (context) => {
187187
const { locale } = context
188188

189+
const data = await cachedFetchTxCount()
190+
189191
// load i18n required namespaces for the given page
190192
const requiredNamespaces = getRequiredNamespacesForPage("/what-is-ethereum")
191193
const lastDeployDate = getLastDeployDate()
@@ -194,32 +196,27 @@ export const getStaticProps = (async (context) => {
194196
props: {
195197
...(await serverSideTranslations(locale!, requiredNamespaces)),
196198
lastDeployDate,
199+
data,
197200
},
198201
}
199-
}) satisfies GetStaticProps<SSRConfig>
202+
}) satisfies GetStaticProps<Props>
200203

201-
const WhatIsEthereumPage = () => {
204+
const WhatIsEthereumPage = ({
205+
data,
206+
}: InferGetStaticPropsType<typeof getStaticProps>) => {
202207
const { t } = useTranslation(["page-what-is-ethereum", "learn-quizzes"])
203208

204209
const { locale } = useRouter()
210+
const localeForNumberFormat = getLocaleForNumberFormat(locale! as Lang)
211+
212+
const formatNumber = (value: number) =>
213+
new Intl.NumberFormat(localeForNumberFormat, {
214+
notation: "compact",
215+
minimumSignificantDigits: 3,
216+
maximumSignificantDigits: 4,
217+
}).format(value)
205218

206-
const localeForStatsBoxNumbers = getLocaleForNumberFormat(locale! as Lang)
207-
208-
// TODO! Fetch txCount from etherscan API
209-
// const txCount = useFetchStat<
210-
// Array<{ unixTimeStamp: string; transactionCount: number }>
211-
// >(
212-
// `${GATSBY_FUNCTIONS_PATH}/txs`,
213-
// (response) => {
214-
// return response
215-
// .map(({ unixTimeStamp, transactionCount }) => ({
216-
// timestamp: parseInt(unixTimeStamp) * 1000, // unix milliseconds
217-
// value: transactionCount,
218-
// }))
219-
// .sort((a, b) => a.timestamp - b.timestamp)
220-
// },
221-
// (value) => defaultFormatter(value, localeForStatsBoxNumbers)
222-
// )
219+
const txStat = "error" in data ? "" : formatNumber(data.value)
223220

224221
const cards = [
225222
{
@@ -301,7 +298,7 @@ const WhatIsEthereumPage = () => {
301298
<PageMetadata
302299
title={t("page-what-is-ethereum-meta-title")}
303300
description={t("page-what-is-ethereum-meta-description")}
304-
image={ogImage.src}
301+
image="what-is-ethereum.png"
305302
/>
306303
<Content>
307304
<Flex
@@ -451,11 +448,8 @@ const WhatIsEthereumPage = () => {
451448

452449
<Section>
453450
<Banner>
454-
{/* TODO: Update stats box */}
455-
{/* <BannerBody>
456-
<H2>
457-
{t("page-what-is-ethereum-ethereum-in-numbers-title")}
458-
</H2>
451+
<BannerBody>
452+
<H2>{t("page-what-is-ethereum-ethereum-in-numbers-title")}</H2>
459453
<BannerGrid>
460454
<BannerGridCell>
461455
<StatPrimary>4k+</StatPrimary>
@@ -554,8 +548,9 @@ const WhatIsEthereumPage = () => {
554548
</BannerGridCell>
555549
<BannerGridCell>
556550
<StatPrimary>
557-
<Stat stat={txCount} />
551+
{txStat || <StatErrorMessage fontSize="1rem" />}
558552
</StatPrimary>
553+
{/* TODO: Extract strings for translation */}
559554
<StatDescription>
560555
Number of transactions{" "}
561556
<NoWrapText>
@@ -574,7 +569,7 @@ const WhatIsEthereumPage = () => {
574569
</StatDescription>
575570
</BannerGridCell>
576571
</BannerGrid>
577-
</BannerBody> */}
572+
</BannerBody>
578573
<BannerImage>
579574
<Image400 src={stats} />
580575
</BannerImage>

0 commit comments

Comments
 (0)