fix(frontend): Remove unused Stripe on frontend (#9536)

### Changes 🏗️

Remove Stripe on frontend.

### Checklist 📋

#### For code changes:
- [ ] I have clearly listed my changes in the PR description
- [ ] I have made a test plan
- [ ] I have tested my changes according to the test plan:
  <!-- Put your test plan here: -->
  - [ ] ...

<details>
  <summary>Example test plan</summary>
  
  - [ ] Create from scratch and execute an agent with at least 3 blocks
- [ ] Import an agent from file upload, and confirm it executes
correctly
  - [ ] Upload agent to marketplace
- [ ] Import an agent from marketplace and confirm it executes correctly
  - [ ] Edit an agent from monitor, and confirm it executes correctly
</details>

#### For configuration changes:
- [ ] `.env.example` is updated or already compatible with my changes
- [ ] `docker-compose.yml` is updated or already compatible with my
changes
- [ ] I have included a list of my configuration changes in the PR
description (under **Changes**)

<details>
  <summary>Examples of configuration changes</summary>

  - Changing ports
  - Adding new services that need to communicate with each other
  - Secrets or environment variable changes
  - New or infrastructure changes such as databases
</details>
This commit is contained in:
Zamil Majdy
2025-02-27 18:13:53 +07:00
committed by GitHub
parent c1b12d4a12
commit 52ee7d150e
6 changed files with 20 additions and 63 deletions

View File

@@ -34,7 +34,6 @@ export default function CreditsPage() {
fetchInitialAutoTopUpConfig: true,
fetchInitialRefundRequests: true,
fetchInitialTransactionHistory: true,
fetchTopUpLibrary: true,
});
const router = useRouter();
const searchParams = useSearchParams();

View File

@@ -23,10 +23,6 @@ interface SidebarProps {
}
export const Sidebar: React.FC<SidebarProps> = ({ linkGroups }) => {
const stripeAvailable = Boolean(
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY,
);
return (
<>
<Sheet>
@@ -54,17 +50,15 @@ export const Sidebar: React.FC<SidebarProps> = ({ linkGroups }) => {
Creator dashboard
</div>
</Link>
{stripeAvailable && (
<Link
href="/profile/credits"
className="inline-flex w-full items-center gap-2.5 rounded-xl px-3 py-3 text-neutral-800 hover:bg-neutral-800 hover:text-white dark:text-neutral-200 dark:hover:bg-neutral-700 dark:hover:text-white"
>
<IconCoin className="h-6 w-6" />
<div className="p-ui-medium text-base font-medium leading-normal">
Billing
</div>
</Link>
)}
<Link
href="/profile/credits"
className="inline-flex w-full items-center gap-2.5 rounded-xl px-3 py-3 text-neutral-800 hover:bg-neutral-800 hover:text-white dark:text-neutral-200 dark:hover:bg-neutral-700 dark:hover:text-white"
>
<IconCoin className="h-6 w-6" />
<div className="p-ui-medium text-base font-medium leading-normal">
Billing
</div>
</Link>
<Link
href="/profile/integrations"
className="inline-flex w-full items-center gap-2.5 rounded-xl px-3 py-3 text-neutral-800 hover:bg-neutral-800 hover:text-white dark:text-neutral-200 dark:hover:bg-neutral-700 dark:hover:text-white"
@@ -118,17 +112,15 @@ export const Sidebar: React.FC<SidebarProps> = ({ linkGroups }) => {
Agent dashboard
</div>
</Link>
{stripeAvailable && (
<Link
href="/profile/credits"
className="inline-flex w-full items-center gap-2.5 rounded-xl px-3 py-3 text-neutral-800 hover:bg-neutral-800 hover:text-white dark:text-neutral-200 dark:hover:bg-neutral-700 dark:hover:text-white"
>
<IconCoin className="h-6 w-6" />
<div className="p-ui-medium text-base font-medium leading-normal">
Billing
</div>
</Link>
)}
<Link
href="/profile/credits"
className="inline-flex w-full items-center gap-2.5 rounded-xl px-3 py-3 text-neutral-800 hover:bg-neutral-800 hover:text-white dark:text-neutral-200 dark:hover:bg-neutral-700 dark:hover:text-white"
>
<IconCoin className="h-6 w-6" />
<div className="p-ui-medium text-base font-medium leading-normal">
Billing
</div>
</Link>
<Link
href="/profile/integrations"
className="inline-flex w-full items-center gap-2.5 rounded-xl px-3 py-3 text-neutral-800 hover:bg-neutral-800 hover:text-white dark:text-neutral-200 dark:hover:bg-neutral-700 dark:hover:text-white"

View File

@@ -4,7 +4,6 @@ import {
TransactionHistory,
} from "@/lib/autogpt-server-api/types";
import { useCallback, useEffect, useMemo, useState } from "react";
import { loadStripe, Stripe } from "@stripe/stripe-js";
import { useRouter } from "next/navigation";
export default function useCredits({
@@ -12,13 +11,11 @@ export default function useCredits({
fetchInitialAutoTopUpConfig = false,
fetchInitialTransactionHistory = false,
fetchInitialRefundRequests = false,
fetchTopUpLibrary = false,
}: {
fetchInitialCredits?: boolean;
fetchInitialAutoTopUpConfig?: boolean;
fetchInitialTransactionHistory?: boolean;
fetchInitialRefundRequests?: boolean;
fetchTopUpLibrary?: boolean;
} = {}): {
credits: number | null;
fetchCredits: () => void;
@@ -38,7 +35,6 @@ export default function useCredits({
amount: number;
threshold: number;
} | null>(null);
const [stripe, setStripe] = useState<Stripe | null>(null);
const api = useMemo(() => new AutoGPTServerAPI(), []);
const router = useRouter();
@@ -53,21 +49,6 @@ export default function useCredits({
fetchCredits();
}, [fetchCredits, fetchInitialCredits]);
useEffect(() => {
if (!fetchTopUpLibrary) return;
const fetchStripe = async () => {
if (!process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY?.trim()) {
console.debug("Stripe publishable key is not set.");
return;
}
const stripe = await loadStripe(
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY,
);
setStripe(stripe);
};
fetchStripe();
}, [fetchTopUpLibrary]);
const fetchAutoTopUpConfig = useCallback(async () => {
const response = await api.getAutoTopUpConfig();
setAutoTopUpConfig(response);
@@ -88,18 +69,10 @@ export default function useCredits({
const requestTopUp = useCallback(
async (credit_amount: number) => {
if (!stripe) {
console.error(
"Trying to top-up failed because Stripe is not loaded." +
"Did you set NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY?",
);
return;
}
const response = await api.requestTopUp(credit_amount);
router.push(response.checkout_url);
},
[api, router, stripe],
[api, router],
);
const refundTopUp = useCallback(