Skip to content

Commit

Permalink
[landing] Reduce code duplication in landing/siwe.react.js
Browse files Browse the repository at this point in the history
Summary: This code is completely duplicated from `lib/utils/wagmi-utils.js`.

Test Plan:
1. In my local environment, make sure that mobile SIWE still works with Rainbow wallet (mobile SIWE uses `landing`, but web SIWE doesn't)
2. In combination with other diffs in the stack, I tested the following on both my local environment, and in a staging environment for my keyserver on comm.domains:
  - Mobile sign in with Rainbow wallet using Rainbow login
  - Mobile sign in with Rainbow wallet using WalletConnect login
  - Web sign in with Rainbow wallet using Rainbow login
  - Web sign in with Rainbow wallet using WalletConnect login
  - Web sign in with Metamask wallet

Reviewers: rohan, atul, ginsu

Reviewed By: atul

Subscribers: tomek, wyilio

Differential Revision: https://phab.comm.dev/D9432
  • Loading branch information
Ashoat committed Oct 10, 2023
1 parent e8d666f commit d8339b2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
36 changes: 7 additions & 29 deletions landing/siwe.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ import {
RainbowKitProvider,
darkTheme,
useModalState,
connectorsForWallets,
} from '@rainbow-me/rainbowkit';
import '@rainbow-me/rainbowkit/styles.css';
import {
injectedWallet,
rainbowWallet,
metaMaskWallet,
walletConnectWallet,
// eslint-disable-next-line import/extensions
} from '@rainbow-me/rainbowkit/wallets';
import invariant from 'invariant';
import _merge from 'lodash/fp/merge.js';
import * as React from 'react';
Expand All @@ -29,32 +21,14 @@ import {
} from 'lib/utils/siwe-utils.js';
import {
WagmiENSCacheProvider,
configureWagmiChains,
createWagmiClient,
wagmiClient,
wagmiChains,
} from 'lib/utils/wagmi-utils.js';

import { SIWEContext } from './siwe-context.js';
import css from './siwe.css';
import { useMonitorForWalletConnectModal } from './walletconnect-hooks.js';

const { chains, provider } = configureWagmiChains(process.env.COMM_ALCHEMY_KEY);

const wallets = [injectedWallet({ chains })];
const projectId = process.env.COMM_WALLETCONNECT_KEY;
if (projectId) {
wallets.push(
rainbowWallet({ chains, projectId }),
metaMaskWallet({ chains, projectId }),
walletConnectWallet({ chains, projectId }),
);
}

const connectors = connectorsForWallets([
{ groupName: 'Recommended', wallets },
]);

const wagmiClient = createWagmiClient({ connectors, provider });

function postMessageToNativeWebView(message: SIWEWebViewMessage) {
window.ReactNativeWebView?.postMessage?.(JSON.stringify(message));
}
Expand Down Expand Up @@ -188,7 +162,11 @@ function SIWEWrapper(): React.Node {
return (
<WagmiConfig client={wagmiClient}>
<WagmiENSCacheProvider>
<RainbowKitProvider theme={theme} modalSize="compact" chains={chains}>
<RainbowKitProvider
theme={theme}
modalSize="compact"
chains={wagmiChains}
>
<SIWE />
</RainbowKitProvider>
</WagmiENSCacheProvider>
Expand Down
8 changes: 1 addition & 7 deletions lib/utils/wagmi-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,4 @@ function WagmiENSCacheProvider(props: Props): React.Node {
);
}

export {
configureWagmiChains,
createWagmiClient,
wagmiClient,
wagmiChains,
WagmiENSCacheProvider,
};
export { wagmiClient, wagmiChains, WagmiENSCacheProvider };

0 comments on commit d8339b2

Please sign in to comment.