@@ -36,12 +36,12 @@ import { getLastDeployDate } from "@/lib/utils/getLastDeployDate"
36
36
import { runOnlyOnce } from "@/lib/utils/runOnlyOnce"
37
37
import { getRequiredNamespacesForPage } from "@/lib/utils/translations"
38
38
39
- import {
40
- BASE_TIME_UNIT ,
41
- COINGECKO_API_BASE_URL ,
42
- COINGECKO_API_URL_PARAMS ,
43
- } from "@/lib/constants"
39
+ import { BASE_TIME_UNIT } from "@/lib/constants"
44
40
41
+ import {
42
+ fetchEthereumEcosystemData ,
43
+ fetchEthereumStablecoinsData ,
44
+ } from "@/lib/api/stablecoinsData"
45
45
import dogeComputerImg from "@/public/doge-computer.png"
46
46
// -- daps
47
47
import aaveImg from "@/public/stablecoins/aave.png"
@@ -80,17 +80,9 @@ type Props = SSRConfig & {
80
80
lastDeployDate : string
81
81
}
82
82
83
- const ethereumDataFetch = runOnlyOnce ( ( ) =>
84
- fetch (
85
- `${ COINGECKO_API_BASE_URL } ethereum-ecosystem${ COINGECKO_API_URL_PARAMS } `
86
- ) . then ( ( res ) => res . json ( ) )
87
- )
88
-
89
- const stablecoinDataFetch = runOnlyOnce ( ( ) =>
90
- fetch ( `${ COINGECKO_API_BASE_URL } stablecoins${ COINGECKO_API_URL_PARAMS } ` ) . then (
91
- ( res ) => res . json ( )
92
- )
93
- )
83
+ // Fetch external API data once to avoid hitting rate limit
84
+ const ethereumEcosystemDataFetch = runOnlyOnce ( fetchEthereumEcosystemData )
85
+ const ethereumStablecoinsDataFetch = runOnlyOnce ( fetchEthereumStablecoinsData )
94
86
95
87
export const getStaticProps = ( async ( context ) => {
96
88
const { locale } = context
@@ -133,15 +125,16 @@ export const getStaticProps = (async (context) => {
133
125
134
126
try {
135
127
// Fetch token data in the Ethereum ecosystem
136
- const ethereumData : EthereumDataResponse = await ethereumDataFetch ( )
137
-
128
+ const ethereumEcosystemData : EthereumDataResponse =
129
+ await ethereumEcosystemDataFetch ( )
138
130
// Fetch token data for stablecoins
139
- const stablecoinData : StablecoinDataResponse = await stablecoinDataFetch ( )
131
+ const stablecoinsData : StablecoinDataResponse =
132
+ await ethereumStablecoinsDataFetch ( )
140
133
141
134
// Get the intersection of stablecoins and Ethereum tokens to only have a list of data for stablecoins in the Ethereum ecosystem
142
- const ethereumStablecoinData = stablecoinData . filter (
135
+ const ethereumStablecoinData = stablecoinsData . filter (
143
136
( stablecoin ) =>
144
- ethereumData . findIndex (
137
+ ethereumEcosystemData . findIndex (
145
138
// eslint-disable-next-line
146
139
( etherToken ) => stablecoin . id == etherToken . id
147
140
) > - 1
0 commit comments