diff --git a/src/hooks/useKeyTwap.ts b/src/hooks/useKeyTwap.ts index 6dd8f504..c6f2b8d7 100644 --- a/src/hooks/useKeyTwap.ts +++ b/src/hooks/useKeyTwap.ts @@ -2,12 +2,15 @@ import { useQuery } from '@tanstack/react-query'; import { queryKeys } from '@/lib/queryKeys'; import { courseService } from '@/services/course.service'; -export function useKeyTwap(keyId: string) { +export type KeyTwapWindow = '1h' | '24h'; + +export function useKeyTwap(keyId: string, window: KeyTwapWindow = '24h') { return useQuery({ - queryKey: queryKeys.creators.twap(keyId), - queryFn: () => courseService.getKeyTwap(keyId), + queryKey: queryKeys.creators.twap(keyId, window), + queryFn: () => courseService.getKeyTwap(keyId, window), enabled: !!keyId, staleTime: 60_000, + refetchInterval: 60_000, retry: false, }); } diff --git a/src/lib/queryKeys.ts b/src/lib/queryKeys.ts index 34fdbc66..3a17e411 100644 --- a/src/lib/queryKeys.ts +++ b/src/lib/queryKeys.ts @@ -7,7 +7,7 @@ * queryKeys.creatorProfile.all() })`). */ -import type { GetCoursesParams } from '@/services/course.service'; +import type { GetCoursesParams, KeyTwapWindow } from '@/services/course.service'; import type { VolumeWindow } from '@/services/leaderboard.service'; export const queryKeys = { @@ -31,8 +31,8 @@ export const queryKeys = { ['creators', creatorId, 'holders'] as const, activity: (creatorId: string) => ['creators', creatorId, 'activity'] as const, - twap: (creatorId: string) => - ['creators', creatorId, 'twap', '24h'] as const, + twap: (creatorId: string, window: KeyTwapWindow = '24h') => + ['creators', creatorId, 'twap', window] as const, stats: (creatorId: string) => ['creators', creatorId, 'stats'] as const, auctionBids: (creatorId: string) => ['creators', creatorId, 'auction-bids'] as const, diff --git a/src/pages/CreatorDetailPage.tsx b/src/pages/CreatorDetailPage.tsx index 2d6aa9d6..635ee902 100644 --- a/src/pages/CreatorDetailPage.tsx +++ b/src/pages/CreatorDetailPage.tsx @@ -437,6 +437,10 @@ function CreatorDetailPageContent() { const twapDelta = twapPrice != null && spotPrice != null ? twapPrice - spotPrice : null; + const twapDeviationPercent = + twapPrice != null && spotPrice != null && spotPrice > 0 + ? ((twapPrice - spotPrice) / spotPrice) * 100 + : null; const hasRealStakingData = creator.stakingPoolBalance != null || @@ -766,6 +770,51 @@ function CreatorDetailPageContent() { )} + {isTwapLoading ? ( +