Skip to content

Commit

Permalink
[web][lib][landing] Prevent crash when missing WalletConnect key
Browse files Browse the repository at this point in the history
Summary: See [ENG-4175](https://linear.app/comm/issue/ENG-4175/missing-walletconnect-key-crashes-web-app) for context.

Test Plan: I moved my `keyserver/secrets/walletconnect.json` file to another path. Without this diff the web app was crashing, but after this diff it was able to load successfully.

Reviewers: kamil, atul

Reviewed By: kamil

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D8349
  • Loading branch information
Ashoat committed Jun 28, 2023
1 parent eb4630c commit 71601d3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
23 changes: 13 additions & 10 deletions landing/siwe.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,22 @@ import { SIWEContext } from './siwe-context.js';
import css from './siwe.css';
import { useMonitorForWalletConnectModal } from './walletconnect-hooks.js';

const projectId = process.env.COMM_WALLETCONNECT_KEY;
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: [
injectedWallet({ chains }),
rainbowWallet({ chains, projectId }),
metaMaskWallet({ chains, projectId }),
walletConnectWallet({ chains, projectId }),
],
},
{ groupName: 'Recommended', wallets },
]);

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

function postMessageToNativeWebView(message: SIWEWebViewMessage) {
Expand Down
23 changes: 13 additions & 10 deletions lib/utils/wagmi-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,22 @@ function createWagmiClient(input: WagmiClientInput): mixed {
});
}

const projectId = process.env.COMM_WALLETCONNECT_KEY;
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: [
injectedWallet({ chains }),
rainbowWallet({ chains, projectId }),
metaMaskWallet({ chains, projectId }),
walletConnectWallet({ chains, projectId }),
],
},
{ groupName: 'Recommended', wallets },
]);

const wagmiClient: mixed = createWagmiClient({ connectors, provider });
const wagmiChains: mixed = chains;

Expand Down

0 comments on commit 71601d3

Please sign in to comment.