From 9ad1c272b0ac21cb0daf37241fa471565be80bf9 Mon Sep 17 00:00:00 2001 From: Corban Riley Date: Thu, 2 May 2024 16:24:47 -0400 Subject: [PATCH] Exposing setEmail method on sequenceWallet connector in order to update connect.settings.signInWithEmail prop at time of connect --- packages/connectors/src/connectors/email/email.ts | 5 ----- packages/connectors/src/connectors/index.ts | 1 + .../connectors/wagmiConnectors/sequenceConnector.ts | 11 ++++++++++- .../KitProvider/ConnectWalletContent/index.tsx | 11 ++++++++--- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/connectors/src/connectors/email/email.ts b/packages/connectors/src/connectors/email/email.ts index f6938365..2cd7352a 100644 --- a/packages/connectors/src/connectors/email/email.ts +++ b/packages/connectors/src/connectors/email/email.ts @@ -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 => ({ @@ -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: { @@ -25,7 +21,6 @@ export const email = (options: EmailOptions): Wallet => ({ settings: { ...options?.connect?.settings, signInOptions: ['email'] - // signInWithEmail: email || '' } } }) diff --git a/packages/connectors/src/connectors/index.ts b/packages/connectors/src/connectors/index.ts index 4ed7a36e..6dff6e3c 100644 --- a/packages/connectors/src/connectors/index.ts +++ b/packages/connectors/src/connectors/index.ts @@ -11,3 +11,4 @@ export * from './sequence' export * from './twitch' export * from './walletConnect' export * from './types' +export * from './wagmiConnectors' diff --git a/packages/connectors/src/connectors/wagmiConnectors/sequenceConnector.ts b/packages/connectors/src/connectors/wagmiConnectors/sequenceConnector.ts index 68b2064e..ff5dbe43 100644 --- a/packages/connectors/src/connectors/wagmiConnectors/sequenceConnector.ts +++ b/packages/connectors/src/connectors/wagmiConnectors/sequenceConnector.ts @@ -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 @@ -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) => { diff --git a/packages/kit/src/components/KitProvider/ConnectWalletContent/index.tsx b/packages/kit/src/components/KitProvider/ConnectWalletContent/index.tsx index f9a61d2a..d1a2fe27 100644 --- a/packages/kit/src/components/KitProvider/ConnectWalletContent/index.tsx +++ b/packages/kit/src/components/KitProvider/ConnectWalletContent/index.tsx @@ -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' @@ -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 @@ -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 {