From af665656f028626c1d004a5ab29553c8e8e6f1e6 Mon Sep 17 00:00:00 2001 From: Corban Riley Date: Thu, 25 Apr 2024 15:12:45 -0400 Subject: [PATCH] Merge projectAccessKey into connect options --- packages/connectors/src/connectors/apple/apple.ts | 3 ++- .../connectors/src/connectors/discord/discord.ts | 3 ++- packages/connectors/src/connectors/email/email.ts | 10 +++++----- .../connectors/src/connectors/facebook/facebook.ts | 3 ++- .../connectors/src/connectors/google/google.ts | 4 ++-- .../connectors/src/connectors/sequence/sequence.ts | 8 ++++++-- .../connectors/src/connectors/twitch/twitch.ts | 3 ++- .../wagmiConnectors/sequenceConnector.ts | 4 ++-- packages/connectors/src/defaultConnectors.ts | 14 ++++---------- packages/kit/src/utils/getKitConnectWallets.ts | 7 ++----- 10 files changed, 29 insertions(+), 30 deletions(-) diff --git a/packages/connectors/src/connectors/apple/apple.ts b/packages/connectors/src/connectors/apple/apple.ts index 2e4950ba..b26ceaa0 100644 --- a/packages/connectors/src/connectors/apple/apple.ts +++ b/packages/connectors/src/connectors/apple/apple.ts @@ -14,10 +14,11 @@ export const apple = (options: AppleOptions): Wallet => ({ monochromeLogoLight: getAppleMonochromeLogo({ isDarkMode: false }), // iconBackground: '#fff', name: 'Apple', - createConnector: () => { + createConnector: projectAccessKey => { const connector = sequenceWallet({ ...options, connect: { + projectAccessKey, ...options?.connect, settings: { ...options?.connect?.settings, diff --git a/packages/connectors/src/connectors/discord/discord.ts b/packages/connectors/src/connectors/discord/discord.ts index 65b8714e..026825bc 100644 --- a/packages/connectors/src/connectors/discord/discord.ts +++ b/packages/connectors/src/connectors/discord/discord.ts @@ -14,10 +14,11 @@ export const discord = (options: DiscordOptions): Wallet => ({ monochromeLogoLight: getDiscordLogo({ isDarkMode: false }), // iconBackground: '#fff', name: 'Discord', - createConnector: () => { + createConnector: projectAccessKey => { const connector = sequenceWallet({ ...options, connect: { + projectAccessKey, ...options?.connect, settings: { ...options?.connect?.settings, diff --git a/packages/connectors/src/connectors/email/email.ts b/packages/connectors/src/connectors/email/email.ts index aa77c8d7..f6938365 100644 --- a/packages/connectors/src/connectors/email/email.ts +++ b/packages/connectors/src/connectors/email/email.ts @@ -14,18 +14,18 @@ export const email = (options: EmailOptions): Wallet => ({ logoLight: getEmailLogo({ isDarkMode: false }), // iconBackground: '#fff', name: 'Email', - createConnector: () => { - const email = localStorage.getItem(EMAIL_CONNECTOR_LOCAL_STORAGE_KEY) + createConnector: projectAccessKey => { + //const email = localStorage.getItem(EMAIL_CONNECTOR_LOCAL_STORAGE_KEY) const connector = sequenceWallet({ ...options, - // @ts-ignore connect: { + projectAccessKey, ...options?.connect, settings: { ...options?.connect?.settings, - signInOptions: ['email'], - signInWithEmail: email || '' + signInOptions: ['email'] + // signInWithEmail: email || '' } } }) diff --git a/packages/connectors/src/connectors/facebook/facebook.ts b/packages/connectors/src/connectors/facebook/facebook.ts index c661cc52..f00e32da 100644 --- a/packages/connectors/src/connectors/facebook/facebook.ts +++ b/packages/connectors/src/connectors/facebook/facebook.ts @@ -15,10 +15,11 @@ export const facebook = (options: FacebookOptions): Wallet => ({ monochromeLogoLight: getFacebookMonochromeLogo({ isDarkMode: false }), // iconBackground: '#fff', name: 'Facebook', - createConnector: () => { + createConnector: projectAccessKey => { const connector = sequenceWallet({ ...options, connect: { + projectAccessKey, ...options?.connect, settings: { ...options?.connect?.settings, diff --git a/packages/connectors/src/connectors/google/google.ts b/packages/connectors/src/connectors/google/google.ts index 2de33124..8ce2dfe0 100644 --- a/packages/connectors/src/connectors/google/google.ts +++ b/packages/connectors/src/connectors/google/google.ts @@ -13,11 +13,11 @@ export const google = (options: GoogleOptions): Wallet => ({ monochromeLogoDark: getMonochromeGoogleLogo({ isDarkMode: true }), monochromeLogoLight: getMonochromeGoogleLogo({ isDarkMode: false }), name: 'Google', - createConnector: () => { + createConnector: projectAccessKey => { const connector = sequenceWallet({ ...options, - // @ts-ignore connect: { + projectAccessKey, ...options?.connect, settings: { ...options?.connect?.settings, diff --git a/packages/connectors/src/connectors/sequence/sequence.ts b/packages/connectors/src/connectors/sequence/sequence.ts index 31b9c238..56c3fce8 100644 --- a/packages/connectors/src/connectors/sequence/sequence.ts +++ b/packages/connectors/src/connectors/sequence/sequence.ts @@ -12,9 +12,13 @@ export const sequence = (options: SequenceOptions): Wallet => ({ logoLight: SequenceLogo, // iconBackground: '#777', name: 'Sequence', - createConnector: () => { + createConnector: projectAccessKey => { const connector = sequenceWallet({ - ...options + ...options, + connect: { + projectAccessKey, + ...options.connect + } }) return connector } diff --git a/packages/connectors/src/connectors/twitch/twitch.ts b/packages/connectors/src/connectors/twitch/twitch.ts index 2b4bd196..6f2525f4 100644 --- a/packages/connectors/src/connectors/twitch/twitch.ts +++ b/packages/connectors/src/connectors/twitch/twitch.ts @@ -14,10 +14,11 @@ export const twitch = (options: TwitchOptions): Wallet => ({ monochromeLogoLight: getTwitchLogo({ isDarkMode: false }), // iconBackground: '#fff', name: 'Twitch', - createConnector: () => { + createConnector: projectAccessKey => { const connector = sequenceWallet({ ...options, connect: { + projectAccessKey, ...options?.connect, settings: { ...options?.connect?.settings, diff --git a/packages/connectors/src/connectors/wagmiConnectors/sequenceConnector.ts b/packages/connectors/src/connectors/wagmiConnectors/sequenceConnector.ts index 026f0f21..ded8b6bb 100644 --- a/packages/connectors/src/connectors/wagmiConnectors/sequenceConnector.ts +++ b/packages/connectors/src/connectors/wagmiConnectors/sequenceConnector.ts @@ -19,6 +19,8 @@ export function sequenceWallet(params: BaseSequenceConnectorOptions) { let id = 'sequence' let name = 'Sequence' + const { projectAccessKey } = connect + const signInOptions = params?.connect?.settings?.signInOptions || [] const signInWith = params?.connect?.settings?.signInWith const signInWithEmail = params?.connect?.settings?.signInWithEmail @@ -124,8 +126,6 @@ export function sequenceWallet(params: BaseSequenceConnectorOptions) { return provider } catch (e) { - const projectAccessKey = await config.storage?.getItem(LocalStorageKey.ProjectAccessKey) - if (!projectAccessKey) { throw 'projectAccessKey not found' } diff --git a/packages/connectors/src/defaultConnectors.ts b/packages/connectors/src/defaultConnectors.ts index 069a46ef..36f4ab57 100644 --- a/packages/connectors/src/defaultConnectors.ts +++ b/packages/connectors/src/defaultConnectors.ts @@ -23,22 +23,19 @@ export const getDefaultConnectors = ({ email({ defaultNetwork: defaultChainId, connect: { - app: appName, - projectAccessKey + app: appName } }), google({ defaultNetwork: defaultChainId, connect: { - app: appName, - projectAccessKey + app: appName } }), facebook({ defaultNetwork: defaultChainId, connect: { - app: appName, - projectAccessKey + app: appName } }), twitch({ @@ -56,8 +53,7 @@ export const getDefaultConnectors = ({ sequence({ defaultNetwork: defaultChainId, connect: { - app: appName, - projectAccessKey + app: appName } }), walletConnect({ @@ -69,7 +65,6 @@ export const getDefaultConnectors = ({ }) ]) - /* @ts-ignore-next-line */ return connectors } @@ -129,6 +124,5 @@ export const getDefaultWaasConnectors = ({ const connectors = getKitConnectWallets(projectAccessKey, wallets) - /* @ts-ignore-next-line */ return connectors } diff --git a/packages/kit/src/utils/getKitConnectWallets.ts b/packages/kit/src/utils/getKitConnectWallets.ts index 040c9233..72aadadf 100644 --- a/packages/kit/src/utils/getKitConnectWallets.ts +++ b/packages/kit/src/utils/getKitConnectWallets.ts @@ -1,7 +1,6 @@ import React from 'react' import { Connector, CreateConnectorFn } from 'wagmi' -import { LocalStorageKey } from '../constants' import { LogoProps } from '@0xsequence/kit-connectors' export interface WalletProperties { @@ -17,7 +16,7 @@ export interface WalletProperties { } export type Wallet = WalletProperties & { - createConnector: () => CreateConnectorFn + createConnector: (projectAccessKey: string) => CreateConnectorFn } export interface WalletField { @@ -27,8 +26,6 @@ export interface WalletField { export type ExtendedConnector = Connector & WalletField export const getKitConnectWallets = (projectAccessKey: string, wallets: Wallet[]): CreateConnectorFn[] => { - localStorage.setItem(LocalStorageKey.ProjectAccessKey, projectAccessKey) - const connectors: CreateConnectorFn[] = [] wallets.forEach(wallet => { @@ -36,7 +33,7 @@ export const getKitConnectWallets = (projectAccessKey: string, wallets: Wallet[] const walletProperties = { ...metaProperties } const createConnectorOverride = (config: any) => { - const connector = createConnector() + const connector = createConnector(projectAccessKey) const res = connector(config) as ExtendedConnector res._wallet = { ...walletProperties }