11import { useQuery } from '@tanstack/react-query' ;
2+ import { DateTime } from 'luxon' ;
23
34import type { DydxAddress } from '@/constants/wallets' ;
45
56import { wrapAndLogError } from '@/lib/asyncUtils' ;
67import { calc } from '@/lib/do' ;
78
89type ChaosLabsIncentivesResponse = {
9- dydxRewards : number ;
1010 incentivePoints : number ;
1111 marketMakingIncentivePoints : number ;
12+ totalFees : number ;
1213} ;
1314
1415export const useQueryChaosLabsIncentives = ( {
@@ -18,11 +19,11 @@ export const useQueryChaosLabsIncentives = ({
1819 dydxAddress ?: DydxAddress ;
1920 season ?: number ;
2021} ) => {
21- return useQuery < ChaosLabsIncentivesResponse | undefined , Error > ( {
22+ return useQuery ( {
2223 enabled : ! ! dydxAddress ,
2324 queryKey : [ 'launch_incentives_rewards' , dydxAddress , season ] ,
2425 queryFn : wrapAndLogError (
25- async ( ) => {
26+ async ( ) : Promise < ChaosLabsIncentivesResponse | undefined > => {
2627 if ( ! dydxAddress ) return undefined ;
2728
2829 // If season is defined, fetch for a specific season
@@ -42,17 +43,27 @@ export const useQueryChaosLabsIncentives = ({
4243 return undefined ;
4344 }
4445
45- const thisSeasonResponse = await calc ( async ( ) => {
46- return (
47- await fetch (
48- `https://cloud.chaoslabs.co/query/api/dydx/points/${ dydxAddress } ?n=${ currentSeason } `
49- )
50- ) . json ( ) ;
51- } ) ;
46+ const [ thisSeasonResponse , thisSeasonFees ] = await Promise . all ( [
47+ calc ( async ( ) => {
48+ return (
49+ await fetch (
50+ `https://cloud.chaoslabs.co/query/api/dydx/points/${ dydxAddress } ?n=${ currentSeason } `
51+ )
52+ ) . json ( ) ;
53+ } ) ,
54+ calc ( async ( ) => {
55+ return (
56+ await fetch (
57+ `https://cloud.chaoslabs.co/query/api/dydx/fees/${ dydxAddress } ?month=${ DateTime . utc ( ) . toFormat ( 'yyyy-MM' ) } `
58+ )
59+ ) . json ( ) ;
60+ } ) ,
61+ ] ) ;
5262
5363 return {
5464 incentivePoints : thisSeasonResponse . incentivePoints ?? 0 ,
5565 marketMakingIncentivePoints : thisSeasonResponse . marketMakingIncentivePoints ?? 0 ,
66+ totalFees : thisSeasonFees . data ?. [ 0 ] ?. total_fees ?? 0 ,
5667 } ;
5768 } ,
5869 'LaunchIncentives/fetchPoints' ,
0 commit comments