Skip to content

Commit

Permalink
Rm onPaste
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed Sep 20, 2023
1 parent 5eb5938 commit 6d18143
Showing 1 changed file with 4 additions and 40 deletions.
44 changes: 4 additions & 40 deletions src/components/wallet-connect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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<HTMLButtonElement | null>(null)
Expand All @@ -55,45 +54,11 @@ export const ConnectWC = () => {
setOpenModal((prev) => !prev)
}

const onConnect = useCallback(
async (uri: string) => {
await wcConnect(uri)
},
[wcConnect],
)

const onChangeWcUrl = (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const newValue = event.target.value
setWcConnectUrl(newValue)
const onChangeWcUrl = async (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
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 (
<>
<IconButton onClick={handleWidgetIconClick} ref={anchorElem}>
Expand Down Expand Up @@ -219,7 +184,6 @@ export const ConnectWC = () => {
<TextField
placeholder="wc:"
label="Wallet Connect URI"
onPaste={onPaste}
onChange={onChangeWcUrl}
fullWidth
sx={{ mt: 2 }}
Expand Down

0 comments on commit 6d18143

Please sign in to comment.