Skip to content

Commit 0cd0160

Browse files
authored
Merge pull request #15483 from ethereum/master
Master
2 parents dc273dc + a5a75d9 commit 0cd0160

File tree

6 files changed

+87
-25
lines changed

6 files changed

+87
-25
lines changed

app/[locale]/layer-2/_components/layer-2.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,12 @@ const Layer2Hub = ({
124124
<div className="max-w-[224px]">
125125
<p className="text-5xl">
126126
$
127-
{growThePieData.dailyTxCosts["ethereum"].toLocaleString(
128-
locale as Lang,
129-
{ minimumFractionDigits: 2, maximumFractionDigits: 2 }
130-
)}
127+
{(
128+
growThePieData.dailyTxCosts["ethereum"] || 0
129+
).toLocaleString(locale as Lang, {
130+
minimumFractionDigits: 2,
131+
maximumFractionDigits: 2,
132+
})}
131133
</p>
132134
<p className="text-body-medium">
133135
{t("page-layer-2-blockchain-transaction-cost")}

app/[locale]/layer-2/page.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { BASE_TIME_UNIT } from "@/lib/constants"
2020

2121
import Layer2Page from "./_components/layer-2"
2222

23+
import { routing } from "@/i18n/routing"
2324
import { fetchGrowThePie } from "@/lib/api/fetchGrowThePie"
2425
import { fetchL2beat } from "@/lib/api/fetchL2beat"
2526

@@ -79,6 +80,14 @@ const Page = async ({ params }: { params: Promise<{ locale: Lang }> }) => {
7980
)
8081
}
8182

83+
export async function generateStaticParams() {
84+
return routing.locales.map((locale) => ({
85+
locale,
86+
}))
87+
}
88+
89+
export const dynamicParams = false
90+
8291
export async function generateMetadata({
8392
params,
8493
}: {

src/components/Layer2NetworksTable/NetworksSubComponent.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { MdInfoOutline } from "react-icons/md"
22

3+
import { ExtendedRollup } from "@/lib/types"
4+
35
import NetworkUsageChart from "@/components/Layer2NetworksTable/NetworkUsageChart"
46
import Tooltip from "@/components/Tooltip"
57

@@ -21,7 +23,11 @@ const formatNumber = (num: number): string => {
2123
return num.toString()
2224
}
2325

24-
const NetworkSubComponent = ({ network }) => {
26+
type NetworkSubComponentProps = {
27+
network: ExtendedRollup
28+
}
29+
30+
const NetworkSubComponent = ({ network }: NetworkSubComponentProps) => {
2531
const { t } = useTranslation("page-layer-2-networks")
2632

2733
return (
@@ -60,6 +66,7 @@ const NetworkSubComponent = ({ network }) => {
6066
</p>
6167
<p>
6268
{(() => {
69+
if (!network.launchDate) return "-"
6370
const launch = new Date(network.launchDate)
6471
const today = new Date()
6572
const yearDiff = today.getFullYear() - launch.getFullYear()
@@ -141,7 +148,11 @@ const NetworkSubComponent = ({ network }) => {
141148
</Tooltip>
142149
</p>
143150
</div>
144-
<p>{formatNumber(network.activeAddresses)}</p>
151+
<p>
152+
{network.activeAddresses
153+
? formatNumber(network.activeAddresses)
154+
: "-"}
155+
</p>
145156
</div>
146157
<div className="flex-1">
147158
<div>

src/components/Layer2NetworksTable/hooks/useNetworkColumns.tsx

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const useNetworkColumns: ColumnDef<ExtendedRollup>[] = [
4949
},
5050
cell: ({ table, row }) => {
5151
const meta = table.options.meta as TableMeta
52+
5253
return (
5354
<TableCell
5455
className={cn(
@@ -78,11 +79,20 @@ export const useNetworkColumns: ColumnDef<ExtendedRollup>[] = [
7879
<Translation id="page-layer-2-networks:page-layer-2-networks-avg-transaction-fee" />
7980
</p>
8081
<p>
81-
$
82-
{row.original.txCosts.toLocaleString(meta.locale as Lang, {
83-
minimumFractionDigits: 2,
84-
maximumFractionDigits: 3,
85-
})}
82+
{row.original.txCosts ? (
83+
<>
84+
$
85+
{(row.original.txCosts || 0).toLocaleString(
86+
meta.locale as Lang,
87+
{
88+
minimumFractionDigits: 2,
89+
maximumFractionDigits: 3,
90+
}
91+
)}
92+
</>
93+
) : (
94+
<p>-</p>
95+
)}
8696
</p>
8797
</div>
8898
<div>
@@ -160,11 +170,17 @@ export const useNetworkColumns: ColumnDef<ExtendedRollup>[] = [
160170
row.original.canExpand === false && "border-b-4"
161171
)}
162172
>
163-
$
164-
{row.original.txCosts.toLocaleString(meta.locale as Lang, {
165-
minimumFractionDigits: 2,
166-
maximumFractionDigits: 3,
167-
})}
173+
{row.original.txCosts ? (
174+
<p>
175+
$
176+
{row.original.txCosts.toLocaleString(meta.locale as Lang, {
177+
minimumFractionDigits: 2,
178+
maximumFractionDigits: 3,
179+
})}
180+
</p>
181+
) : (
182+
<p>-</p>
183+
)}
168184
</TableCell>
169185
)
170186
},

src/lib/api/fetchGrowThePie.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,47 @@ type DataItem = {
1111

1212
const TXCOSTS_MEDIAN_USD = "txcosts_median_usd"
1313
const TXCOUNT = "txcount"
14+
const ACTIVE_ADDRESSES = "aa_last7d"
1415

1516
export const fetchGrowThePie = async (): Promise<GrowThePieData> => {
1617
const url = "https://api.growthepie.xyz/v1/fundamentals.json"
1718

18-
const response = await fetch(url)
19+
const response = await fetch(url, { cache: "no-store" })
1920
if (!response.ok) {
2021
console.log(response.status, response.statusText)
2122
throw new Error("Failed to fetch growthepie data")
2223
}
2324
const data: DataItem[] = await response.json()
2425

25-
const mostRecentDate = data.reduce((latest, item) => {
26+
// Get the date 7 days ago
27+
const sevenDaysAgo = new Date()
28+
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7)
29+
30+
// Filter data to only include the last 7 days and the metrics we need
31+
const filteredData = data.filter((item) => {
32+
const itemDate = new Date(item.date)
33+
return (
34+
itemDate >= sevenDaysAgo &&
35+
[TXCOSTS_MEDIAN_USD, TXCOUNT, ACTIVE_ADDRESSES].includes(item.metric_key)
36+
)
37+
})
38+
39+
const mostRecentDate = filteredData.reduce((latest, item) => {
2640
const itemDate = new Date(item.date)
2741
return itemDate > new Date(latest) ? item.date : latest
28-
}, data[0].date)
42+
}, filteredData[0].date)
2943

30-
const activeAddresses = data
44+
const activeAddresses = filteredData
3145
.filter((item) => item.date === mostRecentDate)
32-
.filter((item) => item.metric_key === "aa_last7d")
46+
.filter((item) => item.metric_key === ACTIVE_ADDRESSES)
3347
.reduce((acc, item) => {
3448
return {
3549
...acc,
3650
[item.origin_key]: item.value,
3751
}
3852
}, {})
3953

40-
const mostRecentData = data.filter(
54+
const mostRecentData = filteredData.filter(
4155
(item) =>
4256
item.date === mostRecentDate &&
4357
[TXCOSTS_MEDIAN_USD, TXCOUNT].includes(item.metric_key)

src/lib/types.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,8 +559,8 @@ export type StatsBoxState = ValueOrError<string>
559559
export type GrowThePieMetricKey = "txCount" | "txCostsMedianUsd"
560560

561561
export type GrowThePieData = Record<GrowThePieMetricKey, MetricReturnData> & {
562-
dailyTxCosts: Record<string, number>
563-
activeAddresses: Record<string, number>
562+
dailyTxCosts: Record<string, number | undefined>
563+
activeAddresses: Record<string, number | undefined>
564564
}
565565

566566
export type MetricName =
@@ -642,9 +642,19 @@ export type NonEVMChainName = "Starknet"
642642

643643
export type ExtendedRollup = Rollup & {
644644
networkMaturity: MaturityLevel
645-
txCosts: number
645+
txCosts: number | undefined
646646
tvl: number
647647
walletsSupported: string[]
648+
activeAddresses: number | undefined
649+
launchDate: string | null
650+
walletsSupportedCount: number
651+
blockspaceData: {
652+
nft: number
653+
defi: number
654+
social: number
655+
token_transfers: number
656+
unlabeled: number
657+
} | null
648658
}
649659

650660
// Wallets

0 commit comments

Comments
 (0)