Skip to content

Commit 7aa67f3

Browse files
authored
Merge pull request #1859 from IndexCoop/fix/stats-query
fix: stats query
2 parents 1649da4 + f8b17cc commit 7aa67f3

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/app/leverage/components/stats/use-quick-stats.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getTokenByChainAndSymbol } from '@indexcoop/tokenlists'
12
import { type QueryFunctionContext, useQuery } from '@tanstack/react-query'
23

34
import { formatAmount, formatDollarAmount } from '@/lib/utils'
@@ -71,10 +72,9 @@ export function useQuickStats(
7172
try {
7273
const response = await fetch(
7374
`/api/stats?address=${address}&chainId=${chainId}&symbol=${symbol}&base=${baseToken}&baseCurrency=${baseCurrency}`,
74-
{
75-
method: 'GET',
76-
},
75+
{ method: 'GET' },
7776
)
77+
7878
const { base, token }: QuickStatsApiResponse = await response.json()
7979
return {
8080
base: {
@@ -107,29 +107,26 @@ export function useQuickStats(
107107
}
108108
}
109109

110+
const address =
111+
getTokenByChainAndSymbol(indexToken.chainId, indexToken.symbol)?.address ??
112+
''
110113
const { data, isFetching } = useQuery({
111114
queryKey: [
112115
'fetch-quick-stats',
113116
{
114117
chainId: indexToken.chainId,
115118
symbol: indexToken.symbol,
116-
address: indexToken.address,
119+
address,
117120
market,
118121
},
119122
],
120123
queryFn: fetchStats,
121-
enabled: !!indexToken.address,
124+
enabled: !!address,
122125
})
123126

124127
return {
125128
data: data ?? {
126-
base: {
127-
symbol: '',
128-
price: '',
129-
change24h: 0,
130-
low24h: '',
131-
high24h: '',
132-
},
129+
base: { symbol: '', price: '', change24h: 0, low24h: '', high24h: '' },
133130
token: {
134131
symbol: '',
135132
costOfCarry: 0,

0 commit comments

Comments
 (0)