diff --git a/landing/siwe.react.js b/landing/siwe.react.js --- a/landing/siwe.react.js +++ b/landing/siwe.react.js @@ -20,7 +20,10 @@ siweMessageSigningExplanationStatements, createSIWEMessage, } from 'lib/utils/siwe-utils.js'; -import { AlchemyENSCacheProvider, wagmiConfig } from 'lib/utils/wagmi-utils.js'; +import { + AlchemyENSCacheProvider, + getWagmiConfig, +} from 'lib/utils/wagmi-utils.js'; import { SIWEContext } from './siwe-context.js'; import css from './siwe.css'; @@ -33,6 +36,8 @@ window.ReactNativeWebView?.postMessage?.(JSON.stringify(message)); } +const wagmiConfig = getWagmiConfig(); + type Signer = { +signMessage: ({ +message: string, ... }) => Promise, ... diff --git a/lib/utils/wagmi-utils.js b/lib/utils/wagmi-utils.js --- a/lib/utils/wagmi-utils.js +++ b/lib/utils/wagmi-utils.js @@ -17,31 +17,40 @@ import { ENSCacheProvider } from '../components/ens-cache-provider.react.js'; -const wallets = [injectedWallet]; const projectId = process.env.COMM_WALLETCONNECT_KEY; -if (projectId) { - wallets.push(rainbowWallet, metaMaskWallet, walletConnectWallet); -} - -const connectors = connectorsForWallets( - [{ groupName: 'Recommended', wallets }], - { - appName: 'Comm', - projectId, - }, -); - const alchemyKey = process.env.COMM_ALCHEMY_KEY; const transport = alchemyKey ? http(`https://eth-mainnet.g.alchemy.com/v2/${alchemyKey}`) : http(); -const wagmiConfig: mixed = createConfig({ - connectors, - chains: [mainnet], - transports: { - [mainnet.id]: transport, - }, -}); + +type GetWagmiConfigParams = { + +includeInjectedWallet?: ?boolean, +}; +function getWagmiConfig(params?: ?GetWagmiConfigParams): mixed { + const wallets = []; + if (params?.includeInjectedWallet) { + wallets.push(injectedWallet); + } + if (projectId) { + wallets.push(rainbowWallet, metaMaskWallet, walletConnectWallet); + } + + const connectors = connectorsForWallets( + [{ groupName: 'Recommended', wallets }], + { + appName: 'Comm', + projectId, + }, + ); + + return createConfig({ + connectors, + chains: [mainnet], + transports: { + [mainnet.id]: transport, + }, + }); +} const ethersAlchemyProvider = new AlchemyProvider('mainnet', alchemyKey); @@ -57,4 +66,4 @@ ); } -export { wagmiConfig, AlchemyENSCacheProvider }; +export { getWagmiConfig, AlchemyENSCacheProvider }; diff --git a/web/app.react.js b/web/app.react.js --- a/web/app.react.js +++ b/web/app.react.js @@ -38,7 +38,10 @@ import { getConfig, registerConfig } from 'lib/utils/config.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; import { infoFromURL } from 'lib/utils/url-utils.js'; -import { AlchemyENSCacheProvider, wagmiConfig } from 'lib/utils/wagmi-utils.js'; +import { + AlchemyENSCacheProvider, + getWagmiConfig, +} from 'lib/utils/wagmi-utils.js'; import QrCodeLogin from './account/qr-code-login.react.js'; import AppThemeWrapper from './app-theme-wrapper.react.js'; @@ -122,6 +125,8 @@ const queryClient = new QueryClient(); +const wagmiConfig = getWagmiConfig({ includeInjectedWallet: true }); + type BaseProps = { +location: { +pathname: string,