Skip to content

Commit 109c1d7

Browse files
committed
refactor: load apiKey from api util
1 parent b39812b commit 109c1d7

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/lib/api/fetchNodes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { EtherscanNodeResponse, MetricReturnData, TimestampedData } from "@
22

33
import { DAYS_TO_FETCH, ETHERSCAN_API_URL } from "@/lib/constants"
44

5-
export const fetchNodes = async (apiKey: string): Promise<MetricReturnData> => {
5+
export const fetchNodes = async (): Promise<MetricReturnData> => {
6+
const apiKey = process.env.ETHERSCAN_API_KEY
67
const now = new Date()
78
const endDate = now.toISOString().split("T")[0] // YYYY-MM-DD
89
const startDate = new Date(now.setDate(now.getDate() - DAYS_TO_FETCH))

src/lib/api/fetchTxCount.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { EtherscanTxCountResponse, MetricReturnData, TimestampedData } from
22

33
import { DAYS_TO_FETCH, ETHERSCAN_API_URL } from "@/lib/constants"
44

5-
export const fetchTxCount = async (apiKey: string): Promise<MetricReturnData> => {
5+
export const fetchTxCount = async (): Promise<MetricReturnData> => {
6+
const apiKey = process.env.ETHERSCAN_API_KEY
67
const now = new Date()
78
const endDate = now.toISOString().split("T")[0] // YYYY-MM-DD
89
const startDate = new Date(now.setDate(now.getDate() - DAYS_TO_FETCH))

src/pages/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,11 @@ const ButtonLinkRow = (props: ChildOnlyProp) => (
179179
/>
180180
)
181181

182-
const etherscanApiKey = process.env.ETHERSCAN_API_KEY
183-
184182
const cachedFetchCommunityEvents = runOnlyOnce(fetchCommunityEvents)
185183
const cachedFetchTotalEthStaked = runOnlyOnce(fetchTotalEthStaked)
186-
const cachedFetchNodes = runOnlyOnce(() => fetchNodes(etherscanApiKey))
184+
const cachedFetchNodes = runOnlyOnce(fetchNodes)
187185
const cachedFetchTotalValueLocked = runOnlyOnce(fetchTotalValueLocked)
188-
const cachedFetchTxCount = runOnlyOnce(() => fetchTxCount(etherscanApiKey))
186+
const cachedFetchTxCount = runOnlyOnce(fetchTxCount)
189187

190188
type Props = SSRConfig & {
191189
communityEvents: CommunityEventsReturnType

0 commit comments

Comments
 (0)