BlueWallet/screen/settings/lightningSettings.js

118 lines
3.5 KiB
JavaScript
Raw Normal View History

/* global alert */
2018-11-04 22:21:07 +01:00
import React, { Component } from 'react';
2019-05-02 22:33:03 +02:00
import { View, TextInput, Linking } from 'react-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';
import { BlueLoading, BlueSpacing20, BlueButton, SafeBlueArea, BlueCard, BlueNavigationStyle, BlueText } from '../../BlueComponents';
2018-11-04 22:21:07 +01:00
import PropTypes from 'prop-types';
2019-01-24 20:31:30 +01:00
import { Button } from 'react-native-elements';
2018-11-04 22:21:07 +01:00
import { LightningCustodianWallet } from '../../class/lightning-custodian-wallet';
/** @type {AppStorage} */
let BlueApp = require('../../BlueApp');
let loc = require('../../loc');
2018-11-04 22:21:07 +01:00
export default class LightningSettings extends Component {
static navigationOptions = () => ({
...BlueNavigationStyle(),
title: loc.settings.lightning_settings,
2018-11-04 22:21:07 +01:00
});
constructor(props) {
super(props);
this.state = {
isLoading: true,
};
}
async componentDidMount() {
let URI = await AsyncStorage.getItem(AppStorage.LNDHUB);
2018-11-04 22:21:07 +01:00
this.setState({
isLoading: false,
URI,
});
}
save = () => {
this.setState({ isLoading: true }, async () => {
this.state.URI = this.state.URI ? this.state.URI : '';
try {
if (this.state.URI) {
await LightningCustodianWallet.isValidNodeAddress(this.state.URI);
// validating only if its not empty. empty means use default
}
await AsyncStorage.setItem(AppStorage.LNDHUB, this.state.URI);
alert('Your changes have been saved successfully');
} catch (error) {
alert('Not a valid LndHub URI');
console.log(error);
2018-11-04 22:21:07 +01:00
}
this.setState({ isLoading: false });
});
};
2018-11-04 22:21:07 +01:00
render() {
return (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
<BlueCard>
2019-01-11 21:21:59 +01:00
<BlueText>{loc.settings.lightning_settings_explain}</BlueText>
</BlueCard>
2018-12-26 23:18:01 +01:00
2019-01-24 20:31:30 +01:00
<Button
icon={{
2019-04-06 22:18:54 +02:00
name: 'github',
type: 'font-awesome',
color: BlueApp.settings.buttonTextColor,
backgroundColor: '#FFFFFF',
}}
onPress={() => {
Linking.openURL('https://github.com/BlueWallet/LndHub');
}}
title="github.com/BlueWallet/LndHub"
2019-01-24 20:31:30 +01:00
color={BlueApp.settings.buttonTextColor}
buttonStyle={{
backgroundColor: '#FFFFFF',
}}
/>
2018-11-04 22:21:07 +01:00
<BlueCard>
2018-11-04 22:21:07 +01:00
<View
style={{
flexDirection: 'row',
borderColor: '#d2d2d2',
borderBottomColor: '#d2d2d2',
borderWidth: 1.0,
borderBottomWidth: 0.5,
backgroundColor: '#f5f5f5',
minHeight: 44,
height: 44,
alignItems: 'center',
borderRadius: 4,
}}
>
<TextInput
placeholder={LightningCustodianWallet.defaultBaseUri}
2018-11-04 22:21:07 +01:00
value={this.state.URI}
onChangeText={text => this.setState({ URI: text })}
numberOfLines={1}
2019-01-24 20:31:30 +01:00
style={{ flex: 1, marginHorizontal: 8, minHeight: 36, height: 36 }}
2018-11-04 22:21:07 +01:00
editable={!this.state.isLoading}
underlineColorAndroid="transparent"
/>
</View>
<BlueSpacing20 />
{this.state.isLoading ? <BlueLoading /> : <BlueButton onPress={this.save} title={loc.settings.save} />}
2018-11-04 22:21:07 +01:00
</BlueCard>
</SafeBlueArea>
);
}
}
LightningSettings.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
goBack: PropTypes.func,
}),
};