mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-19 05:45:15 +01:00
REF: BlueClipboard JS -> TS
This commit is contained in:
parent
6ed25c807c
commit
edf92c9dbc
@ -1,38 +0,0 @@
|
||||
import { useAsyncStorage } from '@react-native-async-storage/async-storage';
|
||||
import Clipboard from '@react-native-clipboard/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;
|
35
blue_modules/clipboard.ts
Normal file
35
blue_modules/clipboard.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { useAsyncStorage } from '@react-native-async-storage/async-storage';
|
||||
import Clipboard from '@react-native-clipboard/clipboard';
|
||||
|
||||
class BlueClipboard {
|
||||
static STORAGE_KEY = 'ClipboardReadAllowed';
|
||||
|
||||
static isReadClipboardAllowed = async (): Promise<boolean> => {
|
||||
const isClipboardAccessAllowed = await useAsyncStorage(BlueClipboard.STORAGE_KEY).getItem();
|
||||
try {
|
||||
if (isClipboardAccessAllowed === null) {
|
||||
await useAsyncStorage(BlueClipboard.STORAGE_KEY).setItem(JSON.stringify(true));
|
||||
return true;
|
||||
}
|
||||
return !!JSON.parse(isClipboardAccessAllowed);
|
||||
} catch {
|
||||
await useAsyncStorage(BlueClipboard.STORAGE_KEY).setItem(JSON.stringify(true));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
static setReadClipboardAllowed = (value: boolean): void => {
|
||||
useAsyncStorage(BlueClipboard.STORAGE_KEY).setItem(JSON.stringify(!!value));
|
||||
};
|
||||
|
||||
static getClipboardContent = async (): Promise<string> => {
|
||||
const isAllowed = await BlueClipboard.isReadClipboardAllowed();
|
||||
if (isAllowed) {
|
||||
return Clipboard.getString();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default new BlueClipboard();
|
Loading…
Reference in New Issue
Block a user