@@ -7,27 +7,54 @@ import {
7
7
} from "../lib/dynamic" ;
8
8
9
9
import Spinner from "./Spinner" ;
10
+ import AccountModal from "./AccountModal" ;
10
11
11
12
export default function Main ( ) {
12
13
const { sdkHasLoaded, user } = useDynamicContext ( ) ;
13
- const { telegramSignIn } = useTelegramLogin ( ) ;
14
+ const { telegramSignIn, isAuthWithTelegram } = useTelegramLogin ( ) ;
14
15
const [ isLoading , setIsLoading ] = useState < boolean > ( true ) ;
16
+ const [ showModal , setShowModal ] = useState ( false ) ;
15
17
16
18
useEffect ( ( ) => {
17
19
if ( ! sdkHasLoaded ) return ;
18
20
19
- const signIn = async ( ) => {
20
- if ( ! user ) {
21
- await telegramSignIn ( { forceCreateUser : true } ) ;
21
+ const checkTelegramConnection = async ( ) => {
22
+ setIsLoading ( true ) ;
23
+ const isLinkedWithTelegram = await isAuthWithTelegram ( ) ;
24
+
25
+ if ( isLinkedWithTelegram ) {
26
+ // Auto login if Telegram is connected
27
+ await telegramSignIn ( ) ;
28
+ } else {
29
+ // Show modal splash page
30
+ setShowModal ( true ) ;
22
31
}
23
32
setIsLoading ( false ) ;
24
33
} ;
25
34
26
- signIn ( ) ;
27
- } , [ sdkHasLoaded ] ) ;
35
+ if ( user ) {
36
+ setIsLoading ( false ) ;
37
+ return ;
38
+ }
39
+ checkTelegramConnection ( ) ;
40
+ } , [ sdkHasLoaded , isLoading ] ) ;
41
+
42
+ const handleModalResponse = async ( hasAccount : boolean ) => {
43
+ setShowModal ( false ) ;
44
+ if ( hasAccount ) {
45
+ // Prompt developer's login
46
+ console . log ( "User already has an account on XYZ" ) ;
47
+ } else {
48
+ // Call signIn with autoCreate: true
49
+ console . log (
50
+ "User does not have an account on XYZ => Auto Create + Auto Login"
51
+ ) ;
52
+ await telegramSignIn ( { forceCreateUser : true } ) ;
53
+ }
54
+ } ;
28
55
29
56
return (
30
- < div className = "min-h-screen flex flex-col items-center justify-center text-black" style = { { backgroundColor : " #f9f9fb" , backgroundImage : " url('/background-pattern.svg')" , backgroundBlendMode : " overlay", backgroundRepeat : "repeat" } } >
57
+ < div className = "min-h-screen flex flex-col items-center justify-center text-black bg-[ #f9f9fb] bg-[ url('/background-pattern.svg')] bg-repeat bg-blend- overlay" >
31
58
< div className = "flex flex-col items-center justify-center text-center max-w-3xl px-4" >
32
59
< div className = "pt-8" >
33
60
< div className = "inline-flex items-center justify-center" >
@@ -36,21 +63,37 @@ export default function Main() {
36
63
</ div >
37
64
38
65
< div className = "bg-white p-5 rounded-lg shadow-sm mb-7 mt-7 text-sm" >
39
- < h2 className = "text-xl font-semibold mb-3" > You got an auto-wallet!</ h2 >
66
+ { user && (
67
+ < h2 className = "text-xl font-semibold mb-3" >
68
+ You got an auto-wallet!
69
+ </ h2 >
70
+ ) }
40
71
< div className = "flex justify-center py-4" >
41
72
{ isLoading ? < Spinner /> : < DynamicWidget /> }
73
+ { showModal && < AccountModal onResponse = { handleModalResponse } /> }
42
74
</ div >
43
75
< p className = "mb-3" >
44
- Zero clicks, one multi-chain wallet. We automatically created an embedded wallet for you.
76
+ Zero clicks, one multi-chain wallet. We automatically created an
77
+ embedded wallet for you.
45
78
</ p >
46
79
< h3 className = "text-lg font-semibold mb-2" > How This works</ h3 >
47
80
< ul className = "list-disc list-inside mb-3 flex flex-col items-start" >
48
81
< li > We utilize the Telegram authentication token</ li >
49
82
< li > Token is verified and used to create the end user wallet</ li >
50
- < li > The same wallet is accessible on desktop and mobile platforms</ li >
51
- < li > If the end user logs in with Telegram later on your site, your wallet is still available</ li >
83
+ < li >
84
+ The same wallet is accessible on desktop and mobile platforms
85
+ </ li >
86
+ < li >
87
+ If the end user logs in with Telegram later on your site, your
88
+ wallet is still available
89
+ </ li >
52
90
</ ul >
53
- < a href = "https://docs.dynamic.xyz/guides/integrations/telegram/telegram-auto-wallets" target = "_blank" rel = "noopener noreferrer" className = "mt-3 inline-block bg-blue-600 text-white font-semibold py-1.5 px-3 rounded hover:bg-blue-700 transition duration-300 text-sm" >
91
+ < a
92
+ href = "https://docs.dynamic.xyz/guides/integrations/telegram/telegram-auto-wallets"
93
+ target = "_blank"
94
+ rel = "noopener noreferrer"
95
+ className = "mt-3 inline-block bg-blue-600 text-white font-semibold py-1.5 px-3 rounded hover:bg-blue-700 transition duration-300 text-sm"
96
+ >
54
97
Learn More in Our Docs
55
98
</ a >
56
99
</ div >
0 commit comments