diff --git a/README.md b/README.md index 5acae6d9..d9b610f5 100644 --- a/README.md +++ b/README.md @@ -58,18 +58,35 @@ interface CreateConfigOptions { ethAuth?: EthAuthSettings isDev?: boolean - // optional wagmiConfig overrides - wagmiConfig?: WagmiConfig + wagmiConfig?: WagmiConfig // optional wagmiConfig overrides - walletConnectProjectId?: string - - // embedded wallet (waas) specific connector options waasConfigKey: string - googleClientId?: string - appleClientId?: string - appleRedirectURI?: string enableConfirmationModal?: boolean - legacyEmailAuth?: boolean + + walletConnect?: + | boolean + | { + projectId: string + } + + google?: + | boolean + | { + clientId: string + } + + apple?: + | boolean + | { + clientId: string + rediretURI: string + } + + email?: + | boolean + | { + legacyEmailAuth?: boolean + } } ``` @@ -83,7 +100,20 @@ const config = createConfig('waas', { chainIds: [1, 137] defaultChainId: 1 appName: 'Demo Dapp', - waasConfigKey: '' + waasConfigKey: '', + + google: { + clientId: '' + }, + + apple: { + clientId: '', + redirectUrl: '...' + }, + + walletConnect: { + projectId: '' + } }) function App() { @@ -119,25 +149,36 @@ chains.forEach(chain => { }) // Universal wallet configuration -const connectors = getDefaultConnectors({ +const connectors = getDefaultConnectors('universal', { projectAccessKey, - walletConnectProjectId: '', + appName: 'Demo Dapp', defaultChainId: 137, - appName: 'Demo Dapp' + + walletConnect: { + projectId: '' + } }) /* - // ...or for Embedded wallet configuration - const connectors = getDefaultWaasConnectors({ + const connectors = getDefaultWaasConnectors('{ projectAccessKey, - walletConnectProjectId: '', defaultChainId: 137, appName: 'Demo Dapp', waasConfigKey: '', - googleClientId, - appleClientId, - appleRedirectUrl + + google: { + clientId + }, + + apple: { + clientId, + redirectUrl + }, + + walletConnect: { + projectId: '' + } }) */ diff --git a/examples/next/src/config.ts b/examples/next/src/config.ts index f7623fb3..a83fe689 100644 --- a/examples/next/src/config.ts +++ b/examples/next/src/config.ts @@ -46,17 +46,24 @@ export const kitConfig: KitConfig = { export const config = createConfig('waas', { ...kitConfig, appName: 'Kit Demo', - walletConnectProjectId: 'c65a6cb1aa83c4e24500130f23a437d8', chainIds: [ChainId.ARBITRUM_NOVA, ChainId.ARBITRUM_SEPOLIA, ChainId.POLYGON], defaultChainId: ChainId.ARBITRUM_NOVA, // Waas specific config options waasConfigKey: 'eyJwcm9qZWN0SWQiOjE2ODE1LCJycGNTZXJ2ZXIiOiJodHRwczovL3dhYXMuc2VxdWVuY2UuYXBwIn0=', - googleClientId: '970987756660-35a6tc48hvi8cev9cnknp0iugv9poa23.apps.googleusercontent.com', - appleClientId: 'com.horizon.sequence.waas', - appleRedirectURI: 'http://localhost:3000', enableConfirmationModal: false, + google: { + clientId: '970987756660-35a6tc48hvi8cev9cnknp0iugv9poa23.apps.googleusercontent.com' + }, + apple: { + clientId: 'com.horizon.sequence.waas', + redirectURI: 'http://localhost:3000' + }, + walletConnect: { + projectId: 'c65a6cb1aa83c4e24500130f23a437d8' + }, + wagmiConfig: { // Next.js doesn't support localStorage in SSR storage: createStorage({ storage: cookieStorage }), diff --git a/examples/react/src/config.ts b/examples/react/src/config.ts index 72fc360e..c37b798a 100644 --- a/examples/react/src/config.ts +++ b/examples/react/src/config.ts @@ -54,23 +54,33 @@ export const config = ? createConfig('waas', { ...kitConfig, appName: 'Kit Demo', - walletConnectProjectId, chainIds: [ChainId.ARBITRUM_NOVA, ChainId.ARBITRUM_SEPOLIA, ChainId.POLYGON], defaultChainId: ChainId.ARBITRUM_NOVA, waasConfigKey: isDebugMode ? 'eyJwcm9qZWN0SWQiOjY5NCwicnBjU2VydmVyIjoiaHR0cHM6Ly9kZXYtd2Fhcy5zZXF1ZW5jZS5hcHAiLCJlbWFpbFJlZ2lvbiI6ImNhLWNlbnRyYWwtMSIsImVtYWlsQ2xpZW50SWQiOiI1NGF0bjV1cGk2M3FjNTlhMWVtM3ZiaHJzbiJ9' : 'eyJwcm9qZWN0SWQiOjE2ODE1LCJlbWFpbFJlZ2lvbiI6ImNhLWNlbnRyYWwtMSIsImVtYWlsQ2xpZW50SWQiOiI2N2V2NXVvc3ZxMzVmcGI2OXI3NnJoYnVoIiwicnBjU2VydmVyIjoiaHR0cHM6Ly93YWFzLnNlcXVlbmNlLmFwcCJ9', - googleClientId: isDebugMode - ? '603294233249-6h5saeg2uiu8akpcbar3r2aqjp6j7oem.apps.googleusercontent.com' - : '970987756660-35a6tc48hvi8cev9cnknp0iugv9poa23.apps.googleusercontent.com', - appleClientId: 'com.horizon.sequence.waas', - appleRedirectURI: window.location.origin + window.location.pathname, - enableConfirmationModal: localStorage.getItem('confirmationEnabled') === 'true' + enableConfirmationModal: localStorage.getItem('confirmationEnabled') === 'true', + + google: { + clientId: isDebugMode + ? '603294233249-6h5saeg2uiu8akpcbar3r2aqjp6j7oem.apps.googleusercontent.com' + : '970987756660-35a6tc48hvi8cev9cnknp0iugv9poa23.apps.googleusercontent.com' + }, + apple: { + clientId: 'com.horizon.sequence.waas', + redirectURI: window.location.origin + window.location.pathname + }, + walletConnect: { + projectId: walletConnectProjectId + } }) : createConfig('universal', { ...kitConfig, appName: 'Kit Demo', - walletConnectProjectId, chainIds: [ChainId.ARBITRUM_NOVA, ChainId.ARBITRUM_SEPOLIA, ChainId.POLYGON], - defaultChainId: ChainId.ARBITRUM_NOVA + defaultChainId: ChainId.ARBITRUM_NOVA, + + walletConnect: { + projectId: walletConnectProjectId + } }) diff --git a/packages/kit/README.md b/packages/kit/README.md index 78851f30..cc1975b6 100644 --- a/packages/kit/README.md +++ b/packages/kit/README.md @@ -57,18 +57,35 @@ interface CreateConfigOptions { ethAuth?: EthAuthSettings isDev?: boolean - // optional wagmiConfig overrides - wagmiConfig?: WagmiConfig + wagmiConfig?: WagmiConfig // optional wagmiConfig overrides - walletConnectProjectId?: string - - // embedded wallet (waas) specific connector options waasConfigKey: string - googleClientId?: string - appleClientId?: string - appleRedirectURI?: string enableConfirmationModal?: boolean - legacyEmailAuth?: boolean + + walletConnect?: + | boolean + | { + projectId: string + } + + google?: + | boolean + | { + clientId: string + } + + apple?: + | boolean + | { + clientId: string + rediretURI: string + } + + email?: + | boolean + | { + legacyEmailAuth?: boolean + } } ``` @@ -82,7 +99,20 @@ const config = createConfig('waas', { chainIds: [1, 137] defaultChainId: 1 appName: 'Demo Dapp', - waasConfigKey: '' + waasConfigKey: '', + + google: { + clientId: '' + }, + + apple: { + clientId: '', + redirectUrl: '...' + }, + + walletConnect: { + projectId: '' + } }) function App() { @@ -117,11 +147,14 @@ chains.forEach(chain => { transports[chain.id] = http() }) -const connectors = getDefaultConnectors({ - walletConnectProjectId: 'wallet-connect-id', - defaultChainId: 137, +const connectors = getDefaultConnectors('universal', { + projectAccessKey, appName: 'demo app', - projectAccessKey + defaultChainId: 137, + + walletConnect: { + projectId: '' + } }) const config = createConfig({ diff --git a/packages/kit/src/config/defaultConnectors.ts b/packages/kit/src/config/defaultConnectors.ts index cf3a3276..e320371a 100644 --- a/packages/kit/src/config/defaultConnectors.ts +++ b/packages/kit/src/config/defaultConnectors.ts @@ -11,27 +11,87 @@ import { googleWaas } from '../connectors/google/googleWaas' import { sequence } from '../connectors/sequence' import { twitch } from '../connectors/twitch' import { walletConnect } from '../connectors/walletConnect' -import { WalletType } from '../types' +import { Wallet, WalletType } from '../types' import { getKitConnectWallets } from '../utils/getKitConnectWallets' export interface CommonConnectorOptions { appName: string projectAccessKey: string defaultChainId?: number - walletConnectProjectId?: string } export interface DefaultWaasConnectorOptions extends CommonConnectorOptions { waasConfigKey: string + enableConfirmationModal?: boolean + isDev?: boolean + + email?: + | boolean + | { + legacyEmailAuth: boolean + } + google?: + | false + | { + clientId: string + } + apple?: + | false + | { + clientId: string + redirectURI: string + } + coinbase?: boolean + walletConnect?: + | false + | { + projectId: string + } + + /** + * @deprecated use connectors.walletConnect.projectId instead + */ + walletConnectProjectId?: string + + /** + * @deprecated, use connectors.google.clientId instead + */ googleClientId?: string + + /** + * @deprecated, use connectors.apple.clientId instead + */ appleClientId?: string + + /** + * @deprecated, use connectors.apple.redirectURI instead + */ appleRedirectURI?: string - enableConfirmationModal?: boolean + + /** + * @deprecated, use connectors.email.legacyAuth instead + */ legacyEmailAuth?: boolean - isDev?: boolean } -export interface DefaultUniversalConnectorOptions extends CommonConnectorOptions {} +export interface DefaultUniversalConnectorOptions extends CommonConnectorOptions { + sequence?: boolean + email?: boolean + google?: boolean + facebook?: boolean + twitch?: boolean + apple?: boolean + walletConnect?: + | false + | { + projectId: string + } + + /** + * @deprecated, use connectors.walletConnect.projectId instead + */ + walletConnectProjectId?: string +} export type DefaultConnectorOptions = T extends 'waas' ? DefaultWaasConnectorOptions @@ -45,48 +105,32 @@ export const getDefaultConnectors = (walletType: T, option } } -export const getDefaultWaasConnectors = ({ - appName, - projectAccessKey, - defaultChainId, - walletConnectProjectId, - - waasConfigKey, - googleClientId, - appleClientId, - appleRedirectURI, - enableConfirmationModal, - legacyEmailAuth = false, - isDev = false -}: DefaultWaasConnectorOptions): CreateConnectorFn[] => { - const wallets: any[] = [ - emailWaas({ - projectAccessKey, - waasConfigKey, - enableConfirmationModal, - network: defaultChainId, - legacyEmailAuth, - isDev - }), - coinbaseWallet({ - appName - }) - ] - - if (walletConnectProjectId) { +export const getDefaultWaasConnectors = (options: DefaultWaasConnectorOptions): CreateConnectorFn[] => { + const { projectAccessKey, waasConfigKey, appName, enableConfirmationModal, defaultChainId, isDev } = options + + const wallets: Wallet[] = [] + + if (options.email !== false) { wallets.push( - walletConnect({ - projectId: walletConnectProjectId + emailWaas({ + projectAccessKey, + waasConfigKey, + enableConfirmationModal, + network: defaultChainId, + legacyEmailAuth: (typeof options.email === 'object' && options.email.legacyEmailAuth) || options.legacyEmailAuth, + isDev }) ) } - if (googleClientId) { + if (options.google || options.googleClientId) { + const googleClientId = (options.google && options.google.clientId) || options.googleClientId! + wallets.push( googleWaas({ projectAccessKey, - googleClientId, waasConfigKey, + googleClientId, enableConfirmationModal, network: defaultChainId, isDev @@ -94,13 +138,16 @@ export const getDefaultWaasConnectors = ({ ) } - if (appleClientId && appleRedirectURI) { + if (options.apple || (options.appleClientId && options.appleRedirectURI)) { + const appleClientId = (options.apple && options.apple.clientId) || options.appleClientId! + const appleRedirectURI = (options.apple && options.apple.redirectURI) || options.appleRedirectURI! + wallets.push( appleWaas({ projectAccessKey, + waasConfigKey, appleClientId, appleRedirectURI, - waasConfigKey, enableConfirmationModal, network: defaultChainId, isDev @@ -108,58 +155,104 @@ export const getDefaultWaasConnectors = ({ ) } + if (options.coinbase !== false) { + wallets.push( + coinbaseWallet({ + appName + }) + ) + } + + if (options.walletConnect || options.walletConnectProjectId) { + const projectId = (options.walletConnect && options.walletConnect?.projectId) || options.walletConnectProjectId! + + wallets.push( + walletConnect({ + projectId + }) + ) + } + return getKitConnectWallets(projectAccessKey, wallets) } -export const getDefaultUniversalConnectors = ({ - appName, - projectAccessKey, - defaultChainId, - walletConnectProjectId -}: DefaultUniversalConnectorOptions): CreateConnectorFn[] => { - const wallets: any[] = [ - email({ - defaultNetwork: defaultChainId, - connect: { - app: appName - } - }), - google({ - defaultNetwork: defaultChainId, - connect: { - app: appName - } - }), - facebook({ - defaultNetwork: defaultChainId, - connect: { - app: appName - } - }), - twitch({ - defaultNetwork: defaultChainId, - connect: { - app: appName - } - }), - apple({ - defaultNetwork: defaultChainId, - connect: { - app: appName - } - }), - sequence({ - defaultNetwork: defaultChainId, - connect: { - app: appName - } - }) - ] +export const getDefaultUniversalConnectors = (options: DefaultUniversalConnectorOptions): CreateConnectorFn[] => { + const { projectAccessKey, appName, defaultChainId } = options + + const wallets: Wallet[] = [] + + if (options.email !== false) { + wallets.push( + email({ + defaultNetwork: defaultChainId, + connect: { + app: appName + } + }) + ) + } + + if (options.google !== false) { + wallets.push( + google({ + defaultNetwork: defaultChainId, + connect: { + app: appName + } + }) + ) + } + + if (options.facebook !== false) { + wallets.push( + facebook({ + defaultNetwork: defaultChainId, + connect: { + app: appName + } + }) + ) + } + + if (options.twitch !== false) { + wallets.push( + twitch({ + defaultNetwork: defaultChainId, + connect: { + app: appName + } + }) + ) + } + + if (options.apple !== false) { + wallets.push( + apple({ + defaultNetwork: defaultChainId, + connect: { + app: appName + } + }) + ) + } + + if (options.sequence !== false) { + wallets.push( + sequence({ + defaultNetwork: defaultChainId, + connect: { + app: appName + } + }) + ) + } + + if (options.walletConnect || options.walletConnectProjectId) { + const projectId = (options.walletConnect && options.walletConnect?.projectId) || options.walletConnectProjectId! - if (walletConnectProjectId) { wallets.push( walletConnect({ - projectId: walletConnectProjectId + projectId }) ) }