Skip to content

Commit a666f2d

Browse files
committed
add: credit limit info.
1 parent 37437e0 commit a666f2d

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

src/lib/components/navbar.svelte

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
9191
let credits = $state(0);
9292
let creditsUsed = $state(0);
93+
let enforcedCreditLimit = $state(0);
94+
95+
let monthlyCredits = $state(0);
96+
let dailyCredits: number | null = $state(null);
97+
9398
let showSupport = $state(false);
9499
let activeTheme = $state($app.theme);
95100
let shouldAnimateThemeToggle = $state(false);
@@ -130,9 +135,12 @@
130135
131136
const usage = await sdk.forConsole.billing.listUsage(org.$id, startDate, endDate);
132137
creditsUsed = usage.imagineCreditsTotal;
133-
const creditsLimit = plan?.limits?.credits ?? 0;
134138
135-
credits = Math.max(0, creditsLimit - creditsUsed);
139+
monthlyCredits = plan?.limits?.credits ?? 0;
140+
dailyCredits = plan?.limits?.dailyCredits ?? null;
141+
enforcedCreditLimit = dailyCredits ?? monthlyCredits ?? 0;
142+
143+
credits = Math.max(0, enforcedCreditLimit - creditsUsed);
136144
}
137145
138146
beforeNavigate(() => (showAccountMenu = false));
@@ -307,14 +315,23 @@
307315
>{credits} Credit(s) left
308316
</Layout.Stack>
309317
<svelte:fragment slot="more">
310-
<ProgressBar
311-
maxSize={plan.limits.credits ?? 0}
312-
data={[
313-
{
314-
size: credits,
315-
color: 'var(--bgcolor-neutral-invert)'
316-
}
317-
]} />
318+
<Layout.Stack>
319+
<ProgressBar
320+
maxSize={enforcedCreditLimit}
321+
data={[
322+
{
323+
size: credits,
324+
color: 'var(--bgcolor-neutral-invert)'
325+
}
326+
]} />
327+
328+
{#if dailyCredits !== null}
329+
<Typography.Caption>
330+
{dailyCredits} daily and {monthlyCredits} monthly
331+
credits
332+
</Typography.Caption>
333+
{/if}
334+
</Layout.Stack>
318335
</svelte:fragment>
319336
</ActionMenu.Item.Anchor>
320337
<Divider />

0 commit comments

Comments
 (0)