Skip to content

Commit

Permalink
Merge pull request #1982 from kaloudis/settings-channels
Browse files Browse the repository at this point in the history
Settings: Channels
  • Loading branch information
kaloudis authored Feb 19, 2024
2 parents 9f3b0af + fad95ee commit 54a585c
Show file tree
Hide file tree
Showing 6 changed files with 312 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import ProductDetails from './views/POS/ProductDetails';
import PaymentsSettings from './views/Settings/PaymentsSettings';
import InvoicesSettings from './views/Settings/InvoicesSettings';
import LSP from './views/Settings/LSP';
import ChannelsSettings from './views/Settings/ChannelsSettings';

// Lightning address
import LightningAddress from './views/Settings/LightningAddress';
Expand Down Expand Up @@ -422,6 +423,9 @@ const AppScenes = {
ContactQR: {
screen: ContactQR
},
ChannelsSettings: {
screen: ChannelsSettings
},
RawTxHex: {
screen: RawTxHex
}
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@
"views.Settings.Payments.feeLimitMethodExplainer": "Fee limit method will default to fixed for amounts up to 1000 sats and percentage for amounts greater than 1000 sats. You'll be able to change which method and values to use though, under the Settings section of the Payment Request view.",
"views.Settings.Invoices.title": "Invoices settings",
"views.Settings.Invoices.showCustomPreimageField": "Show custom preimage field",
"views.Settings.Channels.title": "Channels settings",
"views.Settings.Privacy.blockExplorer": "Default Block explorer",
"views.Settings.Privacy.BlockExplorer.custom": "Custom",
"views.Settings.Privacy.customBlockExplorer": "Custom Block explorer",
Expand Down
14 changes: 14 additions & 0 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ interface InvoicesSettings {
showCustomPreimageField?: boolean;
}

interface ChannelsSettings {
min_confs: number;
privateChannel: boolean;
scidAlias: boolean;
simpleTaprootChannel: boolean;
}

interface LightningAddressSettings {
enabled: boolean;
automaticallyAccept: boolean;
Expand Down Expand Up @@ -109,6 +116,7 @@ export interface Settings {
pos: PosSettings;
payments: PaymentsSettings;
invoices: InvoicesSettings;
channels: ChannelsSettings;
isBiometryEnabled: boolean;
supportedBiometryType?: BiometryType;
lndHubLnAuthMode?: string;
Expand Down Expand Up @@ -945,6 +953,12 @@ export default class SettingsStore {
ampInvoice: false,
showCustomPreimageField: false
},
channels: {
min_confs: 1,
privateChannel: true,
scidAlias: true,
simpleTaprootChannel: false
},
supportedBiometryType: undefined,
isBiometryEnabled: false,
scramblePin: true,
Expand Down
16 changes: 16 additions & 0 deletions views/OpenChannel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ export default class OpenChannel extends React.Component<
});
}
}

this.setState({
min_confs: settings?.channels?.min_confs || 1,
privateChannel:
settings?.channels?.privateChannel !== null
? settings.channels.privateChannel
: true,
scidAlias:
settings?.channels?.scidAlias !== null
? settings.channels.scidAlias
: true,
simpleTaprootChannel:
settings?.channels?.simpleTaprootChannel !== null
? settings.channels.simpleTaprootChannel
: false
});
}

async componentDidMount() {
Expand Down
233 changes: 233 additions & 0 deletions views/Settings/ChannelsSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
import * as React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { inject, observer } from 'mobx-react';

import Header from '../../components/Header';
import Screen from '../../components/Screen';
import Switch from '../../components/Switch';
import TextInput from '../../components/TextInput';

import SettingsStore from '../../stores/SettingsStore';

import BackendUtils from '../../utils/BackendUtils';
import { localeString } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';

interface ChannelsSettingsProps {
navigation: any;
SettingsStore: SettingsStore;
}

interface ChannelsSettingsState {
min_confs: number;
privateChannel: boolean;
scidAlias: boolean;
simpleTaprootChannel: boolean;
}

@inject('SettingsStore')
@observer
export default class ChannelsSettings extends React.Component<
ChannelsSettingsProps,
ChannelsSettingsState
> {
state = {
min_confs: 1,
privateChannel: true,
scidAlias: true,
simpleTaprootChannel: false
};

async UNSAFE_componentWillMount() {
const { SettingsStore } = this.props;
const { getSettings } = SettingsStore;
const settings = await getSettings();

this.setState({
min_confs: settings?.channels?.min_confs || 1,
privateChannel:
settings?.channels?.privateChannel !== null
? settings.channels.privateChannel
: true,
scidAlias:
settings?.channels?.scidAlias !== null
? settings.channels.scidAlias
: true,
simpleTaprootChannel:
settings?.channels?.simpleTaprootChannel !== null
? settings.channels.simpleTaprootChannel
: false
});
}

renderSeparator = () => (
<View
style={{
height: 1,
backgroundColor: themeColor('separator')
}}
/>
);

render() {
const { navigation, SettingsStore } = this.props;
const { min_confs, privateChannel, scidAlias, simpleTaprootChannel } =
this.state;
const { updateSettings }: any = SettingsStore;

return (
<Screen>
<Header
leftComponent="Back"
centerComponent={{
text: localeString('views.Settings.Channels.title'),
style: {
color: themeColor('text'),
fontFamily: 'PPNeueMontreal-Book'
}
}}
navigation={navigation}
/>
<View
style={{
padding: 20
}}
>
<Text
style={{
...styles.text,
color: themeColor('secondaryText')
}}
>
{localeString('views.OpenChannel.numConf')}
</Text>
<TextInput
keyboardType="numeric"
placeholder={'1'}
value={min_confs.toString()}
onChangeText={async (text: string) => {
const newMinConfs = Number(text);
this.setState({
min_confs: newMinConfs
});
await updateSettings({
channels: {
min_confs: newMinConfs,
privateChannel,
scidAlias,
simpleTaprootChannel
}
});
}}
/>

<>
<Text
style={{
top: 20,
color: themeColor('secondaryText')
}}
>
{localeString('views.OpenChannel.announceChannel')}
</Text>
<Switch
value={!privateChannel}
onValueChange={async () => {
this.setState({
privateChannel: !privateChannel
});
await updateSettings({
channels: {
min_confs,
privateChannel: !privateChannel,
scidAlias,
simpleTaprootChannel
}
});
}}
disabled={simpleTaprootChannel}
/>
</>

{BackendUtils.isLNDBased() && (
<>
<Text
style={{
top: 20,
color: themeColor('secondaryText')
}}
>
{localeString('views.OpenChannel.scidAlias')}
</Text>
<Switch
value={scidAlias}
onValueChange={async () => {
this.setState({
scidAlias: !scidAlias
});
await updateSettings({
channels: {
min_confs,
privateChannel,
scidAlias: !scidAlias,
simpleTaprootChannel
}
});
}}
/>
</>
)}

{BackendUtils.supportsSimpleTaprootChannels() && (
<>
<Text
style={{
top: 20,
color: themeColor('secondaryText')
}}
>
{localeString(
'views.OpenChannel.simpleTaprootChannel'
)}
</Text>
<Switch
value={simpleTaprootChannel}
onValueChange={async () => {
this.setState({
simpleTaprootChannel:
!simpleTaprootChannel
});

if (!simpleTaprootChannel) {
this.setState({
privateChannel: true
});
}

await updateSettings({
channels: {
min_confs,
privateChannel:
!simpleTaprootChannel
? true
: privateChannel,
scidAlias,
simpleTaprootChannel:
!simpleTaprootChannel
}
});
}}
/>
</>
)}
</View>
</Screen>
);
}
}

const styles = StyleSheet.create({
text: {
fontFamily: 'PPNeueMontreal-Book'
}
});
44 changes: 44 additions & 0 deletions views/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { inject, observer } from 'mobx-react';
import AddIcon from '../../assets/images/SVG/Add.svg';
import BlockIcon from '../../assets/images/SVG/Block.svg';
import ForwardIcon from '../../assets/images/SVG/Caret Right-3.svg';
import ChannelsIcon from '../../assets/images/SVG/Channels.svg';
import ContactIcon from '../../assets/images/SVG/PeersContact.svg';
import PrivacyIcon from '../../assets/images/SVG/Eye On.svg';
import SecurityIcon from '../../assets/images/SVG/Lock.svg';
Expand Down Expand Up @@ -675,6 +676,49 @@ export default class Settings extends React.Component<
</View>
)}

{selectedNode && BackendUtils.supportsChannelManagement() && (
<View
style={{
backgroundColor: themeColor('secondary'),
width: '90%',
borderRadius: 10,
alignSelf: 'center',
marginVertical: 5
}}
>
<TouchableOpacity
onPress={() =>
navigation.navigate('ChannelsSettings')
}
>
<View style={styles.columnField}>
<View style={styles.icon}>
<ChannelsIcon
fill={themeColor('text')}
width={27}
height={27}
/>
</View>
<Text
style={{
...styles.columnText,
color: themeColor('text')
}}
>
{localeString(
'views.Wallet.Wallet.channels'
)}
</Text>
<View style={styles.ForwardArrow}>
<ForwardIcon
stroke={forwardArrowColor}
/>
</View>
</View>
</TouchableOpacity>
</View>
)}

{selectedNode &&
!BackendUtils.isLNDBased() &&
implementation !== 'lndhub' && (
Expand Down

0 comments on commit 54a585c

Please sign in to comment.