Skip to content

Commit d72800f

Browse files
change injected connector logic so that it shows before the others + showUniversalWalletsFirst param (#563)
* change injected connector logic so that it shows before the others * added ability to show universal wallets first * updated walletconnectorssection div * Rename showUniversalWalletsFirst to showWalletAuthOptionsFirst --------- Co-authored-by: Taylan Pince <[email protected]>
1 parent 0eef9a1 commit d72800f

File tree

3 files changed

+57
-27
lines changed

3 files changed

+57
-27
lines changed

examples/react/src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export const connectConfig: ConnectConfig = {
2727
defaultTheme: 'dark',
2828
signIn: {
2929
projectName: 'Sequence Web SDK Demo',
30-
useMock: isDebugMode
30+
useMock: isDebugMode,
31+
showWalletAuthOptionsFirst: false
3132
},
3233
// Custom css injected into shadow dom
3334
// customCSS: `

packages/connect/src/components/Connect/Connect.tsx

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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 />

packages/connect/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export interface ConnectConfig {
7171
position?: ModalPosition
7272
signIn?: {
7373
logoUrl?: string
74+
showWalletAuthOptionsFirst?: boolean
7475
descriptiveSocials?: boolean
7576
disableTooltipForDescriptiveSocials?: boolean
7677
projectName?: string

0 commit comments

Comments
 (0)