BlueWallet/blue_modules/environment.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-09-22 18:07:13 +02:00
import AsyncStorage from '@react-native-async-storage/async-storage';
import { Platform } from 'react-native';
import { isTablet, getDeviceType } from 'react-native-device-info';
2023-03-30 03:04:18 +02:00
const isDesktop: boolean = getDeviceType() === 'Desktop';
const getIsTorCapable = (): boolean => {
let capable = true;
if (Platform.OS === 'android' && Platform.Version < 26) {
capable = false;
} else if (isDesktop) {
capable = false;
}
return capable;
};
2023-03-30 03:04:18 +02:00
const IS_TOR_DAEMON_DISABLED: string = 'is_tor_daemon_disabled';
export async function setIsTorDaemonDisabled(disabled: boolean = true): Promise<void> {
2021-09-22 18:07:13 +02:00
return AsyncStorage.setItem(IS_TOR_DAEMON_DISABLED, disabled ? '1' : '');
}
2023-03-30 03:04:18 +02:00
export async function isTorDaemonDisabled(): Promise<boolean> {
let result: boolean;
2021-09-22 18:07:13 +02:00
try {
const savedValue = await AsyncStorage.getItem(IS_TOR_DAEMON_DISABLED);
if (savedValue === null) {
result = false;
2021-09-22 18:07:13 +02:00
} else {
result = savedValue === '1';
2021-09-22 18:07:13 +02:00
}
} catch {
result = true;
2021-09-22 18:07:13 +02:00
}
return result;
2021-09-22 18:07:13 +02:00
}
2023-03-30 03:04:18 +02:00
export const isHandset: boolean = getDeviceType() === 'Handset';
export const isTorCapable: boolean = getIsTorCapable();
export { isDesktop, isTablet };