From 520f80c22ba2f2c441d7cb5a0f158b6dafebaf54 Mon Sep 17 00:00:00 2001 From: Yann Amsellem Date: Fri, 17 May 2024 17:18:58 +0200 Subject: [PATCH] chore(ecplore): handle cache --- .../graphql/agnostic/pools/usePoolsFromTokenAddress.ts | 6 ++++++ apps/web/src/graphql/agnostic/pools/useTopPools.ts | 10 +++++++++- apps/web/src/graphql/agnostic/useDailyProtocolTVL.ts | 7 ++++++- .../graphql/agnostic/useHistoricalProtocolVolume.ts | 7 ++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/apps/web/src/graphql/agnostic/pools/usePoolsFromTokenAddress.ts b/apps/web/src/graphql/agnostic/pools/usePoolsFromTokenAddress.ts index bb942864918..8a032d92e4e 100644 --- a/apps/web/src/graphql/agnostic/pools/usePoolsFromTokenAddress.ts +++ b/apps/web/src/graphql/agnostic/pools/usePoolsFromTokenAddress.ts @@ -54,6 +54,12 @@ export function useTopPoolsFromTokenQuery(token: string, skip = false) { offset: '0', }, skip, + context: { + headers: { + 'Cache-control': 'max-age=1800', + 'X-Agnostic-Cache-Refresh-Trigger': '0.9', + }, + }, }) const offsetRef = useRef(20) diff --git a/apps/web/src/graphql/agnostic/pools/useTopPools.ts b/apps/web/src/graphql/agnostic/pools/useTopPools.ts index 586cddb8af2..60c8f31c9d4 100644 --- a/apps/web/src/graphql/agnostic/pools/useTopPools.ts +++ b/apps/web/src/graphql/agnostic/pools/useTopPools.ts @@ -97,7 +97,15 @@ function transform(data?: AgnosticTopPoolResult): TopV3PoolsQuery | undefined { // eslint-disable-next-line @typescript-eslint/no-unused-vars export function useTopV3PoolsQuery(_: any) { - const { data, error, loading } = useQuery(TOP_POOLS_QUERY, { client }) + const { data, error, loading } = useQuery(TOP_POOLS_QUERY, { + client, + context: { + headers: { + 'Cache-control': 'max-age=1800', + 'X-Agnostic-Cache-Refresh-Trigger': '0.9', + }, + }, + }) return { data: useMemo(() => transform(data), [data]), diff --git a/apps/web/src/graphql/agnostic/useDailyProtocolTVL.ts b/apps/web/src/graphql/agnostic/useDailyProtocolTVL.ts index d660f74b852..6933cff3d33 100644 --- a/apps/web/src/graphql/agnostic/useDailyProtocolTVL.ts +++ b/apps/web/src/graphql/agnostic/useDailyProtocolTVL.ts @@ -17,11 +17,16 @@ type AgnosticHistoricalProtocolTVLResult = { explore_daily_protocol_tvl_v3?: { timestamp: string; tvl_usd: string }[] } -// eslint-disable-next-line import/no-unused-modules export function useDailyProtocolTvlQuery({ variables }: { variables: { chain: Chain } }) { const { data, loading } = useQuery(HISTORICAL_PROTOCOL_TVL_QUERY, { client, skip: variables.chain !== Chain.Ethereum, + context: { + headers: { + 'Cache-control': 'max-age=86400', + 'X-Agnostic-Cache-Refresh-Trigger': '0.9', + }, + }, }) return { diff --git a/apps/web/src/graphql/agnostic/useHistoricalProtocolVolume.ts b/apps/web/src/graphql/agnostic/useHistoricalProtocolVolume.ts index 2358b4672c4..b4a8ec0fa44 100644 --- a/apps/web/src/graphql/agnostic/useHistoricalProtocolVolume.ts +++ b/apps/web/src/graphql/agnostic/useHistoricalProtocolVolume.ts @@ -29,7 +29,6 @@ type AgnosticHistoricalProtocolVolumeVariables = { all_time?: boolean } -// eslint-disable-next-line import/no-unused-modules export function useHistoricalProtocolVolumeQuery({ variables, }: { @@ -45,6 +44,12 @@ export function useHistoricalProtocolVolumeQuery({ all_time: variables.duration === HistoryDuration.Max, }, skip: shouldSkip(variables.chain, variables.duration), + context: { + headers: { + 'Cache-control': 'max-age=86400', + 'X-Agnostic-Cache-Refresh-Trigger': '0.9', + }, + }, } )