mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 18:00:17 +01:00
5ece75b691
* ADD: Privacy Settings Screen * REF: Clipboard read opt-out * ADD: Wallet shortcut privacy * FIX: Remove unused code * REF:Addasync/await * REF: BlueClipboard * REF: Rename file
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import { useAsyncStorage } from '@react-native-community/async-storage';
|
|
import Clipboard from '@react-native-community/clipboard';
|
|
|
|
function BlueClipboard() {
|
|
BlueClipboard.STORAGE_KEY = 'ClipboardReadAllowed';
|
|
const isClipboardAccessAllowed = useAsyncStorage(BlueClipboard.STORAGE_KEY).getItem;
|
|
const setIsClipboardAccessAllowed = useAsyncStorage(BlueClipboard.STORAGE_KEY).setItem;
|
|
|
|
BlueClipboard.isReadClipboardAllowed = async () => {
|
|
try {
|
|
const clipboardAccessAllowed = await isClipboardAccessAllowed();
|
|
if (clipboardAccessAllowed === null) {
|
|
await setIsClipboardAccessAllowed(JSON.stringify(true));
|
|
return true;
|
|
}
|
|
return !!JSON.parse(clipboardAccessAllowed);
|
|
} catch {
|
|
await setIsClipboardAccessAllowed(JSON.stringify(true));
|
|
return true;
|
|
}
|
|
};
|
|
|
|
BlueClipboard.setReadClipboardAllowed = value => {
|
|
setIsClipboardAccessAllowed(JSON.stringify(!!value));
|
|
};
|
|
|
|
BlueClipboard.getClipboardContent = async () => {
|
|
const isAllowed = await BlueClipboard.isReadClipboardAllowed();
|
|
if (isAllowed) {
|
|
return Clipboard.getString();
|
|
} else {
|
|
return '';
|
|
}
|
|
};
|
|
}
|
|
|
|
BlueClipboard.default = new BlueClipboard();
|
|
export default BlueClipboard;
|