Skip to content

Commit 9b0b58a

Browse files
committed
randomize wallets list at build time
1 parent eb74969 commit 9b0b58a

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

src/pages/wallets/find-wallet.tsx

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useRef, useState } from "react"
2-
import { GetStaticProps } from "next"
2+
import { GetStaticProps, InferGetStaticPropsType } from "next"
33
import { useRouter } from "next/router"
44
import { useTranslation } from "next-i18next"
55
import { serverSideTranslations } from "next-i18next/serverSideTranslations"
@@ -56,6 +56,10 @@ const Subtitle = ({ children }: ChildOnlyProp) => (
5656
</Text>
5757
)
5858

59+
type Props = BasePageProps & {
60+
wallets: WalletData[]
61+
}
62+
5963
export const getStaticProps = (async ({ locale }) => {
6064
const lastDeployDate = getLastDeployDate()
6165

@@ -65,18 +69,24 @@ export const getStaticProps = (async ({ locale }) => {
6569

6670
const contentNotTranslated = !existsNamespace(locale!, requiredNamespaces[2])
6771

72+
const supportedLocaleWallets = getSupportedLocaleWallets(locale!)
73+
const noSupportedLocaleWallets = getNonSupportedLocaleWallets(locale!)
74+
const wallets = supportedLocaleWallets.concat(noSupportedLocaleWallets)
75+
6876
return {
6977
props: {
7078
...(await serverSideTranslations(locale!, requiredNamespaces)),
7179
contentNotTranslated,
7280
lastDeployDate,
81+
wallets,
7382
},
7483
}
75-
}) satisfies GetStaticProps<BasePageProps>
84+
}) satisfies GetStaticProps<Props>
7685

77-
const FindWalletPage = () => {
78-
const { pathname, locale } = useRouter()
79-
const theme = useTheme()
86+
const FindWalletPage = ({
87+
wallets,
88+
}: InferGetStaticPropsType<typeof getStaticProps>) => {
89+
const { pathname } = useRouter()
8090
const { t } = useTranslation("page-wallets-find-wallet")
8191

8292
const resetWalletFilter = useRef(() => {})
@@ -87,24 +97,6 @@ const FindWalletPage = () => {
8797

8898
const { isOpen: showMobileSidebar, onOpen, onClose } = useDisclosure()
8999

90-
const supportedLocaleWallets = getSupportedLocaleWallets(locale!)
91-
const noSupportedLocaleWallets = getNonSupportedLocaleWallets(locale!)
92-
const [randomizedWalletData, setRandomizedWalletData] = useState<
93-
WalletData[]
94-
>(supportedLocaleWallets.concat(noSupportedLocaleWallets))
95-
96-
// If any wallet supports user's locale, show them (shuffled) at the top and then the remaining ones
97-
useEffect(() => {
98-
const supportedLocaleWallets = getSupportedLocaleWallets(locale!)
99-
100-
const noSupportedLocaleWallets = getNonSupportedLocaleWallets(locale!)
101-
102-
setRandomizedWalletData(
103-
supportedLocaleWallets.concat(noSupportedLocaleWallets)
104-
)
105-
// eslint-disable-next-line react-hooks/exhaustive-deps
106-
}, [locale])
107-
108100
const updateFilterOption = (key) => {
109101
const updatedFilters = { ...filters }
110102
updatedFilters[key] = !updatedFilters[key]
@@ -242,7 +234,7 @@ const FindWalletPage = () => {
242234
filters={filters}
243235
resetFilters={resetFilters}
244236
resetWalletFilter={resetWalletFilter}
245-
walletData={randomizedWalletData}
237+
walletData={wallets}
246238
onOpen={onOpen}
247239
/>
248240
</Box>

0 commit comments

Comments
 (0)