Skip to content

Commit

Permalink
Payment settings: add preferred Mempool rate
Browse files Browse the repository at this point in the history
  • Loading branch information
kaloudis committed Sep 4, 2023
1 parent 7a8f560 commit eaef20d
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 14 deletions.
10 changes: 8 additions & 2 deletions components/DropdownSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ interface DropdownSettingProps {
selectedValue: string | boolean;
onValueChange: (value: any) => void;
values: Array<any>;
disabled?: boolean;
}

export default class DropdownSetting extends React.Component<
DropdownSettingProps,
{}
> {
render() {
const { title, selectedValue, onValueChange, values } = this.props;
const { title, selectedValue, onValueChange, values, disabled } =
this.props;

const pickerValuesAndroid: Array<any> = [];
const pickerValuesIOS: Array<string> = ['Cancel'];
Expand Down Expand Up @@ -70,9 +72,11 @@ export default class DropdownSetting extends React.Component<
style={{
color: themeColor('text'),
backgroundColor: themeColor('secondary'),
...styles.field
...styles.field,
opacity: disabled ? 0.25 : 1
}}
dropdownIconColor={themeColor('text')}
enabled={!disabled}
>
{pickerValuesAndroid}
</Picker>
Expand All @@ -91,6 +95,7 @@ export default class DropdownSetting extends React.Component<
</Text>
<TouchableOpacity
onPress={() =>
!disabled &&
ActionSheetIOS.showActionSheetWithOptions(
{
options: pickerValuesIOS,
Expand All @@ -105,6 +110,7 @@ export default class DropdownSetting extends React.Component<
}
)
}
style={{ opacity: disabled ? 0.25 : 1 }}
>
<Text
style={{
Expand Down
5 changes: 3 additions & 2 deletions components/OnchainFeeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default function OnchainFeeInput(props: OnchainFeeInputProps) {
const { settingsStore, feeStore } = stores;
const { settings } = settingsStore;
const enableMempoolRates = settings?.privacy?.enableMempoolRates;
const preferredMempoolRate =
settings?.payments?.preferredMempoolRate || 'fastestFee';

const [newFee, setNewFee] = useState(fee);
const [loading, setLoading] = useState(false);
Expand All @@ -30,8 +32,7 @@ export default function OnchainFeeInput(props: OnchainFeeInputProps) {
feeStore
.getOnchainFeesviaMempool()
.then((recommendedFees) => {
console.log('recommendedFees', recommendedFees);
setNewFee(recommendedFees.fastestFee);
setNewFee(recommendedFees[preferredMempoolRate]);
setLoading(false);
})
.catch(() => {
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@
"views.Settings.Privacy.title": "Privacy settings",
"views.Settings.Payments.title": "Payments settings",
"views.Settings.Payments.defaultFeeLimit": "Default Fee Limit",
"views.Settings.Payments.preferredMempoolRate": "Preferred Mempool Rate",
"views.Settings.Invoices.title": "Invoices settings",
"views.Settings.Privacy.blockExplorer": "Default Block explorer",
"views.Settings.Privacy.BlockExplorer.custom": "Custom",
Expand Down
2 changes: 1 addition & 1 deletion stores/FeeStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class FeeStore {
return ReactNativeBlobUtil.fetch(
'get',
`https://mempool.space/${
this.nodeInfoStore.nodeInfo.isTestNet ? 'testnet/' : ''
this.nodeInfoStore.nodeInfo.isTestNet && false ? 'testnet/' : ''
}api/v1/fees/recommended`
)
.then((response: any) => {
Expand Down
27 changes: 26 additions & 1 deletion stores/SettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface PaymentsSettings {
defaultFeeMethod?: string;
defaultFeePercentage?: string;
defaultFeeFixed?: string;
preferredMempoolRate?: string;
}

interface InvoicesSettings {
Expand Down Expand Up @@ -118,6 +119,29 @@ export const BLOCK_EXPLORER_KEYS = [
}
];

export const MEMPOOL_RATES_KEYS = [
{
key: 'Fastest fee',
value: 'fastestFee',
translateKey: 'views.EditFee.fastestFee'
},
{
key: 'Half hour fee',
value: 'halfHourFee',
translateKey: 'views.EditFee.halfHourFee'
},
{
key: 'Hour fee',
value: 'hourFee',
translateKey: 'views.EditFee.hourFee'
},
{
key: 'Minimum fee',
value: 'minimumFee',
translateKey: 'views.EditFee.minimumFee'
}
];

export const INTERFACE_KEYS = [
{ key: 'Embedded LND', value: 'embedded-lnd' },
{ key: 'LND (REST)', value: 'lnd' },
Expand Down Expand Up @@ -653,7 +677,8 @@ export default class SettingsStore {
payments: {
defaultFeeMethod: 'fixed',
defaultFeePercentage: '0.5',
defaultFeeFixed: '100'
defaultFeeFixed: '100',
preferredMempoolRate: 'fastestFee'
},
invoices: {
addressType: '0',
Expand Down
106 changes: 98 additions & 8 deletions views/Settings/PaymentsSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import * as React from 'react';
import { Text, View } from 'react-native';
import { ListItem } from 'react-native-elements';
import { inject, observer } from 'mobx-react';

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

import SettingsStore from '../../stores/SettingsStore';
import SettingsStore, { MEMPOOL_RATES_KEYS } from '../../stores/SettingsStore';

import { localeString } from '../../utils/LocaleUtils';
import { themeColor } from '../../utils/ThemeUtils';
Expand All @@ -21,6 +24,8 @@ interface PaymentsSettingsState {
feeLimitMethod: string;
feeLimit: string;
feePercentage: string;
enableMempoolRates: boolean;
preferredMempoolRate: string;
}

@inject('SettingsStore')
Expand All @@ -32,7 +37,9 @@ export default class PaymentsSettings extends React.Component<
state = {
feeLimitMethod: 'fixed',
feeLimit: '100',
feePercentage: '0.5'
feePercentage: '0.5',
enableMempoolRates: false,
preferredMempoolRate: 'fastestFee'
};

async UNSAFE_componentWillMount() {
Expand All @@ -43,7 +50,10 @@ export default class PaymentsSettings extends React.Component<
this.setState({
feeLimitMethod: settings?.payments?.defaultFeeMethod || 'fixed',
feeLimit: settings?.payments?.defaultFeeFixed || '100',
feePercentage: settings?.payments?.defaultFeePercentage || '0.5'
feePercentage: settings?.payments?.defaultFeePercentage || '0.5',
enableMempoolRates: settings?.privacy?.enableMempoolRates || false,
preferredMempoolRate:
settings?.payments?.preferredMempoolRate || 'fastestFee'
});
}

Expand All @@ -58,9 +68,15 @@ export default class PaymentsSettings extends React.Component<

render() {
const { navigation } = this.props;
const { feeLimit, feeLimitMethod, feePercentage } = this.state;
const {
feeLimit,
feeLimitMethod,
feePercentage,
enableMempoolRates,
preferredMempoolRate
} = this.state;
const { SettingsStore } = this.props;
const { updateSettings } = SettingsStore;
const { updateSettings, settings } = SettingsStore;

return (
<Screen>
Expand All @@ -77,7 +93,8 @@ export default class PaymentsSettings extends React.Component<
/>
<View
style={{
padding: 20
paddingLeft: 15,
paddingRight: 15
}}
>
<Text
Expand Down Expand Up @@ -121,7 +138,8 @@ export default class PaymentsSettings extends React.Component<
payments: {
defaultFeeMethod: 'fixed',
defaultFeePercentage: feePercentage,
defaultFeeFixed: text
defaultFeeFixed: text,
preferredMempoolRate
}
});
}}
Expand Down Expand Up @@ -158,7 +176,8 @@ export default class PaymentsSettings extends React.Component<
payments: {
defaultFeeMethod: 'percent',
defaultFeePercentage: text,
defaultFeeFixed: feeLimit
defaultFeeFixed: feeLimit,
preferredMempoolRate
}
});
}}
Expand All @@ -181,6 +200,77 @@ export default class PaymentsSettings extends React.Component<
{'%'}
</Text>
</View>
<ListItem
containerStyle={{
borderBottomWidth: 0,
backgroundColor: 'transparent'
}}
>
<ListItem.Title
style={{
color: themeColor('secondaryText'),
fontFamily: 'Lato-Regular',
left: -10
}}
>
{localeString(
'views.Settings.Privacy.enableMempoolRates'
)}
</ListItem.Title>
<View
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end'
}}
>
<Switch
value={enableMempoolRates}
onValueChange={async () => {
this.setState({
enableMempoolRates: !enableMempoolRates
});
await updateSettings({
privacy: {
defaultBlockExplorer:
settings?.privacy
?.defaultBlockExplorer,
customBlockExplorer:
settings?.privacy
?.customBlockExplorer,
clipboard:
settings?.privacy?.clipboard,
lurkerMode:
settings?.privacy?.lurkerMode,
enableMempoolRates:
!enableMempoolRates
}
});
}}
/>
</View>
</ListItem>
<DropdownSetting
title={localeString(
'views.Settings.Payments.preferredMempoolRate'
)}
selectedValue={preferredMempoolRate}
onValueChange={async (value: string) => {
this.setState({
preferredMempoolRate: value
});
await updateSettings({
payments: {
defaultFeeMethod: feeLimitMethod,
defaultFeePercentage: feePercentage,
defaultFeeFixed: feeLimit,
preferredMempoolRate: value
}
});
}}
values={MEMPOOL_RATES_KEYS}
disabled={!enableMempoolRates}
/>
</View>
</Screen>
);
Expand Down

0 comments on commit eaef20d

Please sign in to comment.