From 8cc2924d9dd3c22d1f139e3c399e77bd767f0fc4 Mon Sep 17 00:00:00 2001 From: katspaugh Date: Wed, 20 Sep 2023 12:05:21 +0200 Subject: [PATCH] Rm onPaste --- .../wallet-connect/hooks/useWalletConnect.ts | 12 ++--- src/components/wallet-connect/index.tsx | 44 ++----------------- 2 files changed, 7 insertions(+), 49 deletions(-) diff --git a/src/components/wallet-connect/hooks/useWalletConnect.ts b/src/components/wallet-connect/hooks/useWalletConnect.ts index 2f2d40c674..79dc5b9603 100644 --- a/src/components/wallet-connect/hooks/useWalletConnect.ts +++ b/src/components/wallet-connect/hooks/useWalletConnect.ts @@ -5,13 +5,7 @@ import { useCurrentChain } from '@/hooks/useChains' import useSafeInfo from '@/hooks/useSafeInfo' import useSafeWalletProvider from '@/safe-wallet-provider/useSafeWalletProvider' import { WalletConnect } from './WalletConnect' - -const EVMBasedNamespaces: string = 'eip155' - -// see https://docs.walletconnect.com/2.0/specs/sign/error-codes -const UNSUPPORTED_CHAIN_ERROR_CODE = 5100 -const INVALID_METHOD_ERROR_CODE = 1001 -const USER_REJECTED_REQUEST_CODE = 4001 +import { WC_ERRORS, EVMBasedNamespaces } from './constants' export const errorLabel = 'We were unable to create a connection due to compatibility issues with the latest WalletConnect v2 upgrade. We are actively working with the WalletConnect team and the dApps to get these issues resolved. Use Safe Apps instead wherever possible.' @@ -93,7 +87,7 @@ const useWalletConnect = (): useWalletConnectType => { setError(errorMessage) await walletConnect.sendSessionResponse({ topic, - response: rejectResponse(id, UNSUPPORTED_CHAIN_ERROR_CODE, errorMessage), + response: rejectResponse(id, WC_ERRORS.UNSUPPORTED_CHAIN_ERROR_CODE, errorMessage), }) return } @@ -115,7 +109,7 @@ const useWalletConnect = (): useWalletConnectType => { } catch (error: any) { setError(error?.message) const isUserRejection = error?.message?.includes?.('Transaction was rejected') - const code = isUserRejection ? USER_REJECTED_REQUEST_CODE : INVALID_METHOD_ERROR_CODE + const code = isUserRejection ? WC_ERRORS.USER_REJECTED_REQUEST_CODE : WC_ERRORS.INVALID_METHOD_ERROR_CODE try { await walletConnect.sendSessionResponse({ diff --git a/src/components/wallet-connect/index.tsx b/src/components/wallet-connect/index.tsx index 8ad3b45c43..1bc5b7a496 100644 --- a/src/components/wallet-connect/index.tsx +++ b/src/components/wallet-connect/index.tsx @@ -13,7 +13,7 @@ import { Typography, } from '@mui/material' import WcIcon from '@/public/images/apps/wallet-connect.svg' -import { type ChangeEvent, useCallback, useState, useRef } from 'react' +import { type ChangeEvent, useState, useRef } from 'react' import useWalletConnect, { WC_CONNECT_STATE } from './hooks/useWalletConnect' import css from './styles.module.css' import type { Web3WalletTypes } from '@walletconnect/web3wallet' @@ -38,7 +38,6 @@ const extractInformationFromProposal = (sessionProposal: Web3WalletTypes.Session export const ConnectWC = () => { const [openModal, setOpenModal] = useState(false) - const [wcConnectUrl, setWcConnectUrl] = useState('') const { wcConnect, wcDisconnect, wcClientData, wcApproveSession, acceptInvalidSession, wcState, sessionProposal } = useWalletConnect() const anchorElem = useRef(null) @@ -55,45 +54,11 @@ export const ConnectWC = () => { setOpenModal((prev) => !prev) } - const onConnect = useCallback( - async (uri: string) => { - await wcConnect(uri) - }, - [wcConnect], - ) - - const onChangeWcUrl = (event: ChangeEvent) => { - const newValue = event.target.value - setWcConnectUrl(newValue) + const onChangeWcUrl = async (event: ChangeEvent) => { + const uri = event.target.value + await wcConnect(uri) } - const onPaste = useCallback( - (event: React.ClipboardEvent) => { - const connectWithUri = (data: string) => { - if (data.startsWith('wc')) { - onConnect(data) - } - } - - setWcConnectUrl('') - - if (wcClientData) { - return - } - - const items = event.clipboardData.items - - for (const index in items) { - const item = items[index] - - if (item.kind === 'string' && item.type === 'text/plain') { - connectWithUri(event.clipboardData.getData('Text')) - } - } - }, - [wcClientData, onConnect], - ) - return ( <> @@ -219,7 +184,6 @@ export const ConnectWC = () => {