Skip to content

Commit

Permalink
fix: don't check for permissions on Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Oct 17, 2023
1 parent 3fd395f commit a6b9d47
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/components/walletconnect/WcInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -14,10 +14,6 @@ const WcInput = ({ uri }: { uri: string }): ReactElement => {
const [error, setError] = useState<Error>()
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
Expand Down Expand Up @@ -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 : (
<InputAdornment position="end">
<Button variant="contained" onClick={onPaste} className={css.button}>
Paste
Expand Down
15 changes: 11 additions & 4 deletions src/utils/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { logError, Errors } from '@/services/exceptions'

export const isFirefox = (): boolean => {
// 'clipboard-read' and `readText` are not supported by Firefox
// @see https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/readText#browser_compatibility
return navigator.userAgent.includes('Firefox')
}

export const isClipboardGranted = async (): Promise<boolean> => {
if (isFirefox()) {
return false
}

let isGranted = false

try {
Expand All @@ -15,10 +25,7 @@ export const isClipboardGranted = async (): Promise<boolean> => {
}

export const getClipboard = async (): Promise<string> => {
// 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')
if (isFirefox) {
if (isFirefox()) {
return ''
}

Expand Down

0 comments on commit a6b9d47

Please sign in to comment.