From 08829c24ff019facb06937f29d18a8fb0653889e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Aaron?= Date: Mon, 30 Sep 2024 09:56:50 +0200 Subject: [PATCH] feat: zapplanner integration --- frontend/src/components/SuggestedAppData.tsx | 60 +------- frontend/src/routes.tsx | 5 + .../src/screens/internal-apps/Zapplanner.tsx | 142 ++++++++++++++++++ 3 files changed, 148 insertions(+), 59 deletions(-) create mode 100644 frontend/src/screens/internal-apps/Zapplanner.tsx diff --git a/frontend/src/components/SuggestedAppData.tsx b/frontend/src/components/SuggestedAppData.tsx index 2e571232..b23979ae 100644 --- a/frontend/src/components/SuggestedAppData.tsx +++ b/frontend/src/components/SuggestedAppData.tsx @@ -647,65 +647,7 @@ export const suggestedApps: SuggestedApp[] = [ description: "Schedule payments", webLink: "https://zapplanner.albylabs.com/", logo: zapplanner, - guide: ( - <> -
-

In ZapPlanner

- -
-
-

In Alby Hub

- -
-
-

In ZapPlanner

- -
- - ), + internal: true, }, { id: "zapplepay", diff --git a/frontend/src/routes.tsx b/frontend/src/routes.tsx index 96648661..93bc4cbe 100644 --- a/frontend/src/routes.tsx +++ b/frontend/src/routes.tsx @@ -36,6 +36,7 @@ import { OpenedFirstChannel } from "src/screens/channels/first/OpenedFirstChanne import { OpeningFirstChannel } from "src/screens/channels/first/OpeningFirstChannel"; import { BuzzPay } from "src/screens/internal-apps/BuzzPay"; import { UncleJim } from "src/screens/internal-apps/UncleJim"; +import { Zapplanner } from "src/screens/internal-apps/Zapplanner"; import BuyBitcoin from "src/screens/onchain/BuyBitcoin"; import DepositBitcoin from "src/screens/onchain/DepositBitcoin"; import ConnectPeer from "src/screens/peers/ConnectPeer"; @@ -217,6 +218,10 @@ const routes = [ path: "buzzpay", element: , }, + { + path: "zapplanner", + element: , + }, ], }, { diff --git a/frontend/src/screens/internal-apps/Zapplanner.tsx b/frontend/src/screens/internal-apps/Zapplanner.tsx new file mode 100644 index 00000000..9da74138 --- /dev/null +++ b/frontend/src/screens/internal-apps/Zapplanner.tsx @@ -0,0 +1,142 @@ +import React from "react"; +import AppHeader from "src/components/AppHeader"; +import AppCard from "src/components/connections/AppCard"; +import { Button } from "src/components/ui/button"; +import { + Card, + CardDescription, + CardFooter, + CardHeader, + CardTitle, +} from "src/components/ui/card"; +import { useToast } from "src/components/ui/use-toast"; +import { useApps } from "src/hooks/useApps"; +import { createApp } from "src/requests/createApp"; +import { CreateAppRequest } from "src/types"; +import { handleRequestError } from "src/utils/handleRequestError"; + +export function Zapplanner() { + const { data: apps, mutate: reloadApps } = useApps(); + const { toast } = useToast(); + const [, setLoading] = React.useState(false); + const handleSubmit = async (name: string) => { + setLoading(true); + + try { + if (apps?.some((existingApp) => existingApp.name === name)) { + throw new Error("A connection with the same name already exists."); + } + + const createAppRequest: CreateAppRequest = { + name, + scopes: [ + "get_balance", + "get_info", + "list_transactions", + "lookup_invoice", + "make_invoice", + "notifications", + "pay_invoice", + ], + isolated: true, + metadata: { + app_store_app_id: "zapplanner", + }, + }; + + await createApp(createAppRequest); + toast({ + title: "Created subscription", + description: "The first payment is scheduled for 1st of October.", + }); + + reloadApps(); + } catch (error) { + handleRequestError(toast, "Failed to create app", error); + } + setLoading(false); + }; + + const zapplannerApps = apps?.filter( + (app) => app.metadata?.app_store_app_id === "zapplanner" + ); + + return ( +
+ +

Inspiration

+

+ Be the change you want to see in the world and do your part +

+
+ + + Alby + description + + + + + + + + HRF + description + + + + + + + + opensats + description + + + + + +
+ {/* {!connectionSecret && ( + <> +
+
+ + setName(e.target.value)} + required + autoComplete="off" + /> +
+ + Create Subaccount + +
*/} + + {!!zapplannerApps?.length && ( + <> +

Recurring Payments

+
+ {zapplannerApps.map((app, index) => ( + + ))} +
+ + )} +
+ ); +}