1
- import { GetStaticProps } from "next"
1
+ import { GetStaticProps , InferGetStaticPropsType } from "next"
2
2
import { useRouter } from "next/router"
3
3
import { SSRConfig , useTranslation } from "next-i18next"
4
4
import { serverSideTranslations } from "next-i18next/serverSideTranslations"
5
+ import { MdInfoOutline } from "react-icons/md"
5
6
import {
6
7
Box ,
7
8
type BoxProps ,
@@ -10,19 +11,21 @@ import {
10
11
type FlexProps ,
11
12
Heading ,
12
13
type HeadingProps ,
14
+ Icon ,
13
15
ListItem ,
14
16
UnorderedList ,
15
17
} from "@chakra-ui/react"
16
18
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"
23
20
24
21
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"
26
29
import Button from "@/components/Buttons/Button"
27
30
import ButtonLink from "@/components/Buttons/ButtonLink"
28
31
import Callout from "@/components/Callout"
@@ -36,16 +39,20 @@ import Text from "@/components/OldText"
36
39
import PageMetadata from "@/components/PageMetadata"
37
40
import { StandaloneQuizWidget } from "@/components/Quiz/QuizWidget"
38
41
import Slider , { EmblaSlide } from "@/components/Slider"
42
+ import StatErrorMessage from "@/components/StatErrorMessage"
39
43
import Tabs from "@/components/Tabs"
44
+ import Tooltip from "@/components/Tooltip"
40
45
import Translation from "@/components/Translation"
41
46
42
47
import { getLastDeployDate } from "@/lib/utils/getLastDeployDate"
43
48
import { trackCustomEvent } from "@/lib/utils/matomo"
49
+ import { runOnlyOnce } from "@/lib/utils/runOnlyOnce"
44
50
import {
45
51
getLocaleForNumberFormat ,
46
52
getRequiredNamespacesForPage ,
47
53
} from "@/lib/utils/translations"
48
54
55
+ import { fetchTxCount } from "@/lib/api/fetchTxCount"
49
56
import developers from "@/public/developers-eth-blocks.png"
50
57
import community from "@/public/enterprise.png"
51
58
import diffEthAndBtc from "@/public/eth.png"
@@ -55,7 +62,6 @@ import whatAreSmartContracts from "@/public/infrastructure_transparent.png"
55
62
import whoRunsEthereum from "@/public/run-a-node/ethereum-inside.png"
56
63
import stats from "@/public/upgrades/newrings.png"
57
64
import hero from "@/public/what-is-ethereum.png"
58
- import ogImage from "@/public/what-is-ethereum.png"
59
65
60
66
const Slogan = ( props : ChildOnlyProp ) => (
61
67
< Text
@@ -163,18 +169,6 @@ const ButtonRow = (props: ChildOnlyProp) => (
163
169
< Flex align = "center" mt = { 4 } mb = { 6 } wrap = "wrap" gap = { 4 } { ...props } />
164
170
)
165
171
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
-
178
172
const NoWrapText = ( props : ChildOnlyProp ) => (
179
173
< Text as = "span" whiteSpace = "nowrap" { ...props } />
180
174
)
@@ -183,9 +177,17 @@ const Image400 = ({ src }: Pick<ImageProps, "src">) => (
183
177
< Image src = { src } alt = "" width = { 400 } />
184
178
)
185
179
180
+ const cachedFetchTxCount = runOnlyOnce ( fetchTxCount )
181
+
182
+ type Props = SSRConfig & {
183
+ data : MetricReturnData
184
+ }
185
+
186
186
export const getStaticProps = ( async ( context ) => {
187
187
const { locale } = context
188
188
189
+ const data = await cachedFetchTxCount ( )
190
+
189
191
// load i18n required namespaces for the given page
190
192
const requiredNamespaces = getRequiredNamespacesForPage ( "/what-is-ethereum" )
191
193
const lastDeployDate = getLastDeployDate ( )
@@ -194,32 +196,27 @@ export const getStaticProps = (async (context) => {
194
196
props : {
195
197
...( await serverSideTranslations ( locale ! , requiredNamespaces ) ) ,
196
198
lastDeployDate,
199
+ data,
197
200
} ,
198
201
}
199
- } ) satisfies GetStaticProps < SSRConfig >
202
+ } ) satisfies GetStaticProps < Props >
200
203
201
- const WhatIsEthereumPage = ( ) => {
204
+ const WhatIsEthereumPage = ( {
205
+ data,
206
+ } : InferGetStaticPropsType < typeof getStaticProps > ) => {
202
207
const { t } = useTranslation ( [ "page-what-is-ethereum" , "learn-quizzes" ] )
203
208
204
209
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 )
205
218
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 )
223
220
224
221
const cards = [
225
222
{
@@ -301,7 +298,7 @@ const WhatIsEthereumPage = () => {
301
298
< PageMetadata
302
299
title = { t ( "page-what-is-ethereum-meta-title" ) }
303
300
description = { t ( "page-what-is-ethereum-meta-description" ) }
304
- image = { ogImage . src }
301
+ image = "what-is-ethereum.png"
305
302
/>
306
303
< Content >
307
304
< Flex
@@ -451,11 +448,8 @@ const WhatIsEthereumPage = () => {
451
448
452
449
< Section >
453
450
< 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 >
459
453
< BannerGrid >
460
454
< BannerGridCell >
461
455
< StatPrimary > 4k+</ StatPrimary >
@@ -554,8 +548,9 @@ const WhatIsEthereumPage = () => {
554
548
</ BannerGridCell >
555
549
< BannerGridCell >
556
550
< StatPrimary >
557
- <Stat stat={txCount} />
551
+ { txStat || < StatErrorMessage fontSize = "1rem" /> }
558
552
</ StatPrimary >
553
+ { /* TODO: Extract strings for translation */ }
559
554
< StatDescription >
560
555
Number of transactions{ " " }
561
556
< NoWrapText >
@@ -574,7 +569,7 @@ const WhatIsEthereumPage = () => {
574
569
</ StatDescription >
575
570
</ BannerGridCell >
576
571
</ BannerGrid >
577
- </BannerBody> */ }
572
+ </ BannerBody >
578
573
< BannerImage >
579
574
< Image400 src = { stats } />
580
575
</ BannerImage >
0 commit comments