Skip to content

Commit a50065a

Browse files
committed
Merge branch 'dev' into translation-banner-logic
2 parents bb42155 + 2be6e65 commit a50065a

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

src/pages/what-is-ethereum.tsx

Lines changed: 48 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 { 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,26 @@ 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 { BasePageProps, ChildOnlyProp, Lang } from "@/lib/types"
19+
import type {
20+
BasePageProps,
21+
ChildOnlyProp,
22+
Lang,
23+
MetricReturnData,
24+
} from "@/lib/types"
2325

2426
import AdoptionChart from "@/components/AdoptionChart"
25-
import { Banner, BannerImage } from "@/components/BannerGrid"
27+
import {
28+
Banner,
29+
BannerBody,
30+
BannerGrid,
31+
BannerGridCell,
32+
BannerImage,
33+
} from "@/components/BannerGrid"
2634
import Button from "@/components/Buttons/Button"
2735
import ButtonLink from "@/components/Buttons/ButtonLink"
2836
import Callout from "@/components/Callout"
@@ -36,17 +44,21 @@ import Text from "@/components/OldText"
3644
import PageMetadata from "@/components/PageMetadata"
3745
import { StandaloneQuizWidget } from "@/components/Quiz/QuizWidget"
3846
import Slider, { EmblaSlide } from "@/components/Slider"
47+
import StatErrorMessage from "@/components/StatErrorMessage"
3948
import Tabs from "@/components/Tabs"
49+
import Tooltip from "@/components/Tooltip"
4050
import Translation from "@/components/Translation"
4151

4252
import { existsNamespace } from "@/lib/utils/existsNamespace"
4353
import { getLastDeployDate } from "@/lib/utils/getLastDeployDate"
4454
import { trackCustomEvent } from "@/lib/utils/matomo"
55+
import { runOnlyOnce } from "@/lib/utils/runOnlyOnce"
4556
import {
4657
getLocaleForNumberFormat,
4758
getRequiredNamespacesForPage,
4859
} from "@/lib/utils/translations"
4960

61+
import { fetchTxCount } from "@/lib/api/fetchTxCount"
5062
import developers from "@/public/developers-eth-blocks.png"
5163
import community from "@/public/enterprise.png"
5264
import diffEthAndBtc from "@/public/eth.png"
@@ -56,7 +68,6 @@ import whatAreSmartContracts from "@/public/infrastructure_transparent.png"
5668
import whoRunsEthereum from "@/public/run-a-node/ethereum-inside.png"
5769
import stats from "@/public/upgrades/newrings.png"
5870
import hero from "@/public/what-is-ethereum.png"
59-
import ogImage from "@/public/what-is-ethereum.png"
6071

6172
const Slogan = (props: ChildOnlyProp) => (
6273
<Text
@@ -164,18 +175,6 @@ const ButtonRow = (props: ChildOnlyProp) => (
164175
<Flex align="center" mt={4} mb={6} wrap="wrap" gap={4} {...props} />
165176
)
166177

167-
// const Stat: React.FC<{ stat: IFetchStat }> = ({ stat }) => {
168-
// const isLoading = !stat.value
169-
170-
// return stat.hasError ? (
171-
// <StatErrorMessage fontSize="1rem" />
172-
// ) : isLoading ? (
173-
// <StatLoadingMessage fontSize="1rem" />
174-
// ) : (
175-
// <>{stat.formattedValue}</>
176-
// )
177-
// }
178-
179178
const NoWrapText = (props: ChildOnlyProp) => (
180179
<Text as="span" whiteSpace="nowrap" {...props} />
181180
)
@@ -184,44 +183,47 @@ const Image400 = ({ src }: Pick<ImageProps, "src">) => (
184183
<Image src={src} alt="" width={400} />
185184
)
186185

186+
const cachedFetchTxCount = runOnlyOnce(fetchTxCount)
187+
188+
type Props = BasePageProps & {
189+
data: MetricReturnData
190+
}
191+
187192
export const getStaticProps = (async ({ locale }) => {
188193
const lastDeployDate = getLastDeployDate()
189194

190195
const requiredNamespaces = getRequiredNamespacesForPage("/what-is-ethereum")
191196

192197
const contentNotTranslated = !existsNamespace(locale!, requiredNamespaces[1])
193198

199+
const data = await cachedFetchTxCount()
200+
194201
return {
195202
props: {
196203
...(await serverSideTranslations(locale!, requiredNamespaces)),
197204
contentNotTranslated,
198205
lastDeployDate,
206+
data,
199207
},
200208
}
201-
}) satisfies GetStaticProps<BasePageProps>
209+
}) satisfies GetStaticProps<Props>
202210

203-
const WhatIsEthereumPage = () => {
211+
const WhatIsEthereumPage = ({
212+
data,
213+
}: InferGetStaticPropsType<typeof getStaticProps>) => {
204214
const { t } = useTranslation(["page-what-is-ethereum", "learn-quizzes"])
205215

206216
const { locale } = useRouter()
217+
const localeForNumberFormat = getLocaleForNumberFormat(locale! as Lang)
218+
219+
const formatNumber = (value: number) =>
220+
new Intl.NumberFormat(localeForNumberFormat, {
221+
notation: "compact",
222+
minimumSignificantDigits: 3,
223+
maximumSignificantDigits: 4,
224+
}).format(value)
207225

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

226228
const cards = [
227229
{
@@ -303,7 +305,7 @@ const WhatIsEthereumPage = () => {
303305
<PageMetadata
304306
title={t("page-what-is-ethereum-meta-title")}
305307
description={t("page-what-is-ethereum-meta-description")}
306-
image={ogImage.src}
308+
image="what-is-ethereum.png"
307309
/>
308310
<Content>
309311
<Flex
@@ -453,11 +455,8 @@ const WhatIsEthereumPage = () => {
453455

454456
<Section>
455457
<Banner>
456-
{/* TODO: Update stats box */}
457-
{/* <BannerBody>
458-
<H2>
459-
{t("page-what-is-ethereum-ethereum-in-numbers-title")}
460-
</H2>
458+
<BannerBody>
459+
<H2>{t("page-what-is-ethereum-ethereum-in-numbers-title")}</H2>
461460
<BannerGrid>
462461
<BannerGridCell>
463462
<StatPrimary>4k+</StatPrimary>
@@ -556,8 +555,9 @@ const WhatIsEthereumPage = () => {
556555
</BannerGridCell>
557556
<BannerGridCell>
558557
<StatPrimary>
559-
<Stat stat={txCount} />
558+
{txStat || <StatErrorMessage fontSize="1rem" />}
560559
</StatPrimary>
560+
{/* TODO: Extract strings for translation */}
561561
<StatDescription>
562562
Number of transactions{" "}
563563
<NoWrapText>
@@ -576,7 +576,7 @@ const WhatIsEthereumPage = () => {
576576
</StatDescription>
577577
</BannerGridCell>
578578
</BannerGrid>
579-
</BannerBody> */}
579+
</BannerBody>
580580
<BannerImage>
581581
<Image400 src={stats} />
582582
</BannerImage>

0 commit comments

Comments
 (0)