2019-03-08 22:54:47 +01:00
|
|
|
/* global alert */
|
2020-07-15 19:32:59 +02:00
|
|
|
import React, { useState, useEffect, useCallback } from 'react';
|
2020-05-24 11:17:26 +02:00
|
|
|
import { View, TextInput, Linking, StyleSheet } from 'react-native';
|
2020-07-20 15:38:46 +02:00
|
|
|
import { Button } from 'react-native-elements';
|
|
|
|
import { useTheme } from '@react-navigation/native';
|
|
|
|
|
2018-11-04 22:21:07 +01:00
|
|
|
import { AppStorage } from '../../class';
|
2019-05-02 22:33:03 +02:00
|
|
|
import AsyncStorage from '@react-native-community/async-storage';
|
2020-07-15 19:32:59 +02:00
|
|
|
import {
|
|
|
|
BlueSpacing20,
|
|
|
|
BlueButton,
|
|
|
|
SafeBlueArea,
|
|
|
|
BlueCard,
|
|
|
|
BlueNavigationStyle,
|
|
|
|
BlueLoadingHook,
|
|
|
|
BlueTextHooks,
|
|
|
|
} from '../../BlueComponents';
|
2020-05-24 12:27:08 +02:00
|
|
|
import { LightningCustodianWallet } from '../../class/wallets/lightning-custodian-wallet';
|
2020-07-20 15:38:46 +02:00
|
|
|
import loc from '../../loc';
|
2020-07-15 19:32:59 +02:00
|
|
|
import { BlueCurrentTheme } from '../../components/themes';
|
|
|
|
|
2020-05-24 11:17:26 +02:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
uri: {
|
|
|
|
flexDirection: 'row',
|
2020-07-15 19:32:59 +02:00
|
|
|
borderColor: BlueCurrentTheme.colors.formBorder,
|
|
|
|
borderBottomColor: BlueCurrentTheme.colors.formBorder,
|
2020-05-24 11:17:26 +02:00
|
|
|
borderWidth: 1,
|
|
|
|
borderBottomWidth: 0.5,
|
2020-07-15 19:32:59 +02:00
|
|
|
backgroundColor: BlueCurrentTheme.colors.inputBackgroundColor,
|
2020-05-24 11:17:26 +02:00
|
|
|
minHeight: 44,
|
|
|
|
height: 44,
|
|
|
|
alignItems: 'center',
|
|
|
|
borderRadius: 4,
|
|
|
|
},
|
|
|
|
uriText: {
|
|
|
|
flex: 1,
|
2020-06-13 22:27:17 +02:00
|
|
|
color: '#81868e',
|
2020-05-24 11:17:26 +02:00
|
|
|
marginHorizontal: 8,
|
|
|
|
minHeight: 36,
|
|
|
|
height: 36,
|
|
|
|
},
|
2020-06-01 14:54:23 +02:00
|
|
|
buttonStyle: {
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
},
|
2020-05-24 11:17:26 +02:00
|
|
|
});
|
|
|
|
|
2020-07-15 19:32:59 +02:00
|
|
|
const LightningSettings = () => {
|
|
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
const [URI, setURI] = useState();
|
|
|
|
const { colors } = useTheme();
|
2018-11-04 22:21:07 +01:00
|
|
|
|
2020-07-15 19:32:59 +02:00
|
|
|
useEffect(() => {
|
|
|
|
AsyncStorage.getItem(AppStorage.LNDHUB)
|
|
|
|
.then(setURI)
|
|
|
|
.then(() => setIsLoading(false))
|
|
|
|
.catch(() => setIsLoading(false));
|
|
|
|
}, []);
|
2018-11-04 22:21:07 +01:00
|
|
|
|
2020-08-26 05:18:59 +02:00
|
|
|
const setLndhubURI = value => {
|
|
|
|
setURI(value.trim());
|
|
|
|
};
|
|
|
|
|
2020-07-15 19:32:59 +02:00
|
|
|
const save = useCallback(async () => {
|
|
|
|
setIsLoading(true);
|
|
|
|
try {
|
|
|
|
if (URI) {
|
|
|
|
await LightningCustodianWallet.isValidNodeAddress(URI);
|
|
|
|
// validating only if its not empty. empty means use default
|
2018-11-04 22:21:07 +01:00
|
|
|
}
|
2020-07-15 19:32:59 +02:00
|
|
|
await AsyncStorage.setItem(AppStorage.LNDHUB, URI);
|
2020-07-20 15:38:46 +02:00
|
|
|
alert(loc.settings.lightning_saved);
|
2020-07-15 19:32:59 +02:00
|
|
|
} catch (error) {
|
2020-07-20 15:38:46 +02:00
|
|
|
alert(loc.settings.lightning_error_lndhub_uri);
|
2020-07-15 19:32:59 +02:00
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
setIsLoading(false);
|
|
|
|
}, [URI]);
|
2018-11-04 22:21:07 +01:00
|
|
|
|
2020-07-15 19:32:59 +02:00
|
|
|
return (
|
|
|
|
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={styles.root}>
|
|
|
|
<BlueCard>
|
|
|
|
<BlueTextHooks>{loc.settings.lightning_settings_explain}</BlueTextHooks>
|
|
|
|
</BlueCard>
|
2018-12-26 23:18:01 +01:00
|
|
|
|
2020-07-15 19:32:59 +02:00
|
|
|
<Button
|
|
|
|
icon={{
|
|
|
|
name: 'github',
|
|
|
|
type: 'font-awesome',
|
|
|
|
color: colors.foregroundColor,
|
|
|
|
}}
|
2020-07-20 15:38:46 +02:00
|
|
|
onPress={() => Linking.openURL('https://github.com/BlueWallet/LndHub')}
|
2020-07-15 19:32:59 +02:00
|
|
|
titleStyle={{ color: colors.buttonAlternativeTextColor }}
|
|
|
|
title="github.com/BlueWallet/LndHub"
|
|
|
|
color={colors.buttonTextColor}
|
|
|
|
buttonStyle={styles.buttonStyle}
|
|
|
|
/>
|
2018-11-04 22:21:07 +01:00
|
|
|
|
2020-07-15 19:32:59 +02:00
|
|
|
<BlueCard>
|
|
|
|
<View style={styles.uri}>
|
|
|
|
<TextInput
|
|
|
|
placeholder={LightningCustodianWallet.defaultBaseUri}
|
|
|
|
value={URI}
|
2020-08-26 05:18:59 +02:00
|
|
|
onChangeText={setLndhubURI}
|
2020-07-15 19:32:59 +02:00
|
|
|
numberOfLines={1}
|
|
|
|
style={styles.uriText}
|
|
|
|
placeholderTextColor="#81868e"
|
|
|
|
editable={!isLoading}
|
|
|
|
textContentType="URL"
|
|
|
|
autoCapitalize="none"
|
2020-08-26 05:22:45 +02:00
|
|
|
autoCorrect={false}
|
2020-07-15 19:32:59 +02:00
|
|
|
underlineColorAndroid="transparent"
|
|
|
|
/>
|
|
|
|
</View>
|
2018-11-04 22:21:07 +01:00
|
|
|
|
2020-07-15 19:32:59 +02:00
|
|
|
<BlueSpacing20 />
|
|
|
|
{isLoading ? <BlueLoadingHook /> : <BlueButton onPress={save} title={loc.settings.save} />}
|
|
|
|
</BlueCard>
|
|
|
|
</SafeBlueArea>
|
|
|
|
);
|
2018-11-04 22:21:07 +01:00
|
|
|
};
|
2020-07-15 19:32:59 +02:00
|
|
|
|
|
|
|
LightningSettings.navigationOptions = () => ({
|
|
|
|
...BlueNavigationStyle(),
|
|
|
|
title: loc.settings.lightning_settings,
|
|
|
|
});
|
|
|
|
export default LightningSettings;
|