Skip to content

Commit

Permalink
Exposing setEmail method on sequenceWallet connector in order to upda…
Browse files Browse the repository at this point in the history
…te connect.settings.signInWithEmail prop at time of connect
  • Loading branch information
corbanbrook committed May 2, 2024
1 parent c7fcf8d commit 9ad1c27
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
5 changes: 0 additions & 5 deletions packages/connectors/src/connectors/email/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { getEmailLogo } from './EmailLogo'
import { sequenceWallet, BaseSequenceConnectorOptions } from '../wagmiConnectors'
import { Wallet } from '@0xsequence/kit'

export const EMAIL_CONNECTOR_LOCAL_STORAGE_KEY = '@sequence.kit.connector.email'

export interface EmailOptions extends BaseSequenceConnectorOptions {}

export const email = (options: EmailOptions): Wallet => ({
Expand All @@ -15,8 +13,6 @@ export const email = (options: EmailOptions): Wallet => ({
// iconBackground: '#fff',
name: 'Email',
createConnector: projectAccessKey => {
//const email = localStorage.getItem(EMAIL_CONNECTOR_LOCAL_STORAGE_KEY)

const connector = sequenceWallet({
...options,
connect: {
Expand All @@ -25,7 +21,6 @@ export const email = (options: EmailOptions): Wallet => ({
settings: {
...options?.connect?.settings,
signInOptions: ['email']
// signInWithEmail: email || ''
}
}
})
Expand Down
1 change: 1 addition & 0 deletions packages/connectors/src/connectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * from './sequence'
export * from './twitch'
export * from './walletConnect'
export * from './types'
export * from './wagmiConnectors'
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export function sequenceWallet(params: BaseSequenceConnectorOptions) {
}

type Provider = sequence.provider.SequenceProvider
type Properties = { params: BaseSequenceConnectorOptions }
type Properties = {
params: BaseSequenceConnectorOptions
setEmail: (email: string) => void
}
type StorageItem = {
[LocalStorageKey.EthAuthProof]: ETHAuthProof
[LocalStorageKey.Theme]: string
Expand All @@ -55,6 +58,12 @@ export function sequenceWallet(params: BaseSequenceConnectorOptions) {
type: sequenceWallet.type,
params,

setEmail(email: string) {
if (params.connect.settings) {
params.connect.settings.signInWithEmail = email
}
},

async setup() {
const provider = await this.getProvider()
provider.on('chainChanged', (chainIdHex: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Tooltip
} from '@0xsequence/design-system'
import { useConnect, useAccount, Connector, useConfig, Storage } from 'wagmi'
import { EMAIL_CONNECTOR_LOCAL_STORAGE_KEY, LogoProps } from '@0xsequence/kit-connectors'
import { LogoProps, sequenceWallet } from '@0xsequence/kit-connectors'
import { GoogleLogin } from '@react-oauth/google'
import { appleAuthHelpers, useScript } from 'react-apple-signin-auth'

Expand Down Expand Up @@ -145,7 +145,10 @@ export const ConnectWalletContent = (props: ConnectWalletContentProps) => {

if (connector._wallet.id === 'email') {
const email = prompt('Auto-email login, please specify the email address:')
localStorage.setItem(EMAIL_CONNECTOR_LOCAL_STORAGE_KEY, email || '')

if ('setEmail' in connector) {
;(connector as any).setEmail(email)
}
}

// Open Metamask download page if Metamask window.ethereum is not found
Expand All @@ -170,7 +173,9 @@ export const ConnectWalletContent = (props: ConnectWalletContentProps) => {
}

if (emailConnector) {
localStorage.setItem(EMAIL_CONNECTOR_LOCAL_STORAGE_KEY, email)
if ('setEmail' in emailConnector) {
;(emailConnector as any).setEmail(email)
}

if (emailConnector._wallet.id === 'email-waas') {
try {
Expand Down

0 comments on commit 9ad1c27

Please sign in to comment.