Skip to content

Commit

Permalink
fix: clear clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Oct 16, 2023
1 parent e0ead58 commit a518831
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/components/walletconnect/HeaderWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const usePrepopulatedUri = (): [string, () => void] => {

const clearUri = useCallback(() => {
setSearchParamWcUri(null)
// This does not clear the system clipboard, just state
setClipboardWcUri('')
}, [setClipboardWcUri, setSearchParamWcUri])

Expand Down
17 changes: 14 additions & 3 deletions src/services/walletconnect/useWalletConnectClipboardUri.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useState, useEffect } from 'react'
import type { SetStateAction, Dispatch } from 'react'

import { getClipboard, isClipboardGranted } from '@/utils/clipboard'
import { Errors, logError } from '../exceptions'

export const useWalletConnectClipboardUri = (): [string, Dispatch<SetStateAction<string>>] => {
export const useWalletConnectClipboardUri = (): [string, (data: string) => Promise<void>] => {
const [state, setState] = useState('')

useEffect(() => {
Expand Down Expand Up @@ -34,5 +34,16 @@ export const useWalletConnectClipboardUri = (): [string, Dispatch<SetStateAction
}
}, [])

return [state, setState]
const setClipboard = async (data: string) => {
await navigator.clipboard
.writeText(data)
.then(() => {
setState(data)
})
.catch((e) => {
logError(Errors._709, e)
})
}

return [state, setClipboard]
}

0 comments on commit a518831

Please sign in to comment.