AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend/copilot): gate credits-add pop-up behind ENABLE_PLATFORM_PAYMENT (#12952)
Ubbed8016e66ff4f
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/RateLimitResetDialog/RateLimitGate.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/RateLimitResetDialog/RateLimitGate.tsxindex 5f268f1396..dcefd33aea 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/RateLimitResetDialog/RateLimitGate.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/RateLimitResetDialog/RateLimitGate.tsx@@ -40,20 +40,32 @@ export function RateLimitGate({ rateLimitMessage, onDismiss }: Props) {const hasInsufficientCredits =credits !== null && resetCost != null && credits < resetCost;- // When the credit-based reset is unavailable (feature disabled or the query- // failed), fall back to a toast so the user still gets feedback.+ // Fall back to a toast when the credit-based reset isn't a real option:+ // billing is off (no way to top up), the usage query failed, or reset_cost+ // is non-positive. Without billing the dialog's "Add credits" CTA is dead,+ // so showing it would just dangle a useless reset offer.useEffect(() => {if (!rateLimitMessage) return;- if (!usageError && !(hasUsage && (resetCost ?? 0) <= 0)) return;+ const creditResetUnavailable =+ !isBillingEnabled || usageError || (hasUsage && (resetCost ?? 0) <= 0);+ if (!creditResetUnavailable) return;toast({title: "Usage limit reached",description: rateLimitMessage,variant: "destructive",});onDismiss();- }, [rateLimitMessage, resetCost, hasUsage, usageError, onDismiss]);+ }, [+ rateLimitMessage,+ resetCost,+ hasUsage,+ usageError,+ onDismiss,+ isBillingEnabled,+ ]);- const canShowDialog = !!rateLimitMessage && hasUsage && (resetCost ?? 0) > 0;+ const canShowDialog =+ isBillingEnabled && !!rateLimitMessage && hasUsage && (resetCost ?? 0) > 0;return (<RateLimitResetDialogdiff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/RateLimitResetDialog/__tests__/RateLimitGate.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/RateLimitResetDialog/__tests__/RateLimitGate.test.tsxindex 8734dc9d45..fc2a752588 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/RateLimitResetDialog/__tests__/RateLimitGate.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/RateLimitResetDialog/__tests__/RateLimitGate.test.tsx@@ -23,9 +23,10 @@ vi.mock("@/hooks/useCredits", () => ({default: () => ({ credits: 1000, fetchCredits: vi.fn() }),}));+const mockUseGetFlag = vi.fn(() => true);vi.mock("@/services/feature-flags/use-get-flag", () => ({Flag: { ENABLE_PLATFORM_PAYMENT: "ENABLE_PLATFORM_PAYMENT" },- useGetFlag: () => false,+ useGetFlag: () => mockUseGetFlag(),}));// Capture props the dialog was rendered with so we can assert on them.@@ -44,6 +45,8 @@ afterEach(() => {mockToast.mockReset();mockUseGetV2GetCopilotUsage.mockReset();dialogSpy.mockReset();+ mockUseGetFlag.mockReset();+ mockUseGetFlag.mockReturnValue(true);});describe("RateLimitGate", () => {@@ -148,6 +151,25 @@ describe("RateLimitGate", () => {expect(lastProps.isOpen).toBe(false);});+ it("falls back to a toast when ENABLE_PLATFORM_PAYMENT is off, even with a positive reset cost", () => {+ mockUseGetFlag.mockReturnValue(false);+ const onDismiss = vi.fn();+ mockUseGetV2GetCopilotUsage.mockReturnValue({+ data: { reset_cost: 50, weekly: { percent_used: 10 } },+ isSuccess: true,+ isError: false,+ });++ render(+ <RateLimitGate rateLimitMessage="limit reached" onDismiss={onDismiss} />,+ );++ expect(mockToast).toHaveBeenCalledTimes(1);+ expect(onDismiss).toHaveBeenCalledTimes(1);+ const lastProps = dialogSpy.mock.calls.at(-1)?.[0];+ expect(lastProps.isOpen).toBe(false);+ });+it("does not fire the fallback toast when no rate-limit message is present", () => {mockUseGetV2GetCopilotUsage.mockReturnValue({data: undefined,