-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e894daf
commit 7ef2803
Showing
3 changed files
with
41 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { apiWrapper } from "./apiWrapper"; | ||
|
||
export interface SystemStats { | ||
active_tvl: number; | ||
total_tvl: number; | ||
active_delegations: number; | ||
total_delegations: number; | ||
active_stakers: number; | ||
total_stakers: number; | ||
active_finality_providers: number; | ||
total_finality_providers: number; | ||
} | ||
|
||
interface SystemStatsAPIResponse { | ||
data: SystemStats; | ||
} | ||
|
||
export const getSystemStats = async (): Promise<SystemStats> => { | ||
const response = await apiWrapper( | ||
"GET", | ||
"/v2/stats", | ||
"Error getting system stats", | ||
); | ||
|
||
const systemStatsAPIResponse: SystemStatsAPIResponse = response.data; | ||
|
||
return systemStatsAPIResponse.data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,14 @@ | ||
import { getSystemStats } from "@/app/api/getSystemStats"; | ||
import { ONE_MINUTE } from "@/app/constants"; | ||
import { useAPIQuery } from "@/app/hooks/api/useApi"; | ||
|
||
export const BTC_TIP_HEIGHT_KEY = "API_STATS"; | ||
|
||
const defaultValues = { | ||
activeTvl: 0, | ||
totalTvl: 0, | ||
activeDelegations: 0, | ||
totalDelegations: 0, | ||
activeStakers: 0, | ||
totalStakers: 0, | ||
activeFinalityProviders: 0, | ||
totalFinalityProviders: 0, | ||
}; | ||
|
||
export function useSystemStats() { | ||
export function useSystemStats({ enabled = true }: { enabled?: boolean } = {}) { | ||
return useAPIQuery({ | ||
queryKey: ["API_STATS"], | ||
queryFn: () => Promise.resolve(defaultValues), | ||
initialData: defaultValues, | ||
placeholderData: defaultValues, | ||
queryFn: () => getSystemStats(), | ||
refetchInterval: ONE_MINUTE, | ||
enabled, | ||
}); | ||
} |