@@ -59,6 +59,7 @@ export const Connect = (props: ConnectProps) => {
5959 const descriptiveSocials = ! ! config ?. signIn ?. descriptiveSocials
6060 const [ isLoading , setIsLoading ] = useState < boolean > ( false )
6161 const projectName = config ?. signIn ?. projectName
62+ const showWalletAuthOptionsFirst = config ?. signIn ?. showWalletAuthOptionsFirst ?? false
6263
6364 const [ email , setEmail ] = useState ( '' )
6465 const [ showEmailWaasPinInput , setShowEmailWaasPinInput ] = useState ( false )
@@ -70,8 +71,6 @@ export const Connect = (props: ConnectProps) => {
7071 const { wallets, linkedWallets, disconnectWallet, refetchLinkedWallets } = useWallets ( )
7172 const { data : waasStatusData } = useGetWaasStatus ( )
7273
73- const hasInjectedSequenceConnector = connectors . some ( c => c . id === 'app.sequence' )
74-
7574 const hasConnectedSequenceUniversal = connections . some ( c => c . connector . name === SEQUENCE_UNIVERSAL_CONNECTOR_NAME )
7675 const hasConnectedSocialOrSequenceUniversal =
7776 connections . some ( c => ( c . connector as ExtendedConnector ) ?. _wallet ?. type === 'social' ) || hasConnectedSequenceUniversal
@@ -184,33 +183,59 @@ export const Connect = (props: ConnectProps) => {
184183 . filter ( c => {
185184 return c . _wallet && ( c . _wallet . type === 'wallet' || c . _wallet . type === undefined )
186185 } )
187- // Remove sequence if wallet extension detected
186+ // Remove metamask if metamask is detected
187+ . filter ( c => {
188+ const isMetamaskInjected = window . ethereum ?. isMetaMask
189+
190+ if ( c . _wallet ?. id === 'metamask-wallet' && isMetamaskInjected ) {
191+ return false
192+ }
193+
194+ return true
195+ } )
196+ // Remove coinbase if coinbase is detected
188197 . filter ( c => {
189- if ( c . _wallet ?. id === 'sequence' && hasInjectedSequenceConnector ) {
198+ const isCoinbaseInjected = window . ethereum ?. isCoinbaseWallet
199+
200+ if ( c . _wallet ?. id === 'coinbase-wallet' && isCoinbaseInjected ) {
190201 return false
191202 }
192203
193204 return true
194205 } )
206+
195207 const mockConnector = baseWalletConnectors . find ( connector => {
196208 return connector . _wallet . id === 'mock'
197209 } )
198210
199211 // EIP-6963 connectors will not have the _wallet property
200212 const injectedConnectors : ExtendedConnector [ ] = connectors
201- . filter ( c => c . type === 'injected' )
202- // Remove the injected connectors when another connector is already in the base connectors
203213 . filter ( connector => {
204- if ( connector . id === 'com.coinbase.wallet' ) {
205- return ! connectors . find ( connector => ( connector as ExtendedConnector ) ?. _wallet ?. id === 'coinbase-wallet' )
214+ // Keep the connector when it is an EIP-6963 connector
215+ if ( connector . type === 'injected' ) {
216+ return true
206217 }
207- if ( connector . id === 'io.metamask' ) {
208- return ! connectors . find ( connector => ( connector as ExtendedConnector ) ?. _wallet ?. id === 'metamask-wallet' )
218+
219+ // We check if SDK-generated connectors is actually an injected connector
220+ const isMetamaskInjected = window . ethereum ?. isMetaMask
221+
222+ if ( ( connector as ExtendedConnector ) . _wallet ?. id === 'metamask-wallet' && isMetamaskInjected ) {
223+ return true
209224 }
210225
211- return true
226+ const isCoinbaseInjected = window . ethereum ?. isCoinbaseWallet
227+
228+ if ( ( connector as ExtendedConnector ) . _wallet ?. id === 'coinbase-wallet' && isCoinbaseInjected ) {
229+ return true
230+ }
231+
232+ return false
212233 } )
213234 . map ( connector => {
235+ if ( connector ?. _wallet ) {
236+ return connector as ExtendedConnector
237+ }
238+
214239 const Logo = ( props : LogoProps ) => {
215240 return < Image src = { connector . icon } alt = { connector . name } disableAnimation { ...props } />
216241 }
@@ -230,9 +255,10 @@ export const Connect = (props: ConnectProps) => {
230255 const socialAuthConnectors = ( connectors as ExtendedConnector [ ] )
231256 . filter ( c => c . _wallet ?. type === 'social' )
232257 . filter ( c => ! c . _wallet . id . includes ( 'email' ) )
233- const walletConnectors = [ ...baseWalletConnectors , ...injectedConnectors ] . filter ( c =>
258+ const walletConnectors = [ ...injectedConnectors , ...baseWalletConnectors ] . filter ( c =>
234259 hasConnectedSequenceUniversal ? c . name !== SEQUENCE_UNIVERSAL_CONNECTOR_NAME : true
235260 )
261+
236262 const emailConnector = ( connectors as ExtendedConnector [ ] ) . find ( c => c . _wallet ?. id . includes ( 'email' ) )
237263
238264 const onChangeEmail : ChangeEventHandler < HTMLInputElement > = ev => {
@@ -359,6 +385,17 @@ export const Connect = (props: ConnectProps) => {
359385 const socialConnectorsPerRow = showMoreSocialOptions && ! descriptiveSocials ? MAX_ITEM_PER_ROW - 1 : socialAuthConnectors . length
360386 const walletConnectorsPerRow = showMoreWalletOptions ? MAX_ITEM_PER_ROW - 1 : walletConnectors . length
361387
388+ const WalletConnectorsSection = ( ) => {
389+ return (
390+ < div className = { clsx ( 'flex gap-2 flex-row justify-center items-center' , hasConnectedSequenceUniversal ? 'mt-4' : 'mt-6' ) } >
391+ { walletConnectors . slice ( 0 , walletConnectorsPerRow ) . map ( connector => {
392+ return < ConnectButton key = { connector . uid } connector = { connector } onConnect = { onConnect } />
393+ } ) }
394+ { showMoreWalletOptions && < ShowAllWalletsButton onClick = { ( ) => setShowExtendedList ( 'wallet' ) } /> }
395+ </ div >
396+ )
397+ }
398+
362399 if ( showExtendedList ) {
363400 const SEARCHABLE_TRESHOLD = 8
364401 const connectors = showExtendedList === 'social' ? socialAuthConnectors : walletConnectors
@@ -482,6 +519,9 @@ export const Connect = (props: ConnectProps) => {
482519 < >
483520 < Banner config = { config as ConnectConfig } />
484521
522+ { showWalletAuthOptionsFirst && ! hideExternalConnectOptions && walletConnectors . length > 0 && (
523+ < WalletConnectorsSection />
524+ ) }
485525 < div className = "flex mt-6 gap-6 flex-col" >
486526 < >
487527 { ! hideSocialConnectOptions && showSocialConnectorSection && (
@@ -574,20 +614,8 @@ export const Connect = (props: ConnectProps) => {
574614 </ div >
575615 </ >
576616 ) }
577- { ! hideExternalConnectOptions && walletConnectors . length > 0 && (
578- < >
579- < div
580- className = { clsx (
581- 'flex gap-2 flex-row justify-center items-center' ,
582- hasConnectedSequenceUniversal ? 'mt-4' : 'mt-6'
583- ) }
584- >
585- { walletConnectors . slice ( 0 , walletConnectorsPerRow ) . map ( connector => {
586- return < ConnectButton key = { connector . uid } connector = { connector } onConnect = { onConnect } />
587- } ) }
588- { showMoreWalletOptions && < ShowAllWalletsButton onClick = { ( ) => setShowExtendedList ( 'wallet' ) } /> }
589- </ div >
590- </ >
617+ { ! showWalletAuthOptionsFirst && ! hideExternalConnectOptions && walletConnectors . length > 0 && (
618+ < WalletConnectorsSection />
591619 ) }
592620 < div className = "mt-6" >
593621 < PoweredBySequence />
0 commit comments