forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
121 changed files
with
3,185 additions
and
1,526 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,40 @@ | ||
import { useAsyncStorage } from '@react-native-async-storage/async-storage'; | ||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
import Clipboard from '@react-native-clipboard/clipboard'; | ||
|
||
const BlueClipboard = () => { | ||
const STORAGE_KEY = 'ClipboardReadAllowed'; | ||
const { getItem, setItem } = useAsyncStorage(STORAGE_KEY); | ||
const STORAGE_KEY: string = 'ClipboardReadAllowed'; | ||
|
||
const isReadClipboardAllowed = async () => { | ||
try { | ||
const clipboardAccessAllowed = await getItem(); | ||
if (clipboardAccessAllowed === null) { | ||
await setItem(JSON.stringify(true)); | ||
return true; | ||
} | ||
return !!JSON.parse(clipboardAccessAllowed); | ||
} catch { | ||
await setItem(JSON.stringify(true)); | ||
export const isReadClipboardAllowed = async (): Promise<boolean> => { | ||
try { | ||
const clipboardAccessAllowed = await AsyncStorage.getItem(STORAGE_KEY); | ||
if (clipboardAccessAllowed === null) { | ||
await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(true)); | ||
return true; | ||
} | ||
}; | ||
return !!JSON.parse(clipboardAccessAllowed); | ||
} catch { | ||
await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(true)); | ||
return true; | ||
} | ||
}; | ||
|
||
const setReadClipboardAllowed = (value: boolean) => { | ||
setItem(JSON.stringify(!!value)); | ||
}; | ||
export const setReadClipboardAllowed = async (value: boolean): Promise<void> => { | ||
try { | ||
await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(Boolean(value))); | ||
} catch (error) { | ||
console.error('Failed to set clipboard permission:', error); | ||
throw error; | ||
} | ||
}; | ||
|
||
const getClipboardContent = async () => { | ||
export const getClipboardContent = async (): Promise<string | undefined> => { | ||
try { | ||
const isAllowed = await isReadClipboardAllowed(); | ||
const hasString = (await Clipboard.hasString()) || false; | ||
if (isAllowed && hasString) { | ||
return Clipboard.getString(); | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
if (!isAllowed) return undefined; | ||
|
||
return { | ||
isReadClipboardAllowed, | ||
setReadClipboardAllowed, | ||
getClipboardContent, | ||
}; | ||
const hasString = await Clipboard.hasString(); | ||
return hasString ? await Clipboard.getString() : undefined; | ||
} catch (error) { | ||
console.error('Error accessing clipboard:', error); | ||
return undefined; | ||
} | ||
}; | ||
|
||
export default BlueClipboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.