Skip to content

Commit

Permalink
Embedded LND: Settings: add Custom fee estimator
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Jul 8, 2024
1 parent 77bcc7c commit 5c0389b
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 8 deletions.
8 changes: 6 additions & 2 deletions components/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface TextInputProps {
onPressIn?: any;
right?: number;
ref?: React.Ref<TextInputRN>;
error?: boolean;
}

const TextInput: React.FC<TextInputProps> = (
Expand All @@ -56,7 +57,8 @@ const TextInput: React.FC<TextInputProps> = (
suffix,
toggleUnits,
onPressIn,
right
right,
error
},
ref
) => {
Expand Down Expand Up @@ -125,7 +127,9 @@ const TextInput: React.FC<TextInputProps> = (
opacity: locked ? 0.8 : 1,
...defaultStyle,
...styles.wrapper,
...style
...style,
borderWidth: error ? 1.0 : 0,
borderColor: error ? themeColor('error') : undefined
}}
>
{prefix ? (
Expand Down
2 changes: 2 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,8 @@
"views.Settings.EmbeddedNode.AdvancedDisasterRecovery.noBackups": "No backups found",
"views.Settings.EmbeddedNode.LNDLogs.title": "LND Logs",
"views.Settings.EmbeddedNode.LNDLogs.copyLogs": "Copy logs to clipboard",
"views.Settings.EmbeddedNode.feeEstimator": "Fee estimator",
"views.Settings.EmbeddedNode.customFeeEstimator": "Custom fee estimator",
"views.Settings.LSP.enableLSP": "Enable Lightning Service Provider (LSP)",
"views.Settings.LSP.enableLSP.subtitle": "The LSP will get you connected to the Lightning network by opening up payment channels for you.",
"views.Settings.LSP.lspAccessKey": "LSP Access Key (if needed)",
Expand Down
23 changes: 23 additions & 0 deletions stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export interface Settings {
recovery: boolean;
initialLoad: boolean;
embeddedTor: boolean;
feeEstimator: string;
customFeeEstimator: string;
// LSP
enableLSP: boolean;
lspMainnet: string;
Expand Down Expand Up @@ -202,6 +204,25 @@ export const MEMPOOL_RATES_KEYS = [
}
];

export const DEFAULT_FEE_ESTIMATOR =
'https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json';

export const FEE_ESTIMATOR_KEYS = [
{
key: 'lightning.computer',
value: 'https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json'
},
{
key: 'strike.me',
value: 'https://bitcoinchainfees.strike.me/v1/fee-estimates'
},
{
key: 'Custom',
translateKey: 'views.Settings.Privacy.BlockExplorer.custom',
value: 'Custom'
}
];

export const INTERFACE_KEYS = [
{ key: 'Embedded LND', value: 'embedded-lnd' },
{ key: 'LND (REST)', value: 'lnd' },
Expand Down Expand Up @@ -1064,6 +1085,8 @@ export default class SettingsStore {
recovery: false,
initialLoad: true,
embeddedTor: false,
feeEstimator: DEFAULT_FEE_ESTIMATOR,
customFeeEstimator: '',
// LSP
enableLSP: true,
lspMainnet: DEFAULT_LSP_MAINNET,
Expand Down
10 changes: 8 additions & 2 deletions utils/LndMobileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import stores from '../stores/Stores';
import {
DEFAULT_NEUTRINO_PEERS_MAINNET,
SECONDARY_NEUTRINO_PEERS_MAINNET,
DEFAULT_NEUTRINO_PEERS_TESTNET
DEFAULT_NEUTRINO_PEERS_TESTNET,
DEFAULT_FEE_ESTIMATOR
} from '../stores/SettingsStore';

import { lnrpc } from '../proto/lightning';
Expand Down Expand Up @@ -140,7 +141,12 @@ const writeLndConfig = async (
neutrino.persistfilters=true
[fee]
fee.url=https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json
fee.url=${
stores.settingsStore?.settings?.feeEstimator === 'Custom'
? stores.settingsStore?.settings?.customFeeEstimator
: stores.settingsStore?.settings?.feeEstimator ||
DEFAULT_FEE_ESTIMATOR
}
[autopilot]
autopilot.active=0
Expand Down
75 changes: 71 additions & 4 deletions views/Settings/EmbeddedNode/Advanced.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
import { StackNavigationProp } from '@react-navigation/stack';

import Button from '../../../components/Button';
import DropdownSetting from '../../../components/DropdownSetting';
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 SettingsStore, {
DEFAULT_FEE_ESTIMATOR,
FEE_ESTIMATOR_KEYS
} from '../../../stores/SettingsStore';

import { localeString } from '../../../utils/LocaleUtils';
import { restartNeeded } from '../../../utils/RestartUtils';
Expand All @@ -29,6 +34,8 @@ interface EmbeddedNodeAdvancedSettingsState {
embeddedTor: boolean | undefined;
persistentMode: boolean | undefined;
compactDb: boolean | undefined;
feeEstimator: string;
customFeeEstimator: string;
}

const PERSISTENT_KEY = 'persistentServicesEnabled';
Expand All @@ -43,7 +50,9 @@ export default class EmbeddedNodeAdvancedSettings extends React.Component<
rescan: false,
persistentMode: false,
embeddedTor: false,
compactDb: false
compactDb: false,
feeEstimator: DEFAULT_FEE_ESTIMATOR,
customFeeEstimator: ''
};

async UNSAFE_componentWillMount() {
Expand All @@ -56,13 +65,22 @@ export default class EmbeddedNodeAdvancedSettings extends React.Component<
rescan: settings.rescan,
persistentMode: persistentMode === 'true' ? true : false,
embeddedTor: settings.embeddedTor,
compactDb: settings.compactDb
compactDb: settings.compactDb,
feeEstimator: settings.feeEstimator || DEFAULT_FEE_ESTIMATOR,
customFeeEstimator: settings.customFeeEstimator || ''
});
}

render() {
const { navigation, SettingsStore } = this.props;
const { rescan, persistentMode, embeddedTor, compactDb } = this.state;
const {
rescan,
persistentMode,
embeddedTor,
compactDb,
feeEstimator,
customFeeEstimator
} = this.state;
const { updateSettings, embeddedLndNetwork, settings }: any =
SettingsStore;
const { bimodalPathfinding } = settings;
Expand All @@ -82,6 +100,55 @@ export default class EmbeddedNodeAdvancedSettings extends React.Component<
navigation={navigation}
/>
<ScrollView>
<View style={{ margin: 10 }}>
<DropdownSetting
title={localeString(
'views.Settings.EmbeddedNode.feeEstimator'
)}
selectedValue={feeEstimator}
onValueChange={async (value: string) => {
this.setState({
feeEstimator: value
});
await updateSettings({
feeEstimator: value
});
restartNeeded();
}}
values={FEE_ESTIMATOR_KEYS}
/>

{feeEstimator === 'Custom' && (
<>
<Text
style={{
color: themeColor('secondaryText'),
fontFamily: 'PPNeueMontreal-Book'
}}
>
{localeString(
'views.Settings.EmbeddedNode.customFeeEstimator'
)}
</Text>
<TextInput
value={customFeeEstimator}
placeholder={DEFAULT_FEE_ESTIMATOR}
onChangeText={async (text: string) => {
this.setState({
customFeeEstimator: text
});

await updateSettings({
customFeeEstimator: text
});
}}
autoCapitalize="none"
error={!customFeeEstimator}
/>
</>
)}
</View>

<ListItem
containerStyle={{
backgroundColor: 'transparent'
Expand Down

0 comments on commit 5c0389b

Please sign in to comment.