MCPcopy Create free account
hub / github.com/Dimillian/CodexMonitor / formatCreditsLabel

Function formatCreditsLabel

src/features/app/utils/usageLabels.ts:25–47  ·  view source on GitHub ↗
(accountRateLimits: RateLimitSnapshot | null)

Source from the content-addressed store, hash-verified

23}
24
25function formatCreditsLabel(accountRateLimits: RateLimitSnapshot | null) {
26 const credits = accountRateLimits?.credits ?? null;
27 if (!credits?.hasCredits) {
28 return null;
29 }
30 if (credits.unlimited) {
31 return "Available credits: Unlimited";
32 }
33 const balance = credits.balance?.trim() ?? "";
34 if (!balance) {
35 return null;
36 }
37 const intValue = Number.parseInt(balance, 10);
38 if (Number.isFinite(intValue) && intValue > 0) {
39 return `Available credits: ${intValue}`;
40 }
41 const floatValue = Number.parseFloat(balance);
42 if (Number.isFinite(floatValue) && floatValue > 0) {
43 const rounded = Math.round(floatValue);
44 return rounded > 0 ? `Available credits: ${rounded}` : null;
45 }
46 return null;
47}
48
49export function getUsageLabels(
50 accountRateLimits: RateLimitSnapshot | null,

Callers 1

getUsageLabelsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected