mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
fix(usage): only show CLI subscription quota for active provider
CLI-credential-based subscriptions (Claude/Codex/Gemini) read from a single global credential file, so the quota always reflects the last CLI login rather than a specific provider. Showing it on non-current cards is misleading when multiple official subscriptions exist. Apply the same isCurrent + autoQuery pattern already used by Copilot and Codex OAuth: only query and render the quota footer when the provider is the currently active one.
This commit is contained in:
@@ -8,6 +8,7 @@ import type { QuotaTier, SubscriptionQuota } from "@/types/subscription";
|
||||
interface SubscriptionQuotaFooterProps {
|
||||
appId: AppId;
|
||||
inline?: boolean;
|
||||
isCurrent?: boolean;
|
||||
}
|
||||
|
||||
interface SubscriptionQuotaViewProps {
|
||||
@@ -386,12 +387,15 @@ const TierBar: React.FC<{
|
||||
const SubscriptionQuotaFooter: React.FC<SubscriptionQuotaFooterProps> = ({
|
||||
appId,
|
||||
inline = false,
|
||||
isCurrent = false,
|
||||
}) => {
|
||||
const {
|
||||
data: quota,
|
||||
isFetching: loading,
|
||||
refetch,
|
||||
} = useSubscriptionQuota(appId, true);
|
||||
} = useSubscriptionQuota(appId, isCurrent, isCurrent);
|
||||
|
||||
if (!isCurrent) return null;
|
||||
|
||||
return (
|
||||
<SubscriptionQuotaView
|
||||
|
||||
@@ -369,7 +369,7 @@ export function ProviderCard({
|
||||
isCurrent={isCurrent}
|
||||
/>
|
||||
) : isOfficial ? (
|
||||
<SubscriptionQuotaFooter appId={appId} inline={true} />
|
||||
<SubscriptionQuotaFooter appId={appId} inline={true} isCurrent={isCurrent} />
|
||||
) : hasMultiplePlans ? (
|
||||
<div className="flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400">
|
||||
<span className="font-medium">
|
||||
|
||||
@@ -7,13 +7,18 @@ import { PROVIDER_TYPES } from "@/config/constants";
|
||||
|
||||
const REFETCH_INTERVAL = 5 * 60 * 1000; // 5 minutes
|
||||
|
||||
export function useSubscriptionQuota(appId: AppId, enabled: boolean) {
|
||||
export function useSubscriptionQuota(
|
||||
appId: AppId,
|
||||
enabled: boolean,
|
||||
autoQuery = false,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ["subscription", "quota", appId],
|
||||
queryFn: () => subscriptionApi.getQuota(appId),
|
||||
enabled: enabled && ["claude", "codex", "gemini"].includes(appId),
|
||||
refetchInterval: REFETCH_INTERVAL,
|
||||
refetchOnWindowFocus: true,
|
||||
refetchInterval: autoQuery ? REFETCH_INTERVAL : false,
|
||||
refetchIntervalInBackground: autoQuery,
|
||||
refetchOnWindowFocus: autoQuery,
|
||||
staleTime: REFETCH_INTERVAL,
|
||||
retry: 1,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user