Skip to content

Commit e546db5

Browse files
committed
refactor: BigNumber pass locale to next-intl/server
add data-labels for selection
1 parent a492e51 commit e546db5

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

app/[locale]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ const Page = async ({ params }: { params: Promise<{ locale: Lang }> }) => {
537537
<p className="mt-8 text-xl font-bold">
538538
{t("page-index-activity-description")}
539539
</p>
540-
<ActivityStats metrics={metrics} />
540+
<ActivityStats metrics={metrics} locale={locale} />
541541

542542
<div className="mt-12 flex justify-center">
543543
<ButtonLink

src/components/ActivityStats/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import BigNumber from "../BigNumber"
44

55
type ActivityStatsProps = {
66
metrics: StatsBoxMetric[]
7+
locale: string
78
}
8-
const ActivityStats = async ({ metrics }: ActivityStatsProps) => {
9+
const ActivityStats = async ({ metrics, locale }: ActivityStatsProps) => {
910
const gridBorderClasses = [
1011
"border-b border-body-light xl:border-e xl:pe-8",
1112
"border-b border-body-light xl:ps-8",
@@ -16,6 +17,7 @@ const ActivityStats = async ({ metrics }: ActivityStatsProps) => {
1617
<div className="grid w-full grid-cols-1 xl:grid-cols-2">
1718
{metrics.map(({ label, apiProvider, apiUrl, state }, idx) => (
1819
<BigNumber
20+
locale={locale}
1921
className={gridBorderClasses[idx]}
2022
key={label}
2123
value={"value" in state ? state.value : undefined}

src/components/BigNumber/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type ReactNode } from "react"
2-
import { useLocale } from "next-intl"
2+
import { getTranslations } from "next-intl/server"
33
import { MdInfoOutline } from "react-icons/md"
44

55
import { cn } from "@/lib/utils/cn"
@@ -8,9 +8,8 @@ import { isValidDate } from "@/lib/utils/date"
88
import Tooltip from "../Tooltip"
99
import Link from "../ui/Link"
1010

11-
import { useTranslation } from "@/hooks/useTranslation"
12-
1311
type BigNumberProps = {
12+
locale: string
1413
children: ReactNode
1514
value?: ReactNode
1615
sourceName?: string
@@ -19,16 +18,16 @@ type BigNumberProps = {
1918
className?: string
2019
}
2120

22-
const BigNumber = ({
21+
const BigNumber = async ({
22+
locale,
2323
children,
2424
value,
2525
sourceName,
2626
sourceUrl,
2727
lastUpdated,
2828
className,
2929
}: BigNumberProps) => {
30-
const { t } = useTranslation("common")
31-
const locale = useLocale()
30+
const t = await getTranslations({ locale, namespace: "common" })
3231
const lastUpdatedDisplay =
3332
lastUpdated && isValidDate(lastUpdated)
3433
? new Intl.DateTimeFormat(locale, {
@@ -37,14 +36,17 @@ const BigNumber = ({
3736
: ""
3837
return (
3938
<div
39+
data-label="big-number"
4040
className={cn(
4141
"flex flex-1 shrink-0 flex-col self-stretch py-8",
4242
className
4343
)}
4444
>
4545
{value ? (
4646
<>
47-
<div className="text-4xl font-bold sm:text-5xl">{value}</div>
47+
<div data-label="value" className="text-4xl font-bold sm:text-5xl">
48+
{value}
49+
</div>
4850
<div className="text-sm">
4951
{children}
5052
{sourceName && sourceUrl && (

src/components/Resources/useResources.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ export const useResources = ({ txCostsMedianUsd }): DashboardSection[] => {
9696
{
9797
title: t("page-resources-network-layer2-title"),
9898
metric: (
99-
<BigNumber className="items-center" value={medianTxCost.value}>
99+
<BigNumber
100+
className="items-center"
101+
value={medianTxCost.value}
102+
locale={locale}
103+
>
100104
Median transaction cost on Ethereum networks
101105
</BigNumber>
102106
),

0 commit comments

Comments
 (0)