Skip to content

Commit 104c49c

Browse files
committed
refactor: use getLocale from next/server
avoid prop drilling locale
1 parent 003e609 commit 104c49c

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

app/[locale]/enterprise/page.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,13 @@ const Page = async ({ params }: { params: { locale: Lang } }) => {
104104
const ethPrice = await fetchEthPrice()
105105
const totalEthStaked = await fetchTotalEthStaked()
106106

107-
const metrics = await parseActivity(
108-
{
109-
txCount,
110-
stablecoinMarketCap,
111-
ethPrice,
112-
totalEthStaked,
113-
// totalCapitalSecured,
114-
},
115-
locale
116-
)
107+
const metrics = await parseActivity({
108+
txCount,
109+
stablecoinMarketCap,
110+
ethPrice,
111+
totalEthStaked,
112+
// totalCapitalSecured,
113+
})
117114

118115
const features: Feature[] = [
119116
{
@@ -304,7 +301,6 @@ const Page = async ({ params }: { params: { locale: Lang } }) => {
304301

305302
<ActivityStats
306303
metrics={metrics}
307-
locale={locale}
308304
className={cn(
309305
metrics.length < 2 && "hidden", // Minimum before displaying
310306
"w-fit max-w-xl shrink-0 gap-8 sm:max-md:grid-cols-2",

app/[locale]/enterprise/utils.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getTranslations } from "next-intl/server"
1+
import { getLocale, getTranslations } from "next-intl/server"
22

33
import type {
44
AllEnterpriseActivityData,
@@ -10,16 +10,14 @@ import { formatLargeNumber, formatLargeUSD } from "@/lib/utils/numbers"
1010
import { getLocaleForNumberFormat } from "@/lib/utils/translations"
1111

1212
// Convert numerical value to formatted values
13-
export const parseActivity = async (
14-
{
15-
txCount,
16-
stablecoinMarketCap,
17-
ethPrice,
18-
totalEthStaked,
19-
// totalCapitalSecured,
20-
}: AllEnterpriseActivityData,
21-
locale: Lang
22-
): Promise<StatsBoxMetric[]> => {
13+
export const parseActivity = async ({
14+
txCount,
15+
stablecoinMarketCap,
16+
ethPrice,
17+
totalEthStaked,
18+
// totalCapitalSecured,
19+
}: AllEnterpriseActivityData): Promise<StatsBoxMetric[]> => {
20+
const locale = (await getLocale()) as Lang
2321
const t = await getTranslations("page-enterprise")
2422

2523
const localeForNumberFormat = getLocaleForNumberFormat(locale)

app/[locale]/page.tsx

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

546546
<div className="mt-12 flex justify-center">
547547
<ButtonLink

src/components/ActivityStats/index.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { getLocale } from "next-intl/server"
2+
13
import type { StatsBoxMetric } from "@/lib/types"
24

35
import { cn } from "@/lib/utils/cn"
@@ -6,14 +8,10 @@ import BigNumber from "../BigNumber"
68

79
type ActivityStatsProps = {
810
metrics: StatsBoxMetric[]
9-
locale: string
1011
className?: string
1112
}
12-
const ActivityStats = async ({
13-
metrics,
14-
locale,
15-
className,
16-
}: ActivityStatsProps) => {
13+
const ActivityStats = async ({ metrics, className }: ActivityStatsProps) => {
14+
const locale = await getLocale()
1715
const gridBorderClasses = [
1816
"border-b border-body-light xl:border-e xl:pe-8",
1917
"border-b border-body-light xl:ps-8",

0 commit comments

Comments
 (0)