88 TextInput ,
99 Spinner ,
1010 Image ,
11- IconButton
11+ IconButton ,
12+ ModalPrimitive
1213} from '@0xsequence/design-system'
1314import React , { useState , useEffect } from 'react'
1415import { appleAuthHelpers , useScript } from 'react-apple-signin-auth'
@@ -31,21 +32,25 @@ import { ExtendedWalletList } from './ExtendedWalletList'
3132interface ConnectWalletContentProps extends KitConnectProviderProps {
3233 emailConflictInfo ?: FormattedEmailConflictInfo | null
3334 onClose : ( ) => void
35+ isPreview ?: boolean
3436}
3537
3638export const Connect = ( props : ConnectWalletContentProps ) => {
3739 useScript ( appleAuthHelpers . APPLE_SCRIPT_SRC )
3840
39- const { onClose, emailConflictInfo, config = { } } = props
40- const { signIn = { } } = config as KitConfig
41+ const { onClose, emailConflictInfo, config = { } as KitConfig , isPreview = false } = props
42+ const { signIn = { } } = config
4143 const { isConnected } = useAccount ( )
4244 const storage = useStorage ( )
4345
46+ const [ isLoading , setIsLoading ] = useState < boolean > ( false )
47+ const projectName = config ?. signIn ?. projectName
48+
4449 const [ email , setEmail ] = useState ( '' )
4550 const [ showEmailInput , setShowEmailInput ] = useState < boolean > ( false )
4651 const [ showEmailWaasPinInput , setShowEmailWaasPinInput ] = useState ( false )
4752 const [ showExtendedList , setShowExtendedList ] = useState < boolean > ( false )
48- const { connectors, connect } = useConnect ( )
53+ const { status , connectors, connect } = useConnect ( )
4954 const hasInjectedSequenceConnector = connectors . some ( c => c . id === 'app.sequence' )
5055
5156 const baseWalletConnectors = ( connectors as ExtendedConnector [ ] )
@@ -110,6 +115,10 @@ export const Connect = (props: ConnectWalletContentProps) => {
110115 }
111116 } , [ isConnected ] )
112117
118+ useEffect ( ( ) => {
119+ setIsLoading ( status === 'pending' || status === 'success' )
120+ } , [ status ] )
121+
113122 const onConnect = ( connector : ExtendedConnector ) => {
114123 if ( signIn . useMock && mockConnector ) {
115124 connect ( { connector : mockConnector } )
@@ -184,106 +193,134 @@ export const Connect = (props: ConnectWalletContentProps) => {
184193 }
185194 } , [ emailConflictInfo ] )
186195
187- if ( showEmailWaasPinInput ) {
188- return < EmailWaasVerify error = { emailAuthError } isLoading = { emailAuthLoading } onConfirm = { sendChallengeAnswer } />
189- }
196+ return (
197+ < Box padding = "4" >
198+ < Box
199+ justifyContent = "center"
200+ color = "text100"
201+ alignItems = "center"
202+ fontWeight = "medium"
203+ style = { {
204+ marginTop : '4px'
205+ } }
206+ >
207+ < TitleWrapper isPreview = { isPreview } >
208+ < Text > { isLoading ? `Connecting...` : `Sign in ${ projectName ? `to ${ projectName } ` : '' } ` } </ Text >
209+ </ TitleWrapper >
210+ </ Box >
190211
191- if ( showExtendedList ) {
192- return (
193- < >
194- < Box position = "absolute" top = "4" >
195- < IconButton icon = { ChevronLeftIcon } onClick = { ( ) => setShowExtendedList ( false ) } size = "xs" />
212+ { isLoading ? (
213+ < Box justifyContent = "center" alignItems = "center" paddingTop = "4" >
214+ < Spinner />
196215 </ Box >
197- < ExtendedWalletList connectors = { walletConnectors } onConnect = { onConnect } />
198- </ >
199- )
200- }
201-
202- return (
203- < >
204- < Banner config = { config as KitConfig } />
205-
206- < Box marginTop = "6" >
207- { emailConnector && ( showEmailInput || isEmailOnly ) ? (
208- < form onSubmit = { onConnectInlineEmail } >
209- < TextInput onChange = { onChangeEmail } value = { email } name = "email" placeholder = "Enter email" data-1p-ignore />
210- < Box alignItems = "center" justifyContent = "center" marginTop = "4" >
211- { ! emailAuthInProgress && (
212- < Box gap = "2" width = "full" >
213- { ! isEmailOnly && < Button label = "Back" width = "full" onClick = { ( ) => setShowEmailInput ( false ) } /> }
214-
215- < Button
216- type = "submit"
217- variant = "primary"
218- disabled = { ! isEmailValid ( email ) }
219- width = "full"
220- label = "Continue"
221- rightIcon = { ChevronRightIcon }
222- />
223- </ Box >
224- ) }
225- { emailAuthInProgress && < Spinner /> }
226- </ Box >
227- </ form >
228- ) : (
229- < >
230- { socialAuthConnectors . length > 0 && (
231- < Box marginTop = "2" gap = "2" flexDirection = "row" justifyContent = "center" alignItems = "center" flexWrap = "wrap" >
232- { socialAuthConnectors . map ( connector => {
233- return (
234- < Box key = { connector . uid } aspectRatio = "1/1" alignItems = "center" justifyContent = "center" >
235- { connector . _wallet . id === 'google-waas' ? (
236- < GoogleWaasConnectButton connector = { connector } onConnect = { onConnect } />
237- ) : connector . _wallet . id === 'apple-waas' ? (
238- < AppleWaasConnectButton connector = { connector } onConnect = { onConnect } />
239- ) : connector . _wallet . id . includes ( 'email' ) ? (
240- < EmailConnectButton onClick = { ( ) => setShowEmailInput ( true ) } />
241- ) : (
242- < ConnectButton connector = { connector } onConnect = { onConnect } />
216+ ) : (
217+ < >
218+ { showEmailWaasPinInput ? (
219+ < EmailWaasVerify error = { emailAuthError } isLoading = { emailAuthLoading } onConfirm = { sendChallengeAnswer } />
220+ ) : showExtendedList ? (
221+ < >
222+ < Box position = "absolute" top = "4" >
223+ < IconButton icon = { ChevronLeftIcon } onClick = { ( ) => setShowExtendedList ( false ) } size = "xs" />
224+ </ Box >
225+ < ExtendedWalletList connectors = { walletConnectors } onConnect = { onConnect } />
226+ </ >
227+ ) : (
228+ < >
229+ < Banner config = { config as KitConfig } />
230+
231+ < Box marginTop = "6" >
232+ { emailConnector && ( showEmailInput || isEmailOnly ) ? (
233+ < form onSubmit = { onConnectInlineEmail } >
234+ < TextInput onChange = { onChangeEmail } value = { email } name = "email" placeholder = "Enter email" data-1p-ignore />
235+ < Box alignItems = "center" justifyContent = "center" marginTop = "4" >
236+ { ! emailAuthInProgress && (
237+ < Box gap = "2" width = "full" >
238+ { ! isEmailOnly && < Button label = "Back" width = "full" onClick = { ( ) => setShowEmailInput ( false ) } /> }
239+
240+ < Button
241+ type = "submit"
242+ variant = "primary"
243+ disabled = { ! isEmailValid ( email ) }
244+ width = "full"
245+ label = "Continue"
246+ rightIcon = { ChevronRightIcon }
247+ />
248+ </ Box >
243249 ) }
250+ { emailAuthInProgress && < Spinner /> }
244251 </ Box >
245- )
246- } ) }
247- </ Box >
248- ) }
249- </ >
250- ) }
251-
252- { walletConnectors . length > 0 && ! showEmailInput && (
253- < >
254- { socialAuthConnectors . length > 0 && (
255- < >
256- < Divider color = "backgroundSecondary" />
257- < Box justifyContent = "center" alignItems = "center" >
258- < Text variant = "small" color = "text50" >
259- or select a wallet
260- </ Text >
261- </ Box >
262- </ >
263- ) }
264-
265- < Box marginTop = "2" gap = "2" flexDirection = "row" justifyContent = "center" alignItems = "center" >
266- { walletConnectors . slice ( 0 , 7 ) . map ( connector => {
267- return < ConnectButton key = { connector . uid } connector = { connector } onConnect = { onConnect } />
268- } ) }
269- </ Box >
270-
271- { displayExtendedListButton && (
272- < Box marginTop = "4" justifyContent = "center" >
273- < Button
274- shape = "square"
275- size = "xs"
276- onClick = { ( ) => setShowExtendedList ( true ) }
277- label = "More options"
278- rightIcon = { ChevronRightIcon }
279- />
252+ </ form >
253+ ) : (
254+ < >
255+ { socialAuthConnectors . length > 0 && (
256+ < Box marginTop = "2" gap = "2" flexDirection = "row" justifyContent = "center" alignItems = "center" flexWrap = "wrap" >
257+ { socialAuthConnectors . map ( connector => {
258+ return (
259+ < Box key = { connector . uid } aspectRatio = "1/1" alignItems = "center" justifyContent = "center" >
260+ { connector . _wallet . id === 'google-waas' ? (
261+ < GoogleWaasConnectButton connector = { connector } onConnect = { onConnect } />
262+ ) : connector . _wallet . id === 'apple-waas' ? (
263+ < AppleWaasConnectButton connector = { connector } onConnect = { onConnect } />
264+ ) : connector . _wallet . id . includes ( 'email' ) ? (
265+ < EmailConnectButton onClick = { ( ) => setShowEmailInput ( true ) } />
266+ ) : (
267+ < ConnectButton connector = { connector } onConnect = { onConnect } />
268+ ) }
269+ </ Box >
270+ )
271+ } ) }
272+ </ Box >
273+ ) }
274+ </ >
275+ ) }
276+
277+ { walletConnectors . length > 0 && ! showEmailInput && (
278+ < >
279+ { socialAuthConnectors . length > 0 && (
280+ < >
281+ < Divider color = "backgroundSecondary" />
282+ < Box justifyContent = "center" alignItems = "center" >
283+ < Text variant = "small" color = "text50" >
284+ or select a wallet
285+ </ Text >
286+ </ Box >
287+ </ >
288+ ) }
289+
290+ < Box marginTop = "2" gap = "2" flexDirection = "row" justifyContent = "center" alignItems = "center" >
291+ { walletConnectors . slice ( 0 , 7 ) . map ( connector => {
292+ return < ConnectButton key = { connector . uid } connector = { connector } onConnect = { onConnect } />
293+ } ) }
294+ </ Box >
295+
296+ { displayExtendedListButton && (
297+ < Box marginTop = "4" justifyContent = "center" >
298+ < Button
299+ shape = "square"
300+ size = "xs"
301+ onClick = { ( ) => setShowExtendedList ( true ) }
302+ label = "More options"
303+ rightIcon = { ChevronRightIcon }
304+ />
305+ </ Box >
306+ ) }
307+ </ >
308+ ) }
280309 </ Box >
281- ) }
282- </ >
283- ) }
284- </ Box >
285310
286- < PoweredBySequence />
287- </ >
311+ < PoweredBySequence />
312+ </ >
313+ ) }
314+ </ >
315+ ) }
316+ </ Box >
288317 )
289318}
319+
320+ const TitleWrapper = ( { children, isPreview } : { children : React . ReactNode ; isPreview : boolean } ) => {
321+ if ( isPreview ) {
322+ return < > { children } </ >
323+ }
324+
325+ return < ModalPrimitive . Title asChild > { children } </ ModalPrimitive . Title >
326+ }
0 commit comments