1
- import { GetStaticProps } from "next"
1
+ import { GetStaticProps , InferGetStaticPropsType } from "next"
2
2
import { useRouter } from "next/router"
3
3
import { 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,26 @@ 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 { BasePageProps , ChildOnlyProp , Lang } from "@/lib/types"
19
+ import type {
20
+ BasePageProps ,
21
+ ChildOnlyProp ,
22
+ Lang ,
23
+ MetricReturnData ,
24
+ } from "@/lib/types"
23
25
24
26
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"
26
34
import Button from "@/components/Buttons/Button"
27
35
import ButtonLink from "@/components/Buttons/ButtonLink"
28
36
import Callout from "@/components/Callout"
@@ -36,17 +44,21 @@ import Text from "@/components/OldText"
36
44
import PageMetadata from "@/components/PageMetadata"
37
45
import { StandaloneQuizWidget } from "@/components/Quiz/QuizWidget"
38
46
import Slider , { EmblaSlide } from "@/components/Slider"
47
+ import StatErrorMessage from "@/components/StatErrorMessage"
39
48
import Tabs from "@/components/Tabs"
49
+ import Tooltip from "@/components/Tooltip"
40
50
import Translation from "@/components/Translation"
41
51
42
52
import { existsNamespace } from "@/lib/utils/existsNamespace"
43
53
import { getLastDeployDate } from "@/lib/utils/getLastDeployDate"
44
54
import { trackCustomEvent } from "@/lib/utils/matomo"
55
+ import { runOnlyOnce } from "@/lib/utils/runOnlyOnce"
45
56
import {
46
57
getLocaleForNumberFormat ,
47
58
getRequiredNamespacesForPage ,
48
59
} from "@/lib/utils/translations"
49
60
61
+ import { fetchTxCount } from "@/lib/api/fetchTxCount"
50
62
import developers from "@/public/developers-eth-blocks.png"
51
63
import community from "@/public/enterprise.png"
52
64
import diffEthAndBtc from "@/public/eth.png"
@@ -56,7 +68,6 @@ import whatAreSmartContracts from "@/public/infrastructure_transparent.png"
56
68
import whoRunsEthereum from "@/public/run-a-node/ethereum-inside.png"
57
69
import stats from "@/public/upgrades/newrings.png"
58
70
import hero from "@/public/what-is-ethereum.png"
59
- import ogImage from "@/public/what-is-ethereum.png"
60
71
61
72
const Slogan = ( props : ChildOnlyProp ) => (
62
73
< Text
@@ -164,18 +175,6 @@ const ButtonRow = (props: ChildOnlyProp) => (
164
175
< Flex align = "center" mt = { 4 } mb = { 6 } wrap = "wrap" gap = { 4 } { ...props } />
165
176
)
166
177
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
-
179
178
const NoWrapText = ( props : ChildOnlyProp ) => (
180
179
< Text as = "span" whiteSpace = "nowrap" { ...props } />
181
180
)
@@ -184,44 +183,47 @@ const Image400 = ({ src }: Pick<ImageProps, "src">) => (
184
183
< Image src = { src } alt = "" width = { 400 } />
185
184
)
186
185
186
+ const cachedFetchTxCount = runOnlyOnce ( fetchTxCount )
187
+
188
+ type Props = BasePageProps & {
189
+ data : MetricReturnData
190
+ }
191
+
187
192
export const getStaticProps = ( async ( { locale } ) => {
188
193
const lastDeployDate = getLastDeployDate ( )
189
194
190
195
const requiredNamespaces = getRequiredNamespacesForPage ( "/what-is-ethereum" )
191
196
192
197
const contentNotTranslated = ! existsNamespace ( locale ! , requiredNamespaces [ 1 ] )
193
198
199
+ const data = await cachedFetchTxCount ( )
200
+
194
201
return {
195
202
props : {
196
203
...( await serverSideTranslations ( locale ! , requiredNamespaces ) ) ,
197
204
contentNotTranslated,
198
205
lastDeployDate,
206
+ data,
199
207
} ,
200
208
}
201
- } ) satisfies GetStaticProps < BasePageProps >
209
+ } ) satisfies GetStaticProps < Props >
202
210
203
- const WhatIsEthereumPage = ( ) => {
211
+ const WhatIsEthereumPage = ( {
212
+ data,
213
+ } : InferGetStaticPropsType < typeof getStaticProps > ) => {
204
214
const { t } = useTranslation ( [ "page-what-is-ethereum" , "learn-quizzes" ] )
205
215
206
216
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 )
207
225
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 )
225
227
226
228
const cards = [
227
229
{
@@ -303,7 +305,7 @@ const WhatIsEthereumPage = () => {
303
305
< PageMetadata
304
306
title = { t ( "page-what-is-ethereum-meta-title" ) }
305
307
description = { t ( "page-what-is-ethereum-meta-description" ) }
306
- image = { ogImage . src }
308
+ image = "what-is-ethereum.png"
307
309
/>
308
310
< Content >
309
311
< Flex
@@ -453,11 +455,8 @@ const WhatIsEthereumPage = () => {
453
455
454
456
< Section >
455
457
< 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 >
461
460
< BannerGrid >
462
461
< BannerGridCell >
463
462
< StatPrimary > 4k+</ StatPrimary >
@@ -556,8 +555,9 @@ const WhatIsEthereumPage = () => {
556
555
</ BannerGridCell >
557
556
< BannerGridCell >
558
557
< StatPrimary >
559
- <Stat stat={txCount} />
558
+ { txStat || < StatErrorMessage fontSize = "1rem" /> }
560
559
</ StatPrimary >
560
+ { /* TODO: Extract strings for translation */ }
561
561
< StatDescription >
562
562
Number of transactions{ " " }
563
563
< NoWrapText >
@@ -576,7 +576,7 @@ const WhatIsEthereumPage = () => {
576
576
</ StatDescription >
577
577
</ BannerGridCell >
578
578
</ BannerGrid >
579
- </BannerBody> */ }
579
+ </ BannerBody >
580
580
< BannerImage >
581
581
< Image400 src = { stats } />
582
582
</ BannerImage >
0 commit comments