({ showTime }: { showTime: number })
| 45 | } |
| 46 | |
| 47 | export const UsageBanner = ({ showTime }: { showTime: number }) => { |
| 48 | if (IS_FREEBUFF) return null |
| 49 | |
| 50 | const sessionCreditsUsed = useChatStore((state) => state.sessionCreditsUsed) |
| 51 | const setInputMode = useChatStore((state) => state.setInputMode) |
| 52 | |
| 53 | // Check if ChatGPT OAuth is connected |
| 54 | const isChatGptConnected = CHATGPT_OAUTH_ENABLED && isChatGptOAuthValid() |
| 55 | |
| 56 | // Fetch subscription data |
| 57 | const { data: subscriptionData, isLoading: isSubscriptionLoading } = useSubscriptionQuery({ |
| 58 | refetchInterval: 30 * 1000, |
| 59 | }) |
| 60 | |
| 61 | const { |
| 62 | data: apiData, |
| 63 | isLoading, |
| 64 | isFetching, |
| 65 | } = useUsageQuery({ |
| 66 | enabled: true, |
| 67 | refetchInterval: USAGE_POLL_INTERVAL, |
| 68 | }) |
| 69 | |
| 70 | // Get cached data for immediate display |
| 71 | const cachedUsageData = getActivityQueryData<{ |
| 72 | type: 'usage-response' |
| 73 | usage: number |
| 74 | remainingBalance: number | null |
| 75 | balanceBreakdown?: { free: number; paid: number; ad?: number } |
| 76 | next_quota_reset: string | null |
| 77 | }>(usageQueryKeys.current()) |
| 78 | |
| 79 | // Auto-hide after timeout |
| 80 | useEffect(() => { |
| 81 | const timer = setTimeout(() => { |
| 82 | setInputMode('default') |
| 83 | }, MANUAL_SHOW_TIMEOUT) |
| 84 | return () => clearTimeout(timer) |
| 85 | }, [showTime, setInputMode]) |
| 86 | |
| 87 | const theme = useTheme() |
| 88 | |
| 89 | const activeData = apiData || cachedUsageData |
| 90 | const isLoadingData = isLoading || isFetching |
| 91 | |
| 92 | // Show loading state immediately when banner is opened but data isn't ready |
| 93 | if (!activeData) { |
| 94 | return ( |
| 95 | <BottomBanner |
| 96 | borderColorKey="muted" |
| 97 | text={generateLoadingBannerText(sessionCreditsUsed)} |
| 98 | onClose={() => setInputMode('default')} |
| 99 | /> |
| 100 | ) |
| 101 | } |
| 102 | |
| 103 | const colorLevel = getBannerColorLevel(activeData.remainingBalance) |
| 104 | const renewalDate = activeData.next_quota_reset ? formatRenewalDate(activeData.next_quota_reset) : null |
nothing calls this directly
no test coverage detected