caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

75 lines
2.1 KiB
TypeScript

/**
* API usage manager: lists the caller's per-key current-month request usage +
* limits (GET /me/api-keys/usage, POWER-USER TIER quotas) with the shared
* loading / error / retry treatment and a manual refresh.
*
* Read-only + strictly caller-scoped by the backend; the payload NEVER carries a
* raw key or hash (only the safe `prefix`). Auth flows through the shared
* `x-api-key` token — no secrets live here.
*/
import { useCallback } from "react";
import { Pressable, StyleSheet, Text, View } from "react-native";
import { getApiKeyUsage } from "@/lib/api";
import type { ApiKeyUsage } from "@/lib/types";
import { Section, SectionState } from "@/components/me/Section";
import { colors } from "@/components/me/theme";
import { useResource } from "@/components/me/use-resource";
import { UsageCard } from "./UsageCard";
interface UsageManagerProps {
token: string | undefined;
}
export function UsageManager({ token }: UsageManagerProps) {
const fetcher = useCallback(() => getApiKeyUsage({ token }), [token]);
const { status, data, error, reload } = useResource<ApiKeyUsage[]>(fetcher);
const rows = data ?? [];
return (
<Section
title="API USAGE"
action={
<Pressable onPress={reload} hitSlop={8} accessibilityRole="button">
<Text style={styles.refresh}>Refresh</Text>
</Pressable>
}
>
<SectionState
status={status}
error={error}
onRetry={reload}
loadingLabel="Loading usage…"
>
{rows.length === 0 ? (
<Text style={styles.empty}>
No API keys yet. Create a key above to start tracking
its monthly request usage here.
</Text>
) : (
<View style={styles.list}>
{rows.map((usage) => (
<UsageCard key={usage.id} usage={usage} />
))}
</View>
)}
</SectionState>
</Section>
);
}
const styles = StyleSheet.create({
refresh: { color: colors.accent, fontWeight: "600", fontSize: 13 },
list: { gap: 10 },
empty: {
color: colors.muted,
fontSize: 13,
lineHeight: 18,
paddingVertical: 8,
},
});