From 3fd395f457fbb8e68153de859f6dd4c18ffb2d7e Mon Sep 17 00:00:00 2001 From: iamacook Date: Tue, 17 Oct 2023 10:39:29 +0200 Subject: [PATCH 1/3] fix: clear pairing URI on rejection --- .../walletconnect/HeaderWidget/index.tsx | 8 ++++++++ .../walletconnect/WalletConnectWallet.ts | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/components/walletconnect/HeaderWidget/index.tsx b/src/components/walletconnect/HeaderWidget/index.tsx index 8696f68b65..577f6e2770 100644 --- a/src/components/walletconnect/HeaderWidget/index.tsx +++ b/src/components/walletconnect/HeaderWidget/index.tsx @@ -63,6 +63,14 @@ const WalletConnectHeaderWidget = (): ReactElement => { return walletConnect.onSessionAdd(onSuccess) }, [onSuccess, walletConnect]) + useEffect(() => { + if (!walletConnect) { + return + } + + return walletConnect.onSessionReject(clearUri) + }, [clearUri, walletConnect]) + return ( <>
diff --git a/src/services/walletconnect/WalletConnectWallet.ts b/src/services/walletconnect/WalletConnectWallet.ts index ef95cce699..a8190ab81f 100644 --- a/src/services/walletconnect/WalletConnectWallet.ts +++ b/src/services/walletconnect/WalletConnectWallet.ts @@ -12,6 +12,7 @@ import { invariant } from '@/utils/helpers' import { getEip155ChainId, stripEip155Prefix } from './utils' const SESSION_ADD_EVENT = 'session_add' as Web3WalletTypes.Event // Workaround: WalletConnect doesn't emit session_add event +const SESSION_REJECT_EVENT = 'session_reject' as Web3WalletTypes.Event // Workaround: WalletConnect doesn't emit session_reject event function assertWeb3Wallet(web3Wallet: T): asserts web3Wallet { return invariant(web3Wallet, 'WalletConnect not initialized') @@ -173,6 +174,9 @@ class WalletConnectWallet { id: proposal.id, reason: getSdkError('UNSUPPORTED_CHAINS'), }) + + // Workaround: WalletConnect doesn't have a session_reject event + this.web3Wallet?.events.emit(SESSION_REJECT_EVENT, proposal) } /** @@ -188,6 +192,19 @@ class WalletConnectWallet { } } + /** + * Subscribe to session proposal rejections + */ + public onSessionReject(handler: (e: Web3WalletTypes.SessionProposal) => void) { + // @ts-expect-error - custom event payload + this.web3Wallet?.on(SESSION_REJECT_EVENT, handler) + + return () => { + // @ts-expect-error + this.web3Wallet?.off(SESSION_REJECT_EVENT, handler) + } + } + /** * Subscribe to session add */ From a6b9d4786ee8b97ba1f1c848acf2a688750bad1e Mon Sep 17 00:00:00 2001 From: iamacook Date: Tue, 17 Oct 2023 11:04:12 +0200 Subject: [PATCH 2/3] fix: don't check for permissions on Firefox --- src/components/walletconnect/WcInput/index.tsx | 8 ++------ src/utils/clipboard.ts | 15 +++++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/components/walletconnect/WcInput/index.tsx b/src/components/walletconnect/WcInput/index.tsx index 0c75abe0e5..2b37700f09 100644 --- a/src/components/walletconnect/WcInput/index.tsx +++ b/src/components/walletconnect/WcInput/index.tsx @@ -4,7 +4,7 @@ import type { ReactElement } from 'react' import { WalletConnectContext } from '@/services/walletconnect/WalletConnectContext' import { asError } from '@/services/exceptions/utils' -import { getClipboard } from '@/utils/clipboard' +import { getClipboard, isFirefox } from '@/utils/clipboard' import css from '../SessionList/styles.module.css' @@ -14,10 +14,6 @@ const WcInput = ({ uri }: { uri: string }): ReactElement => { const [error, setError] = useState() const [connecting, setConnecting] = useState(false) - // readText is not supported by Firefox - // @see https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/readText#browser_compatibility - const isFirefox = navigator?.userAgent.includes('Firefox') - const onInput = useCallback( async (uri: string) => { if (!walletConnect) return @@ -66,7 +62,7 @@ const WcInput = ({ uri }: { uri: string }): ReactElement => { label={error ? error.message : 'Pairing UI'} placeholder="wc:" InputProps={{ - endAdornment: isFirefox ? undefined : ( + endAdornment: isFirefox() ? undefined : (