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"
@@ -163,18 +170,6 @@ const ButtonRow = (props: ChildOnlyProp) => (
163
170
< Flex align = "center" mt = { 4 } mb = { 6 } wrap = "wrap" gap = { 4 } { ...props } />
164
171
)
165
172
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
173
const NoWrapText = ( props : ChildOnlyProp ) => (
179
174
< Text as = "span" whiteSpace = "nowrap" { ...props } />
180
175
)
@@ -183,9 +178,17 @@ const Image400 = ({ src }: Pick<ImageProps, "src">) => (
183
178
< Image src = { src } alt = "" width = { 400 } />
184
179
)
185
180
181
+ const cachedFetchTxCount = runOnlyOnce ( fetchTxCount )
182
+
183
+ type Props = SSRConfig & {
184
+ data : MetricReturnData
185
+ }
186
+
186
187
export const getStaticProps = ( async ( context ) => {
187
188
const { locale } = context
188
189
190
+ const data = await cachedFetchTxCount ( )
191
+
189
192
// load i18n required namespaces for the given page
190
193
const requiredNamespaces = getRequiredNamespacesForPage ( "/what-is-ethereum" )
191
194
const lastDeployDate = getLastDeployDate ( )
@@ -194,32 +197,27 @@ export const getStaticProps = (async (context) => {
194
197
props : {
195
198
...( await serverSideTranslations ( locale ! , requiredNamespaces ) ) ,
196
199
lastDeployDate,
200
+ data,
197
201
} ,
198
202
}
199
- } ) satisfies GetStaticProps < SSRConfig >
203
+ } ) satisfies GetStaticProps < Props >
200
204
201
- const WhatIsEthereumPage = ( ) => {
205
+ const WhatIsEthereumPage = ( {
206
+ data,
207
+ } : InferGetStaticPropsType < typeof getStaticProps > ) => {
202
208
const { t } = useTranslation ( [ "page-what-is-ethereum" , "learn-quizzes" ] )
203
209
204
210
const { locale } = useRouter ( )
211
+ const localeForNumberFormat = getLocaleForNumberFormat ( locale ! as Lang )
212
+
213
+ const formatNumber = ( value : number ) =>
214
+ new Intl . NumberFormat ( localeForNumberFormat , {
215
+ notation : "compact" ,
216
+ minimumSignificantDigits : 3 ,
217
+ maximumSignificantDigits : 4 ,
218
+ } ) . format ( value )
205
219
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
- // )
220
+ const txStat = "error" in data ? "" : formatNumber ( data . value )
223
221
224
222
const cards = [
225
223
{
@@ -451,11 +449,8 @@ const WhatIsEthereumPage = () => {
451
449
452
450
< Section >
453
451
< Banner >
454
- { /* TODO: Update stats box */ }
455
- { /* <BannerBody>
456
- <H2>
457
- {t("page-what-is-ethereum-ethereum-in-numbers-title")}
458
- </H2>
452
+ < BannerBody >
453
+ < H2 > { t ( "page-what-is-ethereum-ethereum-in-numbers-title" ) } </ H2 >
459
454
< BannerGrid >
460
455
< BannerGridCell >
461
456
< StatPrimary > 4k+</ StatPrimary >
@@ -554,8 +549,9 @@ const WhatIsEthereumPage = () => {
554
549
</ BannerGridCell >
555
550
< BannerGridCell >
556
551
< StatPrimary >
557
- <Stat stat={txCount} />
552
+ { txStat || < StatErrorMessage fontSize = "1rem" /> }
558
553
</ StatPrimary >
554
+ { /* TODO: Extract strings for translation */ }
559
555
< StatDescription >
560
556
Number of transactions{ " " }
561
557
< NoWrapText >
@@ -574,7 +570,7 @@ const WhatIsEthereumPage = () => {
574
570
</ StatDescription >
575
571
</ BannerGridCell >
576
572
</ BannerGrid >
577
- </BannerBody> */ }
573
+ </ BannerBody >
578
574
< BannerImage >
579
575
< Image400 src = { stats } />
580
576
</ BannerImage >
0 commit comments