Skip to content

Commit 3bd7a11

Browse files
authored
Merge pull request #14917 from SamarthJ2004/issue14910
issue:14910 added functionality to highlight robust and maturing networks
2 parents ec8b91f + 0decdc8 commit 3bd7a11

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/pages/layer-2/index.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import InlineLink from "@/components/ui/Link"
1616
import { dataLoader } from "@/lib/utils/data/dataLoader"
1717
import { existsNamespace } from "@/lib/utils/existsNamespace"
1818
import { getLastDeployDate } from "@/lib/utils/getLastDeployDate"
19+
import { networkMaturity } from "@/lib/utils/networkMaturity"
1920
import { getLocaleTimestamp } from "@/lib/utils/time"
2021
import { getRequiredNamespacesForPage } from "@/lib/utils/translations"
2122

@@ -24,6 +25,7 @@ import { layer2Data, Rollups } from "@/data/networks/networks"
2425
import { BASE_TIME_UNIT } from "@/lib/constants"
2526

2627
import { fetchGrowThePie } from "@/lib/api/fetchGrowThePie"
28+
import { fetchL2beat } from "@/lib/api/fetchL2beat"
2729
import HeroImage from "@/public/images/heroes/layer-2-hub-hero.jpg"
2830
import EthereumLogo from "@/public/images/layer-2/ethereum.png"
2931
import WalkingImage from "@/public/images/layer-2/layer-2-walking.png"
@@ -34,7 +36,10 @@ import ManDogCardImage from "@/public/images/man-and-dog-playing.png"
3436
const REVALIDATE_TIME = BASE_TIME_UNIT * 24
3537

3638
const loadData = dataLoader(
37-
[["growThePieData", fetchGrowThePie]],
39+
[
40+
["growThePieData", fetchGrowThePie],
41+
["l2beatData", fetchL2beat],
42+
],
3843
REVALIDATE_TIME * 1000
3944
)
4045

@@ -49,14 +54,34 @@ export const getStaticProps = (async ({ locale }) => {
4954

5055
const contentNotTranslated = !existsNamespace(locale!, requiredNamespaces[2])
5156

52-
const [growThePieData] = await loadData()
57+
const [growThePieData, l2beatData] = await loadData()
58+
59+
const getRandomL2s = () => {
60+
let randomL2s = layer2Data.filter(
61+
(network) =>
62+
networkMaturity(l2beatData.data.projects[network.l2beatID]) === "robust"
63+
)
64+
65+
if (randomL2s.length === 0) {
66+
randomL2s = layer2Data.filter(
67+
(network) =>
68+
networkMaturity(l2beatData.data.projects[network.l2beatID]) ===
69+
"maturing"
70+
)
71+
}
72+
73+
return randomL2s.sort(() => 0.5 - Math.random()).slice(0, 3)
74+
}
5375

5476
const randomL2s = layer2Data.sort(() => 0.5 - Math.random()).slice(0, 9)
5577

78+
const userRandomL2s = getRandomL2s()
79+
5680
return {
5781
props: {
5882
...(await serverSideTranslations(locale!, requiredNamespaces)),
5983
randomL2s,
84+
userRandomL2s,
6085
contentNotTranslated,
6186
lastDeployLocaleTimestamp,
6287
locale,
@@ -67,10 +92,12 @@ export const getStaticProps = (async ({ locale }) => {
6792

6893
const Layer2Hub = ({
6994
randomL2s,
95+
userRandomL2s,
7096
growThePieData,
7197
locale,
7298
}: {
7399
randomL2s: Rollups
100+
userRandomL2s: Rollups
74101
growThePieData: GrowThePieData
75102
locale: Lang
76103
}) => {
@@ -385,7 +412,7 @@ const Layer2Hub = ({
385412
<div id="layer-2-cta" className="w-full px-8 py-9">
386413
<div className="mx-auto flex max-w-[640px] flex-col gap-6 rounded bg-main-gradient p-8">
387414
<div className="flex flex-col gap-6">
388-
{randomL2s.slice(0, 3).map((l2, idx) => {
415+
{userRandomL2s.map((l2, idx) => {
389416
return (
390417
<div
391418
key={idx}

0 commit comments

Comments
 (0)