mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-18 13:26:33 +01:00
REF: convert lightningSettings to typescript
This commit is contained in:
parent
1d015d5a2d
commit
2b57c9e4e6
@ -512,6 +512,11 @@ export class BlueWalletNavigationHeader extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: remove this comment once this file gets properly converted to typescript.
|
||||
*
|
||||
* @type {React.FC<any>}
|
||||
*/
|
||||
export const BlueButtonLink = forwardRef((props, ref) => {
|
||||
const { colors } = useTheme();
|
||||
return (
|
||||
|
@ -3,7 +3,7 @@ import { getSystemName, isTablet, getDeviceType } from 'react-native-device-info
|
||||
|
||||
const isMacCatalina = getSystemName() === 'Mac OS X';
|
||||
const isDesktop = getDeviceType() === 'Desktop';
|
||||
const isTorCapable = () => {
|
||||
const getIsTorCapable = () => {
|
||||
let capable = true;
|
||||
if (Platform.OS === 'android' && Platform.Version < 26) {
|
||||
capable = false;
|
||||
@ -13,8 +13,6 @@ const isTorCapable = () => {
|
||||
return capable;
|
||||
};
|
||||
|
||||
module.exports.isMacCatalina = isMacCatalina;
|
||||
module.exports.isDesktop = isDesktop;
|
||||
module.exports.isHandset = getDeviceType() === 'Handset';
|
||||
module.exports.isTablet = isTablet;
|
||||
module.exports.isTorCapable = isTorCapable();
|
||||
export const isHandset = getDeviceType() === 'Handset';
|
||||
export const isTorCapable = getIsTorCapable();
|
||||
export { isMacCatalina, isDesktop, isTablet };
|
||||
|
@ -10,6 +10,12 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* TODO: remove this comment once this file gets properly converted to typescript.
|
||||
*
|
||||
* @param {any} param0
|
||||
* @param {(opts: any) => any} formatter
|
||||
*/
|
||||
const navigationStyle = ({ closeButton = false, closeButtonFunc, ...opts }, formatter) => {
|
||||
return theme => ({ navigation, route }) => {
|
||||
let headerRight = null;
|
||||
|
@ -120,6 +120,10 @@ export const BlueDarkTheme = {
|
||||
};
|
||||
|
||||
export class BlueCurrentTheme {
|
||||
static colors;
|
||||
static closeImage;
|
||||
static scanImage;
|
||||
|
||||
static updateColorScheme() {
|
||||
const isColorSchemeDark = Appearance.getColorScheme() === 'dark';
|
||||
BlueCurrentTheme.colors = isColorSchemeDark ? BlueDarkTheme.colors : BlueDefaultTheme.colors;
|
||||
|
@ -136,7 +136,7 @@ const setDateTimeLocale = async () => {
|
||||
if (localeForDayJSAvailable) {
|
||||
dayjs.locale(lang.split('_')[0]);
|
||||
const language = AvailableLanguages.find(language => language.value === lang.replace('_', '-'));
|
||||
/* I18n Manager breaks testing. Mocking built-in RN modules is not so straightforward.
|
||||
/* I18n Manager breaks testing. Mocking built-in RN modules is not so straightforward.
|
||||
Only run this conditional if its outside a testing environment.
|
||||
*/
|
||||
if (process.env.JEST_WORKER_ID === undefined) {
|
||||
@ -180,6 +180,11 @@ const setLanguageLocale = async () => {
|
||||
};
|
||||
setLanguageLocale();
|
||||
|
||||
/**
|
||||
* TODO: remove this comment once this file gets properly converted to typescript.
|
||||
*
|
||||
* @type {any}
|
||||
*/
|
||||
const strings = new Localization({
|
||||
en: require('./en.json'),
|
||||
ar: require('./ar.json'),
|
||||
|
@ -2,7 +2,7 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { View, TextInput, Linking, StyleSheet, Alert, I18nManager } from 'react-native';
|
||||
import { Button } from 'react-native-elements';
|
||||
import { useTheme, useNavigation, useRoute } from '@react-navigation/native';
|
||||
import { useTheme, useNavigation, useRoute, RouteProp } from '@react-navigation/native';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
|
||||
import navigationStyle from '../../components/navigationStyle';
|
||||
@ -43,29 +43,39 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
});
|
||||
|
||||
const LightningSettings = () => {
|
||||
const params = useRoute().params;
|
||||
type LightingSettingsRouteProps = RouteProp<
|
||||
{
|
||||
params?: {
|
||||
url?: string;
|
||||
};
|
||||
},
|
||||
'params'
|
||||
>;
|
||||
|
||||
// TODO: add proper typing for `navigationOptions`
|
||||
const LightningSettings: React.FC & { navigationOptions: any } = () => {
|
||||
const params = useRoute<LightingSettingsRouteProps>().params;
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [URI, setURI] = useState();
|
||||
const { colors } = useTheme();
|
||||
const [URI, setURI] = useState<string>();
|
||||
const { colors } = useTheme() as any; // TODO: add proper types for theme
|
||||
const route = useRoute();
|
||||
const navigation = useNavigation();
|
||||
|
||||
useEffect(() => {
|
||||
AsyncStorage.getItem(AppStorage.LNDHUB)
|
||||
.then(setURI)
|
||||
.then(value => setURI(value ?? undefined))
|
||||
.then(() => setIsLoading(false))
|
||||
.catch(() => setIsLoading(false));
|
||||
|
||||
if (params?.url) {
|
||||
Alert.alert(
|
||||
loc.formatString(loc.settings.set_lndhub_as_default, { url: params?.url }),
|
||||
loc.formatString(loc.settings.set_lndhub_as_default, { url: params.url }) as string,
|
||||
'',
|
||||
[
|
||||
{
|
||||
text: loc._.ok,
|
||||
onPress: () => {
|
||||
setLndhubURI(params?.url);
|
||||
params?.url && setLndhubURI(params.url);
|
||||
},
|
||||
style: 'default',
|
||||
},
|
||||
@ -76,12 +86,11 @@ const LightningSettings = () => {
|
||||
}
|
||||
}, [params?.url]);
|
||||
|
||||
const setLndhubURI = value => {
|
||||
if (DeeplinkSchemaMatch.getUrlFromSetLndhubUrlAction(value)) {
|
||||
// in case user scans a QR with a deeplink like `bluewallet:setlndhuburl?url=https%3A%2F%2Flndhub.herokuapp.com`
|
||||
value = DeeplinkSchemaMatch.getUrlFromSetLndhubUrlAction(value);
|
||||
}
|
||||
setURI(value.trim());
|
||||
const setLndhubURI = (value: string) => {
|
||||
// in case user scans a QR with a deeplink like `bluewallet:setlndhuburl?url=https%3A%2F%2Flndhub.herokuapp.com`
|
||||
const setLndHubUrl = DeeplinkSchemaMatch.getUrlFromSetLndhubUrlAction(value);
|
||||
|
||||
setURI(typeof setLndHubUrl === 'string' ? setLndHubUrl.trim() : value.trim());
|
||||
};
|
||||
|
||||
const save = useCallback(async () => {
|
||||
@ -91,7 +100,11 @@ const LightningSettings = () => {
|
||||
await LightningCustodianWallet.isValidNodeAddress(URI);
|
||||
// validating only if its not empty. empty means use default
|
||||
}
|
||||
await AsyncStorage.setItem(AppStorage.LNDHUB, URI);
|
||||
if (URI) {
|
||||
await AsyncStorage.setItem(AppStorage.LNDHUB, URI);
|
||||
} else {
|
||||
await AsyncStorage.removeItem(AppStorage.LNDHUB);
|
||||
}
|
||||
alert(loc.settings.lightning_saved);
|
||||
} catch (error) {
|
||||
alert(loc.settings.lightning_error_lndhub_uri);
|
||||
@ -126,7 +139,8 @@ const LightningSettings = () => {
|
||||
onPress={() => Linking.openURL('https://github.com/BlueWallet/LndHub')}
|
||||
titleStyle={{ color: colors.buttonAlternativeTextColor }}
|
||||
title="github.com/BlueWallet/LndHub"
|
||||
color={colors.buttonTextColor}
|
||||
// TODO: looks like there's no `color` prop on `Button`, does this make any sense?
|
||||
// color={colors.buttonTextColor}
|
||||
buttonStyle={styles.buttonStyle}
|
||||
/>
|
||||
|
1
typings/globals.d.ts
vendored
Normal file
1
typings/globals.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
declare function alert(message: string): void;
|
Loading…
Reference in New Issue
Block a user