forked from pancakeswap/pancake-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.ts
37 lines (29 loc) · 920 Bytes
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { useEffect, useState } from 'react'
/*
* Due to Cors the api was forked and a proxy was created
* @see https://github.com/pancakeswap/gatsby-pancake-api/commit/e811b67a43ccc41edd4a0fa1ee704b2f510aa0ba
*/
export const baseUrl = 'https://api.pancakeswap.com/api/v1'
/* eslint-disable camelcase */
export interface ApiTvlResponse {
update_at: string
'24h_total_volume': number
total_value_locked: number
total_value_locked_all: number
}
export const useGetStats = () => {
const [data, setData] = useState<ApiTvlResponse | null>(null)
useEffect(() => {
const fetchData = async () => {
try {
const response = await fetch(`${baseUrl}/tvl`)
const responsedata: ApiTvlResponse = await response.json()
setData(responsedata)
} catch (error) {
console.error('Unable to fetch data:', error)
}
}
fetchData()
}, [setData])
return data
}