import { AlertTriangleIcon, CopyIcon, ExternalLinkIcon } from "lucide-react"; import React, { useEffect } from "react"; import { toast } from "sonner"; import AppHeader from "src/components/AppHeader"; import AppCard from "src/components/connections/AppCard"; import { appStoreApps } from "src/components/connections/SuggestedAppData"; import QRCode from "src/components/QRCode"; import { Alert, AlertDescription, AlertTitle } from "src/components/ui/alert"; import { Button } from "src/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle, } from "src/components/ui/card"; import { LoadingButton } from "src/components/ui/custom/loading-button"; import { Input } from "src/components/ui/input"; import { DEFAULT_APP_BUDGET_RENEWAL, DEFAULT_APP_BUDGET_SATS, } from "src/constants"; import { useApps } from "src/hooks/useApps"; import { copyToClipboard } from "src/lib/clipboard"; import { createApp } from "src/requests/createApp"; import { handleRequestError } from "src/utils/handleRequestError"; import { openLink } from "src/utils/openLink"; export function Tictactoe() { const appId = "tictactoe"; const [isLoading, setLoading] = React.useState(false); const [appLink, setAppLink] = React.useState(""); const { data: appsData, mutate: reloadApps } = useApps(undefined, undefined, { appStoreAppId: appId, }); const tictactoeApps = appsData?.apps; const appStoreApp = appStoreApps.find((app) => app.id === appId)!; useEffect(() => { if (appLink) { window.open(appLink, "_blank"); } }, [appLink]); const handleSubmit = (event: React.FormEvent) => { event.preventDefault(); setLoading(true); (async () => { try { const createAppResponse = await createApp({ name: appStoreApp.title, scopes: ["get_info", "lookup_invoice", "make_invoice", "pay_invoice"], maxAmountSat: DEFAULT_APP_BUDGET_SATS, budgetRenewal: DEFAULT_APP_BUDGET_RENEWAL, metadata: { app_store_app_id: appId, }, }); setAppLink( `https://lntictactoe.com/#nwc=${encodeURIComponent(createAppResponse.pairingUri)}` ); toast("Tic Tac Toe connection created"); } catch (error) { handleRequestError("Failed to create connection", error); } setLoading(false); reloadApps(); })(); }; return (
{appStoreApp.title}
{appStoreApp.description}
} /> {appLink ? (

Open the link below to start playing.

Save this link and add it to your home screen This link will only be shown once and can't be retrieved afterwards. Please make sure to keep it somewhere safe.
openLink(appLink)} >
) : ( About the App

By connecting Tic Tac Toe to your Alby Hub, you can play
tic tac toe with your friends and earn satoshis.

Start playing
)} {!!tictactoeApps?.length && ( <>

Tic Tac Toe connections

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