From def469344edb5605b21877a273f170a526d837f6 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 16 Jul 2024 11:49:05 +0200 Subject: [PATCH 1/4] feat: available credit total --- src/lib/sdk/billing.ts | 1 + .../billing/availableCredit.svelte | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/sdk/billing.ts b/src/lib/sdk/billing.ts index bca6cbb0a..1bf7dbe47 100644 --- a/src/lib/sdk/billing.ts +++ b/src/lib/sdk/billing.ts @@ -111,6 +111,7 @@ export type Credit = { }; export type CreditList = { + available: number; credits: Credit[]; total: number; }; diff --git a/src/routes/console/organization-[organization]/billing/availableCredit.svelte b/src/routes/console/organization-[organization]/billing/availableCredit.svelte index 1d3d54700..be6365940 100644 --- a/src/routes/console/organization-[organization]/billing/availableCredit.svelte +++ b/src/routes/console/organization-[organization]/billing/availableCredit.svelte @@ -9,7 +9,7 @@ TableRow } from '$lib/elements/table'; import { toLocaleDate } from '$lib/helpers/date'; - import type { Credit, CreditList } from '$lib/sdk/billing'; + import type { CreditList } from '$lib/sdk/billing'; import { organization } from '$lib/stores/organization'; import { sdk } from '$lib/stores/sdk'; import { wizard } from '$lib/stores/wizard'; @@ -25,6 +25,7 @@ let offset = 0; let creditList: CreditList = { + available: 0, credits: [], total: 0 }; @@ -56,15 +57,14 @@ request(); } - $: balance = - creditList?.credits?.reduce((acc: number, curr: Credit) => acc + curr.credits, 0) ?? 0; - $: { if (reloadOnWizardClose && !$wizard.show) { request(); reloadOnWizardClose = false; } } + + $: console.log(creditList); @@ -87,7 +87,7 @@

Credit balance

- {formatCurrency(balance)} + {formatCurrency(creditList.available)}
{#if creditList?.total}