diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 9d698e11..8acb296d 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -39,8 +39,6 @@ import { BackupNode } from "src/screens/BackupNode"; import { BackupNodeSuccess } from "src/screens/BackupNodeSuccess"; import { Intro } from "src/screens/Intro"; import AlbyAuthRedirect from "src/screens/alby/AlbyAuthRedirect"; -import AppConnect from "src/screens/appstore/AppConnect"; -import AppDetail from "src/screens/appstore/AppDetail"; import { CurrentChannelOrder } from "src/screens/channels/CurrentChannelOrder"; import { Success } from "src/screens/onboarding/Success"; import Peers from "src/screens/peers/Peers"; @@ -79,8 +77,6 @@ function App() { }> } /> - } /> - } /> }> } /> diff --git a/frontend/src/components/Permissions.tsx b/frontend/src/components/Permissions.tsx index ff60ff57..4aee0116 100644 --- a/frontend/src/components/Permissions.tsx +++ b/frontend/src/components/Permissions.tsx @@ -26,20 +26,20 @@ interface PermissionsProps { initialPermissions: AppPermissions; onPermissionsChange: (permissions: AppPermissions) => void; budgetUsage?: number; - isEditing: boolean; - isNew?: boolean; + canEditPermissions: boolean; + isNewConnection?: boolean; } const Permissions: React.FC = ({ initialPermissions, onPermissionsChange, - isEditing, - isNew, + canEditPermissions, + isNewConnection, budgetUsage, }) => { const [permissions, setPermissions] = React.useState(initialPermissions); - const [days, setDays] = useState(isNew ? 0 : -1); - const [expireOptions, setExpireOptions] = useState(!isNew); + const [days, setDays] = useState(isNewConnection ? 0 : -1); + const [expireOptions, setExpireOptions] = useState(!isNewConnection); useEffect(() => { setPermissions(initialPermissions); @@ -54,7 +54,7 @@ const Permissions: React.FC = ({ }; const handleRequestMethodChange = (requestMethod: PermissionType) => { - if (!isEditing) { + if (!canEditPermissions) { return; } @@ -109,7 +109,7 @@ const Permissions: React.FC = ({ className={cn( "w-full", rm == "pay_invoice" ? "order-last" : "", - !isEditing && !permissions.requestMethods.has(rm) + !canEditPermissions && !permissions.requestMethods.has(rm) ? "hidden" : "" )} @@ -119,19 +119,22 @@ const Permissions: React.FC = ({ )} handleRequestMethodChange(rm)} checked={permissions.requestMethods.has(rm)} /> @@ -141,23 +144,23 @@ const Permissions: React.FC = ({ className={cn( "pt-2 pb-2 pl-5 ml-2.5 border-l-2 border-l-primary", !permissions.requestMethods.has(rm) - ? isEditing + ? canEditPermissions ? "pointer-events-none opacity-30" : "hidden" : "" )} > - {isEditing ? ( + {canEditPermissions ? ( <>

Budget Renewal:

- {!isEditing ? ( + {!canEditPermissions ? ( permissions.budgetRenewal ) : ( {
+ {returnTo && ( +

+ You will automatically return to {returnTo} +

+ )} diff --git a/frontend/src/screens/apps/ShowApp.tsx b/frontend/src/screens/apps/ShowApp.tsx index 4dff80f7..c698a0db 100644 --- a/frontend/src/screens/apps/ShowApp.tsx +++ b/frontend/src/screens/apps/ShowApp.tsx @@ -238,7 +238,7 @@ function ShowApp() { initialPermissions={permissions} onPermissionsChange={setPermissions} budgetUsage={app.budgetUsage} - isEditing={editMode} + canEditPermissions={editMode} /> diff --git a/frontend/src/screens/appstore/AppConnect.tsx b/frontend/src/screens/appstore/AppConnect.tsx deleted file mode 100644 index d9ed5c52..00000000 --- a/frontend/src/screens/appstore/AppConnect.tsx +++ /dev/null @@ -1,122 +0,0 @@ -import { CopyIcon } from "lucide-react"; -import { useEffect, useState } from "react"; -import { - Link, - Navigate, - useLocation, - useNavigate, - useParams, -} from "react-router-dom"; -import AppHeader from "src/components/AppHeader"; -import ExternalLink from "src/components/ExternalLink"; -import Loading from "src/components/Loading"; - -import QRCode from "src/components/QRCode"; -import { suggestedApps } from "src/components/SuggestedAppData"; -import { Button } from "src/components/ui/button"; -import { - Card, - CardContent, - CardHeader, - CardTitle, -} from "src/components/ui/card"; -import { useToast } from "src/components/ui/use-toast"; -import { useApp } from "src/hooks/useApp"; -import { copyToClipboard } from "src/lib/clipboard"; -import { CreateAppResponse } from "src/types"; - -export default function AppConnect() { - const { state } = useLocation(); - const navigate = useNavigate(); - const { toast } = useToast(); - const params = useParams(); - const [timeout, setTimeout] = useState(false); - const createAppResponse = state as CreateAppResponse; - const appstoreApp = suggestedApps.find((x) => x.id == params.id); - const { data: app } = useApp(createAppResponse.pairingPublicKey, true); - const pairingUri = createAppResponse.pairingUri; - - const copy = () => { - copyToClipboard(pairingUri); - toast({ title: "Copied to clipboard." }); - }; - - useEffect(() => { - const timeoutId = window.setTimeout(() => { - setTimeout(true); - }, 10000); - - return () => window.clearTimeout(timeoutId); - }, []); - - useEffect(() => { - if (app?.lastEventAt) { - toast({ - title: "Connection established!", - description: "You can now use the app with your Alby Hub.", - }); - navigate("/apps"); - } - }, [app?.lastEventAt, navigate, toast]); - - if (!createAppResponse || !appstoreApp) { - return ; - } - - return ( - <> - -
-
-

- 1. Open{" "} - - {appstoreApp.title} - {" "} - and look for a way to attach a wallet (most apps provide this option - in settings) -

-

2. Scan or paste the connection secret

-
- - - Connection Secret - - -
- -

Waiting for app to connect

-
- {timeout && ( -
- Connecting is taking longer than usual. - - - -
- )} - - - - -
- -
-
-
-
- - ); -} diff --git a/frontend/src/screens/appstore/AppDetail.tsx b/frontend/src/screens/appstore/AppDetail.tsx deleted file mode 100644 index a2dbce86..00000000 --- a/frontend/src/screens/appstore/AppDetail.tsx +++ /dev/null @@ -1,107 +0,0 @@ -import { useState } from "react"; -import { useNavigate, useParams } from "react-router-dom"; -import AppHeader from "src/components/AppHeader"; -import { suggestedApps } from "src/components/SuggestedAppData"; -import { Button } from "src/components/ui/button"; -import { Separator } from "src/components/ui/separator"; -import { toast } from "src/components/ui/use-toast"; -import { useCSRF } from "src/hooks/useCSRF"; -import { - AppPermissions, - CreateAppResponse, - PermissionType, - nip47PermissionDescriptions, -} from "src/types"; -import { handleRequestError } from "src/utils/handleRequestError"; -import { request } from "src/utils/request"; -import Permissions from "../../components/Permissions"; - -export default function AppDetail() { - const params = useParams(); - const navigate = useNavigate(); - const { data: csrf } = useCSRF(); - - const app = suggestedApps.find((x) => x.id == params.id); - - const methods = Object.keys(nip47PermissionDescriptions); - const requestMethodsSet = new Set( - methods as PermissionType[] - ); - - const [permissions, setPermissions] = useState({ - requestMethods: requestMethodsSet, - maxAmount: 100000, - budgetRenewal: "monthly", - }); - - const handleSubmit = async (event: React.FormEvent) => { - event.preventDefault(); - if (!csrf) { - throw new Error("No CSRF token"); - } - - try { - const createAppResponse = await request("/api/apps", { - method: "POST", - headers: { - "X-CSRF-Token": csrf, - "Content-Type": "application/json", - }, - body: JSON.stringify({ - name: app?.title, - ...permissions, - requestMethods: [...permissions.requestMethods].join(" "), - expiresAt: permissions.expiresAt?.toISOString(), - }), - }); - - if (!createAppResponse) { - throw new Error("no create app response received"); - } - - navigate("/appstore/" + app?.id + "/connect", { - state: createAppResponse, - }); - toast({ title: "App created" }); - } catch (error) { - handleRequestError(toast, "Failed to create app", error); - } - }; - - if (!app) { - return; - } - - return ( - <> - -
-
- -

{app.title}

-
- -
-

Authorize the app to:

- -
- - - - - - - ); -}