on master help sign in
wc: handle METHOD_NOT_SUPPORTED on message signing

Some wallets (like Gnosis Safe multisig) do not support the signPersonalMessage function. Instead of crashing and preventing login, we catch that specific error case and just proceed without an auth token instead.

commite1b030183818a452b411cc68d6589d3bbc67ceca authorFang <git@fang.io> dateThu 19 Aug 2021, 00:09 (5 years ago) parentfe1e348
1 file changed+20−7
src/lib/useWalletConnect.ts+20−7
src/lib/useWalletConnect.ts+20−7
@@ -3,7 +3,7 @@ import QRCodeModal from '@walletconnect/qrcode-modal';
33import { ITxData } from '@walletconnect/types';
44
55import { useEffect, useMemo, useState } from 'react';
6−import { Just } from 'folktale/maybe';
6+import { Just, Nothing } from 'folktale/maybe';
77
88import { useWallet } from 'store/wallet';
99import { getAuthToken } from './authToken';
@@ -81,17 +81,30 @@ export const useWalletConnect = () => {
8181 return;
8282 }
8383
84− const authToken = await getAuthToken({
85− address,
86− connector,
87− walletType: WALLET_TYPES.WALLET_CONNECT,
88− });
84+ let authToken = Nothing();
85+ try {
86+ const token = await getAuthToken({
87+ address,
88+ connector,
89+ walletType: WALLET_TYPES.WALLET_CONNECT,
90+ });
91+ authToken = Just(token);
92+ } catch (e) {
93+ if (e.message === 'METHOD_NOT_SUPPORTED') {
94+ console.warn(
95+ 'wallet does not support message signing. proceeding without auth token.'
96+ );
97+ } else {
98+ throw e;
99+ //TODO should errors with this *really* prevent login?
100+ }
101+ }
89102
90103 const wallet: WalletConnectWallet = {
91104 address,
92105 };
93106
94− setAuthToken(Just(authToken));
107+ setAuthToken(authToken);
95108 setWallet(Just(wallet));
96109 };
97110