11import { CopyIcon } from "lucide-react" ;
22import { useEffect , useState } from "react" ;
3- import { Link , Navigate , useLocation , useNavigate , useParams } from "react-router-dom" ;
3+ import {
4+ Link ,
5+ Navigate ,
6+ useLocation ,
7+ useNavigate ,
8+ useParams ,
9+ } from "react-router-dom" ;
410import AppHeader from "src/components/AppHeader" ;
511import ExternalLink from "src/components/ExternalLink" ;
612import Loading from "src/components/Loading" ;
713
814import QRCode from "src/components/QRCode" ;
915import { suggestedApps } from "src/components/SuggestedAppData" ;
1016import { Button } from "src/components/ui/button" ;
11- import { Card , CardContent , CardHeader , CardTitle } from "src/components/ui/card" ;
17+ import {
18+ Card ,
19+ CardContent ,
20+ CardHeader ,
21+ CardTitle ,
22+ } from "src/components/ui/card" ;
1223import { useToast } from "src/components/ui/use-toast" ;
1324import { useApp } from "src/hooks/useApp" ;
1425import { copyToClipboard } from "src/lib/clipboard" ;
@@ -21,21 +32,16 @@ export default function AppConnect() {
2132 const params = useParams ( ) ;
2233 const [ timeout , setTimeout ] = useState ( false ) ;
2334 const createAppResponse = state as CreateAppResponse ;
24- const appstoreApp = suggestedApps . find ( x => x . id == params . id ) ;
35+ const appstoreApp = suggestedApps . find ( ( x ) => x . id == params . id ) ;
2536 const { data : app } = useApp ( createAppResponse . pairingPublicKey , true ) ;
2637 const pairingUri = createAppResponse . pairingUri ;
2738
28- if ( ! createAppResponse || ! appstoreApp ) {
29- return < Navigate to = "/apps/new" /> ;
30- }
31-
3239 const copy = ( ) => {
3340 copyToClipboard ( pairingUri ) ;
3441 toast ( { title : "Copied to clipboard." } ) ;
3542 } ;
3643
3744 useEffect ( ( ) => {
38-
3945 const timeoutId = window . setTimeout ( ( ) => {
4046 setTimeout ( true ) ;
4147 } , 10000 ) ;
@@ -47,11 +53,15 @@ export default function AppConnect() {
4753 if ( app ?. lastEventAt ) {
4854 toast ( {
4955 title : "Connection established!" ,
50- description : "You can now use the app with your Alby Hub."
56+ description : "You can now use the app with your Alby Hub." ,
5157 } ) ;
5258 navigate ( "/apps" ) ;
5359 }
54- } , [ app ?. lastEventAt ] )
60+ } , [ app ?. lastEventAt , navigate , toast ] ) ;
61+
62+ if ( ! createAppResponse || ! appstoreApp ) {
63+ return < Navigate to = "/apps/new" /> ;
64+ }
5565
5666 return (
5767 < >
@@ -63,15 +73,16 @@ export default function AppConnect() {
6373 < div >
6474 < p >
6575 1. Open{ " " }
66- < ExternalLink className = "font-semibold underline" to = { appstoreApp . to } >
76+ < ExternalLink
77+ className = "font-semibold underline"
78+ to = { appstoreApp . to }
79+ >
6780 { appstoreApp . title }
68- </ ExternalLink >
69- { " " }
70- and look for a way to attach a wallet (most apps provide this option in settings)
71- </ p >
72- < p >
73- 2. Scan or paste the connection secret
81+ </ ExternalLink > { " " }
82+ and look for a way to attach a wallet (most apps provide this option
83+ in settings)
7484 </ p >
85+ < p > 2. Scan or paste the connection secret</ p >
7586 </ div >
7687 < Card className = "max-w-sm" >
7788 < CardHeader >
@@ -82,19 +93,18 @@ export default function AppConnect() {
8293 < Loading className = "w-4 h-4" />
8394 < p > Waiting for app to connect</ p >
8495 </ div >
85- { timeout && < div className = "text-sm flex flex-col gap-2 items-center text-center" >
86- Connecting is taking longer than usual.
87- < Link to = { `/apps/${ app ?. nostrPubkey } ` } >
88- < Button variant = "secondary" > Continue anyway</ Button >
89- </ Link >
90- </ div > }
91- < a
92- href = { pairingUri }
93- target = "_blank"
94- className = "relative"
95- >
96+ { timeout && (
97+ < div className = "text-sm flex flex-col gap-2 items-center text-center" >
98+ Connecting is taking longer than usual.
99+ < Link to = { `/apps/${ app ?. nostrPubkey } ` } >
100+ < Button variant = "secondary" > Continue anyway</ Button >
101+ </ Link >
102+ </ div >
103+ ) }
104+ < a href = { pairingUri } target = "_blank" className = "relative" >
96105 < QRCode value = { pairingUri } className = "w-full" />
97- < img src = { appstoreApp . logo }
106+ < img
107+ src = { appstoreApp . logo }
98108 className = "absolute w-12 h-12 top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 bg-muted p-1 rounded-xl"
99109 />
100110 </ a >
0 commit comments