Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix: render billing responses independently

Steven Enamakel9c8c9eca4d33
diff --git a/app/src/components/settings/panels/BillingPanel.test.tsx b/app/src/components/settings/panels/BillingPanel.test.tsx
index 80912a6cdd..457948652a 100644
--- a/app/src/components/settings/panels/BillingPanel.test.tsx
+++ b/app/src/components/settings/panels/BillingPanel.test.tsx
@@ -1,4 +1,4 @@
-import { fireEvent, render, screen, waitFor } from '@testing-library/react';
+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import BillingPanel from './BillingPanel';
@@ -90,6 +90,23 @@ describe('<BillingPanel />', () => {
expect(screen.getByText(/Spent \$6\.00 this cycle/i)).toBeInTheDocument();
});
+ it('shows each response without waiting for the other request to settle', async () => {
+ let resolveUsage: (value: typeof usage) => void = () => undefined;
+ getTeamUsageMock.mockReturnValue(
+ new Promise<typeof usage>(resolve => {
+ resolveUsage = resolve;
+ })
+ );
+ render(<BillingPanel />);
+
+ expect(await screen.findByText('$4.50')).toBeInTheDocument();
+ expect(screen.getByText('$10.00')).toBeInTheDocument();
+ expect(screen.queryByText('$39.50')).not.toBeInTheDocument();
+
+ await act(async () => resolveUsage(usage));
+ expect(await screen.findByText('$39.50')).toBeInTheDocument();
+ });
+
it('uses backend-provided dashboard URLs for billing actions', async () => {
render(<BillingPanel />);
await screen.findByText('$39.50');
diff --git a/app/src/components/settings/panels/BillingPanel.tsx b/app/src/components/settings/panels/BillingPanel.tsx
index 1bae81e626..e144725352 100644
--- a/app/src/components/settings/panels/BillingPanel.tsx
+++ b/app/src/components/settings/panels/BillingPanel.tsx
@@ -24,46 +24,44 @@ const BillingPanel = () => {
const { navigateBack } = useSettingsNavigation();
const [summary, setSummary] = useState<BillingSummaryData | null>(null);
const [teamUsage, setTeamUsage] = useState<TeamUsage | null>(null);
- const [loading, setLoading] = useState(true);
+ const [summaryLoading, setSummaryLoading] = useState(true);
+ const [usageLoading, setUsageLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
let cancelled = false;
- const load = async () => {
- log('loading billing summary and cycle usage');
- const [summaryResult, usageResult] = await Promise.allSettled([
- billingApi.getSummary(),
- creditsApi.getTeamUsage(),
- ]);
- if (cancelled) return;
-
- if (summaryResult.status === 'fulfilled') {
- setSummary(summaryResult.value);
- } else {
- log('summary load failed error=%s', String(summaryResult.reason));
- }
-
- if (usageResult.status === 'fulfilled') {
- setTeamUsage(usageResult.value);
- } else {
- log('usage load failed error=%s', String(usageResult.reason));
- }
-
- const failure =
- summaryResult.status === 'rejected'
- ? summaryResult.reason
- : usageResult.status === 'rejected'
- ? usageResult.reason
- : null;
- if (failure) {
- setError(failure instanceof Error ? failure.message : String(failure));
- }
- setLoading(false);
- log('billing state applied summary=%s usage=%s', summaryResult.status, usageResult.status);
+ const recordError = (failure: unknown) => {
+ const message = failure instanceof Error ? failure.message : String(failure);
+ setError(current => current ?? message);
};
- void load();
+ log('loading billing summary and cycle usage');
+ void billingApi
+ .getSummary()
+ .then(value => {
+ if (!cancelled) setSummary(value);
+ })
+ .catch(failure => {
+ log('summary load failed error=%s', String(failure));
+ if (!cancelled) recordError(failure);
+ })
+ .finally(() => {
+ if (!cancelled) setSummaryLoading(false);
+ });
+ void creditsApi
+ .getTeamUsage()
+ .then(value => {
+ if (!cancelled) setTeamUsage(value);
+ })
+ .catch(failure => {
+ log('usage load failed error=%s', String(failure));
+ if (!cancelled) recordError(failure);
+ })
+ .finally(() => {
+ if (!cancelled) setUsageLoading(false);
+ });
+
return () => {
cancelled = true;
};
@@ -79,7 +77,11 @@ const BillingPanel = () => {
return (
<SettingsPanel>
- <SettingsStatusLine saving={loading} error={error} savingLabel={t('common.loading')} />
+ <SettingsStatusLine
+ saving={summaryLoading || usageLoading}
+ error={error}
+ savingLabel={t('common.loading')}
+ />
<section className="rounded-2xl border border-line bg-surface p-4 space-y-4">
<div className="space-y-1">
@@ -92,13 +94,17 @@ const BillingPanel = () => {
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4">
<SummaryTile
label={t('settings.billing.subscription.currentPlan')}
- value={summary?.plan?.plan ?? teamUsage?.plan?.plan ?? (loading ? '...' : unavailable)}
+ value={
+ summary?.plan?.plan ??
+ teamUsage?.plan?.plan ??
+ (summaryLoading || usageLoading ? '...' : unavailable)
+ }
/>
<SummaryTile
label={t('settings.billing.payAsYouGo.available')}
value={
availableUsd === undefined
- ? loading
+ ? usageLoading
? '...'
: unavailable
: formatUsd(availableUsd, unavailable)
@@ -109,7 +115,7 @@ const BillingPanel = () => {
value={
summary
? formatUsd(summary.credits?.promotionBalanceUsd, unavailable)
- : loading
+ : summaryLoading
? '...'
: unavailable
}
@@ -119,7 +125,7 @@ const BillingPanel = () => {
value={
summary
? formatUsd(summary.credits?.teamTopupUsd, unavailable)
- : loading
+ : summaryLoading
? '...'
: unavailable
}
@@ -127,7 +133,7 @@ const BillingPanel = () => {
</div>
</section>
- <InferenceBudget teamUsage={teamUsage} isLoadingCredits={loading} />
+ <InferenceBudget teamUsage={teamUsage} isLoadingCredits={usageLoading} />
<div className="flex flex-wrap gap-3">
<Button type="button" variant="primary" size="md" onClick={() => void openUrl(topUpUrl)}>