Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3489150
D6371.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D6371.diff
View Options
diff --git a/landing/siwe.react.js b/landing/siwe.react.js
--- a/landing/siwe.react.js
+++ b/landing/siwe.react.js
@@ -12,16 +12,7 @@
import _merge from 'lodash/fp/merge';
import * as React from 'react';
import '@rainbow-me/rainbowkit/dist/index.css';
-import {
- useAccount,
- useSigner,
- chain,
- configureChains,
- createClient,
- WagmiConfig,
-} from 'wagmi';
-import { alchemyProvider } from 'wagmi/providers/alchemy';
-import { publicProvider } from 'wagmi/providers/public';
+import { useAccount, useSigner, WagmiConfig } from 'wagmi';
import type { SIWEWebViewMessage } from 'lib/types/siwe-types';
import {
@@ -30,29 +21,14 @@
siweMessageSigningExplanationStatements,
createSIWEMessage,
} from 'lib/utils/siwe-utils.js';
+import { configureWagmiChains, createWagmiClient } from 'lib/utils/wagmi-utils';
import { SIWEContext } from './siwe-context.js';
import css from './siwe.css';
-// details can be found https://0.6.x.wagmi.sh/docs/providers/configuring-chains
-const availableProviders = process.env.COMM_ALCHEMY_KEY
- ? [alchemyProvider({ apiKey: process.env.COMM_ALCHEMY_KEY })]
- : [publicProvider()];
-const { chains, provider } = configureChains(
- [chain.mainnet],
- availableProviders,
-);
-
-const { connectors } = getDefaultWallets({
- appName: 'comm',
- chains,
-});
-
-const wagmiClient = createClient({
- autoConnect: true,
- connectors,
- provider,
-});
+const { chains, provider } = configureWagmiChains(process.env.COMM_ALCHEMY_KEY);
+const { connectors } = getDefaultWallets({ appName: 'comm', chains });
+const wagmiClient = createWagmiClient({ connectors, provider });
function postMessageToNativeWebView(message: SIWEWebViewMessage) {
window.ReactNativeWebView?.postMessage?.(JSON.stringify(message));
diff --git a/lib/package.json b/lib/package.json
--- a/lib/package.json
+++ b/lib/package.json
@@ -46,7 +46,8 @@
"tokenize-text": "^1.1.3",
"url-parse-lax": "^3.0.0",
"util-inspect": "^0.1.8",
- "utils-copy-error": "^1.0.1"
+ "utils-copy-error": "^1.0.1",
+ "wagmi": "^0.6.0"
},
"jest": {
"transform": {
diff --git a/lib/utils/wagmi-utils.js b/lib/utils/wagmi-utils.js
new file mode 100644
--- /dev/null
+++ b/lib/utils/wagmi-utils.js
@@ -0,0 +1,37 @@
+// @flow
+
+import { chain, configureChains, createClient } from 'wagmi';
+import { alchemyProvider } from 'wagmi/providers/alchemy';
+import { publicProvider } from 'wagmi/providers/public';
+
+// details can be found https://0.6.x.wagmi.sh/docs/providers/configuring-chains
+
+type WagmiChainConfiguration = {
+ +chains: mixed,
+ +provider: mixed,
+};
+function configureWagmiChains(alchemyKey: ?string): WagmiChainConfiguration {
+ const availableProviders = alchemyKey
+ ? [alchemyProvider({ apiKey: alchemyKey })]
+ : [publicProvider()];
+ const { chains, provider } = configureChains(
+ [chain.mainnet],
+ availableProviders,
+ );
+ return { chains, provider };
+}
+
+type WagmiClientInput = {
+ +provider: mixed,
+ +connectors?: mixed,
+};
+function createWagmiClient(input: WagmiClientInput): mixed {
+ const { provider, connectors } = input;
+ return createClient({
+ autoConnect: true,
+ connectors,
+ provider,
+ });
+}
+
+export { configureWagmiChains, createWagmiClient };
diff --git a/web/account/siwe.react.js b/web/account/siwe.react.js
--- a/web/account/siwe.react.js
+++ b/web/account/siwe.react.js
@@ -13,16 +13,7 @@
import _merge from 'lodash/fp/merge';
import * as React from 'react';
import { FaEthereum } from 'react-icons/fa';
-import {
- chain,
- configureChains,
- createClient,
- useAccount,
- useSigner,
- WagmiConfig,
-} from 'wagmi';
-import { alchemyProvider } from 'wagmi/providers/alchemy';
-import { publicProvider } from 'wagmi/providers/public';
+import { useAccount, useSigner, WagmiConfig } from 'wagmi';
import {
getSIWENonce,
@@ -41,6 +32,7 @@
siweMessageSigningExplanationStatements,
siweStatementWithoutPublicKey,
} from 'lib/utils/siwe-utils.js';
+import { configureWagmiChains, createWagmiClient } from 'lib/utils/wagmi-utils';
import Button from '../components/button.react';
import LoadingIndicator from '../loading-indicator.react';
@@ -48,25 +40,9 @@
import { webLogInExtraInfoSelector } from '../selectors/account-selectors.js';
import css from './siwe.css';
-// details can be found https://0.6.x.wagmi.sh/docs/providers/configuring-chains
-const availableProviders = process.env.COMM_ALCHEMY_KEY
- ? [alchemyProvider({ apiKey: process.env.COMM_ALCHEMY_KEY })]
- : [publicProvider()];
-const { chains, provider } = configureChains(
- [chain.mainnet],
- availableProviders,
-);
-
-const { connectors } = getDefaultWallets({
- appName: 'comm',
- chains,
-});
-
-const wagmiClient = createClient({
- autoConnect: true,
- connectors,
- provider,
-});
+const { chains, provider } = configureWagmiChains(process.env.COMM_ALCHEMY_KEY);
+const { connectors } = getDefaultWallets({ appName: 'comm', chains });
+const wagmiClient = createWagmiClient({ connectors, provider });
const getSIWENonceLoadingStatusSelector = createLoadingStatusSelector(
getSIWENonceActionTypes,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 11:45 AM (20 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2677206
Default Alt Text
D6371.diff (5 KB)
Attached To
Mode
D6371: [lib] Factor out Wagmi configuration logic into lib
Attached
Detach File
Event Timeline
Log In to Comment