Skip to content

Commit a07807b

Browse files
EmilFattakhovclaude
andcommitted
fix(frontend): gate credits API calls behind buyCredits feature flag
The backend returns 404 for /credits/summary and /credits/batches/expiring when BUY_CREDITS_ACTIVE is disabled. SessionEnsurer was polling /credits/summary every 30 s and ExpiryWarningBanner was polling /credits/batches/expiring every 5 min for all authenticated users, flooding the console with 404 errors and adding unnecessary network overhead. Both queries now use `enabled: !!session?.data && !!features?.buyCredits` so they only fire when the feature flag is actually on. ExpiryWarningBanner also gains the useUserStore import needed to read the flag. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ca24477 commit a07807b

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

apps/frontend/src/components/atoms/ExpiryWarningBanner.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
sumExpiringUploadBytes,
1212
} from '../../utils/credits';
1313
import { BannerShell } from '../organisms/BannerNotifications/BannerShell';
14+
import { useUserStore } from '../../globalStates/user';
1415

1516
/**
1617
* Displays a warning banner when the user has purchased credits that will
@@ -20,13 +21,16 @@ import { BannerShell } from '../organisms/BannerNotifications/BannerShell';
2021
export const ExpiryWarningBanner = () => {
2122
const { api } = useNetwork();
2223
const session = useContext(SessionContext);
24+
const features = useUserStore((m) => m.features);
2325

2426
const { data: expiringBatches } = useQuery<ExpiringCreditBatch[]>({
2527
queryKey: ['expiringCreditBatches'],
2628
queryFn: () => api.getExpiringCreditBatches(),
2729
// Refresh every 5 minutes – expiry warnings don't need to be real-time
2830
refetchInterval: 5 * 60 * 1000,
29-
enabled: !!session?.data,
31+
// Only fetch when the buyCredits feature flag is enabled – the backend
32+
// returns 404 for these endpoints when the flag is off.
33+
enabled: !!session?.data && !!features?.buyCredits,
3034
});
3135

3236
if (!expiringBatches || expiringBatches.length === 0) return null;

apps/frontend/src/components/atoms/SessionEnsurer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ export const SessionEnsurer = ({ children }: { children: React.ReactNode }) => {
6161
queryFn: () => api.getCreditSummary(),
6262
// Refresh every 30 s so the cap / balance stays reasonably fresh
6363
refetchInterval: 30_000,
64-
enabled: !!session?.data,
64+
// Only fetch when the buyCredits feature flag is enabled – the backend
65+
// returns 404 for these endpoints when the flag is off.
66+
enabled: !!session?.data && !!features?.buyCredits,
6567
});
6668

6769
const { data: touStatusData, isLoading: touStatusLoading } = useQuery({

0 commit comments

Comments
 (0)