diff --git a/src/constants.ts b/src/constants.ts index 026adaef..4d01a158 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -10,6 +10,8 @@ export const DEFAULT_FAVORITE_RELAYS = [ 'wss://news.utxo.one/' ] +export const RECOMMENDED_RELAYS = DEFAULT_FAVORITE_RELAYS.concat(['wss://yabu.me/']) + export const StorageKey = { VERSION: 'version', THEME_SETTING: 'themeSetting', diff --git a/src/pages/secondary/HomePage/index.tsx b/src/pages/secondary/HomePage/index.tsx index 057ecc9a..ac6ed69b 100644 --- a/src/pages/secondary/HomePage/index.tsx +++ b/src/pages/secondary/HomePage/index.tsx @@ -1,38 +1,34 @@ import { usePrimaryPage, useSecondaryPage } from '@/PageManager' import RelaySimpleInfo from '@/components/RelaySimpleInfo' import { Button } from '@/components/ui/button' +import { RECOMMENDED_RELAYS } from '@/constants' import SecondaryPageLayout from '@/layouts/SecondaryPageLayout' import { toRelay } from '@/lib/link' import relayInfoService from '@/services/relay-info.service' import { TNip66RelayInfo } from '@/types' -import { ArrowRight, RefreshCcw, Server } from 'lucide-react' -import { forwardRef, useCallback, useEffect, useState } from 'react' +import { ArrowRight, Server } from 'lucide-react' +import { forwardRef, useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' const HomePage = forwardRef(({ index }: { index?: number }, ref) => { const { t } = useTranslation() const { navigate } = usePrimaryPage() const { push } = useSecondaryPage() - const [randomRelayInfos, setRandomRelayInfos] = useState([]) - - const refresh = useCallback(async () => { - const relayInfos = await relayInfoService.getRandomRelayInfos(10) - const relayUrls = new Set() - const uniqueRelayInfos = relayInfos.filter((relayInfo) => { - if (relayUrls.has(relayInfo.url)) { - return false - } - relayUrls.add(relayInfo.url) - return true - }) - setRandomRelayInfos(uniqueRelayInfos) - }, []) + const [recommendedRelayInfos, setRecommendedRelayInfos] = useState([]) useEffect(() => { - refresh() + const init = async () => { + try { + const relays = await relayInfoService.getRelayInfos(RECOMMENDED_RELAYS) + setRecommendedRelayInfos(relays.filter(Boolean) as TNip66RelayInfo[]) + } catch (error) { + console.error('Failed to fetch recommended relays:', error) + } + } + init() }, []) - if (!randomRelayInfos.length) { + if (!recommendedRelayInfos.length) { return (
@@ -49,20 +45,14 @@ const HomePage = forwardRef(({ index }: { index?: number }, ref) => { title={ <> -
{t('Random Relays')}
+
{t('Recommended relays')}
} - controls={ - - } hideBackButton >
- {randomRelayInfos.map((relayInfo) => ( + {recommendedRelayInfos.map((relayInfo) => (