Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit 3100931

Browse files
committed
fix(firmware): handle null reset in quota display
When quota hasn't been used yet, the API returns null for reset since the 5-hour rolling window hasn't started. Now only shows reset time when it's available, displaying just 'X% used' otherwise.
1 parent f64bdd3 commit 3100931

3 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/api/providers/fetchers/firmware.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export async function getFirmwareModels(apiKey?: string): Promise<ModelRecord> {
119119

120120
export interface FirmwareQuotaResponse {
121121
used: number // 0 to 1 scale (1 = limit reached)
122-
reset: string // ISO timestamp when quota resets
122+
reset: string | null // ISO timestamp when quota resets, null if window hasn't started
123123
}
124124

125125
/**
@@ -160,7 +160,7 @@ export async function getFirmwareQuota(apiKey: string): Promise<FirmwareQuotaRes
160160

161161
return {
162162
used: data.used ?? 0,
163-
reset: data.reset ?? new Date().toISOString(),
163+
reset: data.reset ?? null,
164164
}
165165
} finally {
166166
clearTimeout(timeoutId)

webview-ui/src/components/settings/providers/FirmwareQuotaDisplay.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ export const FirmwareQuotaDisplay = () => {
1818
}
1919

2020
const percentUsed = (quota.used * 100).toFixed(2)
21-
const resetDate = new Date(quota.reset)
22-
const now = new Date()
23-
const msUntilReset = resetDate.getTime() - now.getTime()
21+
22+
// Calculate reset time only if reset is provided
23+
let resetText = ""
24+
if (quota.reset) {
25+
const resetDate = new Date(quota.reset)
26+
const now = new Date()
27+
const msUntilReset = resetDate.getTime() - now.getTime()
28+
resetText = ` · resets in ${formatTimeUntilReset(msUntilReset)}`
29+
}
2430

2531
const isAtLimit = quota.used >= 1
2632
const isWarning = quota.used >= 0.8
2733

28-
const statusText = isAtLimit
29-
? `Limit reached · resets in ${formatTimeUntilReset(msUntilReset)}`
30-
: `${percentUsed}% used · resets in ${formatTimeUntilReset(msUntilReset)}`
34+
const statusText = isAtLimit ? `Limit reached${resetText}` : `${percentUsed}% used${resetText}`
3135

3236
const colorClass = isAtLimit
3337
? "text-vscode-errorForeground"

webview-ui/src/components/ui/hooks/useFirmwareQuota.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { vscode } from "@src/utils/vscode"
66

77
export interface FirmwareQuotaInfo {
88
used: number // 0 to 1 scale (1 = limit reached)
9-
reset: string // ISO timestamp when quota resets
9+
reset: string | null // ISO timestamp when quota resets, null if window hasn't started
1010
}
1111

1212
export const useFirmwareQuota = () => {

0 commit comments

Comments
 (0)