Skip to content

Commit bda9dcd

Browse files
authored
fix: hompage data (#12488)
<!-- Before opening a pull request, please read the [contributing guidelines](https://github.com/pancakeswap/pancake-frontend/blob/develop/CONTRIBUTING.md) first --> <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on refactoring the import paths in various files from `pages/api/home` to `edge/home`, indicating a restructuring of the project to potentially improve organization or modularity. ### Detailed summary - Changed import paths from `pages/api/home/types` to `edge/home/types` in multiple files. - Updated import paths for query functions from `./queries/queryTokenList` to `edge/home/queries/queryTokenList`. - Modified error handling in `getTotalTvl` to log errors without environment checks. - Altered the `_load` function in `index.ts` to use `Promise.allSettled` for better error handling. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 0e6a694 commit bda9dcd

21 files changed

+38
-33
lines changed

apps/web/src/pages/api/home/queries/queryTokenList.ts renamed to apps/web/src/edge/home/queries/queryTokenList.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ export const _queryTokenList = async () => {
1010
const list = [...DEFAULT_ACTIVE_LIST_URLS]
1111

1212
const results = await Promise.allSettled(list.map((url) => getTokenList(url)))
13+
1314
const allFailed = results.every((result) => result.status === 'rejected')
1415

1516
if (allFailed) {
1617
throw new Error('All token list failed')
1718
}
1819
const lists = results
1920
.filter((result): result is PromiseFulfilledResult<TokenList> => result.status === 'fulfilled')
21+
.filter((x) => x && x.value && x.value.tokens)
2022
.map((result) => result.value.tokens)
2123
.flat()
2224
.map((x) => ({ ...x, address: checksumAddress(x.address) }))

apps/web/src/pages/api/home/queries/settings.ts renamed to apps/web/src/edge/home/queries/settings.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ export const HOME_PAGE_CACHE_MAX_AGE = 60 * 60 * 1000 // 1 hour
44
export const getHomeCacheSettings = (name: string) => {
55
return {
66
ttl: HOME_PAGE_CACHE_TTL,
7-
persist: {
8-
name: `homepage-${name}`,
9-
type: 'r2' as const,
10-
version: 'v3',
11-
},
127
maxAge: HOME_PAGE_CACHE_MAX_AGE,
138
cacheNextEpochOnHalfTTS: true,
149
}
File renamed without changes.

apps/web/src/pages/api/home/index.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
import { cacheByLRU } from '@pancakeswap/utils/cacheByLRU'
22
import { NextApiHandler } from 'next'
3-
import { homePageChainsInfo, homePageCurrencies, partners } from './homePageDataQuery'
4-
import { queryPools } from './queries/queryPools'
5-
import { queryPredictionUser } from './queries/queryPrediction'
6-
import { queryTokens } from './queries/queryTokens'
7-
import { querySiteStats } from './querySiteStats'
8-
import { HomePageData } from './types'
3+
import { homePageChainsInfo, homePageCurrencies, partners } from 'edge/home/homePageDataQuery'
4+
import { queryPools } from 'edge/home/queries/queryPools'
5+
import { queryPredictionUser } from 'edge/home/queries/queryPrediction'
6+
import { queryTokens } from 'edge/home/queries/queryTokens'
7+
import { querySiteStats } from 'edge/home/querySiteStats'
8+
import { HomePageData } from 'edge/home/types'
99

1010
async function _load() {
11-
const [{ topTokens }, stats, topWinner] = await Promise.all([queryTokens(), querySiteStats(), queryPredictionUser()])
12-
const pools = await queryPools()
11+
const [tokensResult, statsResult, topWinnerResult, poolsResult] = await Promise.allSettled([
12+
queryTokens(),
13+
querySiteStats(),
14+
queryPredictionUser(),
15+
queryPools(),
16+
])
17+
18+
const topTokens = tokensResult.status === 'fulfilled' ? tokensResult.value.topTokens : []
19+
const stats = statsResult.status === 'fulfilled' ? statsResult.value : undefined
20+
const topWinner = topWinnerResult.status === 'fulfilled' ? topWinnerResult.value : undefined
21+
const pools = poolsResult.status === 'fulfilled' ? poolsResult.value : []
1322
const currencies = homePageCurrencies
1423
const chains = homePageChainsInfo()
1524
return {

apps/web/src/pages/api/home/tokens.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NextApiHandler } from 'next'
2-
import { queryTokenList } from './queries/queryTokenList'
2+
import { queryTokenList } from 'edge/home/queries/queryTokenList'
33

44
async function load() {
55
return queryTokenList()

0 commit comments

Comments
 (0)