Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit f95256a

Browse files
authored
Merge pull request #1304 from lightninglabs/dev/send-coin-fee-selection
Dev/send coin fee selection
2 parents 6f89cac + 26de7af commit f95256a

File tree

15 files changed

+209
-19
lines changed

15 files changed

+209
-19
lines changed

mobile/android/app/src/main/assets/lnd.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ neutrino.feeurl=https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json
2020
autopilot.active=0
2121
autopilot.private=1
2222
autopilot.minconfs=1
23-
autopilot.conftarget=6
23+
autopilot.conftarget=16
2424
autopilot.allocation=1.0
2525
autopilot.heuristic=externalscore:0.95
2626
autopilot.heuristic=preferential:0.05

mobile/ios/lightning/lnd.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ neutrino.feeurl=https://nodes.lightning.computer/fees/v1/btc-fee-estimates.json
2020
autopilot.active=0
2121
autopilot.private=1
2222
autopilot.minconfs=1
23-
autopilot.conftarget=6
23+
autopilot.conftarget=16
2424
autopilot.allocation=1.0
2525
autopilot.heuristic=externalscore:0.95
2626
autopilot.heuristic=preferential:0.05

mobile/package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mobile/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"react-native-gesture-handler": "^1.3.0",
2626
"react-native-icloudstore": "^0.9.0",
2727
"react-native-keychain": "^3.1.3",
28+
"react-native-picker-select": "^6.3.2",
2829
"react-native-share": "^1.2.1",
2930
"react-native-svg": "^9.6.2",
3031
"react-native-unimodules": "^0.5.4",

mobile/rn-cli.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ module.exports = {
5252
__dirname,
5353
'node_modules/react-native-device-info'
5454
),
55+
'react-native-picker-select': path.resolve(
56+
__dirname,
57+
'node_modules/react-native-picker-select'
58+
),
5559
mobx: path.resolve(__dirname, 'node_modules/mobx'),
5660
'mobx-react': path.resolve(__dirname, 'node_modules/mobx-react'),
5761
'locale-currency': path.resolve(

public/lnd-child-process.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module.exports.startLndProcess = async function({
6666
'--historicalsyncinterval=20m',
6767
'--autopilot.private',
6868
'--autopilot.minconfs=1',
69-
'--autopilot.conftarget=6',
69+
'--autopilot.conftarget=16',
7070
'--autopilot.allocation=1.0',
7171
'--autopilot.heuristic=externalscore:0.95',
7272
'--autopilot.heuristic=preferential:0.05',

src/action/payment.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import {
77
PREFIX_REGEX,
88
PAYMENT_TIMEOUT,
99
POLL_STORE_TIMEOUT,
10-
SEND_TARGET_CONF,
10+
LOW_TARGET_CONF,
11+
MED_TARGET_CONF,
12+
HIGH_TARGET_CONF,
1113
} from '../config';
1214
import { toSatoshis, toAmount, isLnUri, isAddress, nap } from '../helper';
1315
import * as log from './log';
@@ -105,6 +107,7 @@ class PaymentAction {
105107
init() {
106108
this._store.payment.address = '';
107109
this._store.payment.amount = '';
110+
this._store.payment.targetConf = MED_TARGET_CONF;
108111
this._store.payment.fee = '';
109112
this._store.payment.note = '';
110113
this._store.payment.useScanner = false;
@@ -223,14 +226,40 @@ class PaymentAction {
223226
* @return {Promise<undefined>}
224227
*/
225228
async estimateFee() {
229+
const { payment } = this._store;
230+
payment.feeEstimates = [];
231+
await this._fetchEstimate(LOW_TARGET_CONF, 'Low');
232+
await this._fetchEstimate(MED_TARGET_CONF, 'Med');
233+
await this._fetchEstimate(HIGH_TARGET_CONF, 'High');
234+
payment.fee = payment.feeEstimates[1].fee;
235+
}
236+
237+
async _fetchEstimate(targetConf, prio) {
226238
const { payment, settings } = this._store;
227239
const AddrToAmount = {};
228240
AddrToAmount[payment.address] = toSatoshis(payment.amount, settings);
229241
const { feeSat } = await this._grpc.sendCommand('estimateFee', {
230242
AddrToAmount,
231-
targetConf: SEND_TARGET_CONF,
243+
targetConf,
232244
});
233-
payment.fee = toAmount(feeSat, settings);
245+
payment.feeEstimates.push({
246+
fee: toAmount(feeSat, settings),
247+
targetConf,
248+
prio,
249+
});
250+
}
251+
252+
/**
253+
* Set the target_conf for the on-chain send operation and set a fee.
254+
* @param {number} options.targetConf The number blocks to target
255+
*/
256+
setTargetConf({ targetConf }) {
257+
const { payment } = this._store;
258+
payment.targetConf = targetConf;
259+
if (!payment.feeEstimates.length) return;
260+
payment.fee = payment.feeEstimates.find(
261+
e => e.targetConf === targetConf
262+
).fee;
234263
}
235264

236265
/**
@@ -286,7 +315,7 @@ class PaymentAction {
286315
await this._grpc.sendCommand('sendCoins', {
287316
addr: payment.address,
288317
amount,
289-
targetConf: SEND_TARGET_CONF,
318+
targetConf: payment.targetConf,
290319
sendAll: payment.sendAll,
291320
});
292321
}

src/component/field-mobile.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import React from 'react';
2+
import { StyleSheet, View, ViewPropTypes } from 'react-native';
3+
import RNPickerSelect from 'react-native-picker-select';
4+
import PropTypes from 'prop-types';
5+
import Text from './text';
6+
import ArrowDownIcon from '../asset/icon/arrow-down';
7+
import { color, font } from './style';
8+
9+
//
10+
// Named Field Select
11+
//
12+
13+
const namedSelectStyles = StyleSheet.create({
14+
content: {
15+
alignSelf: 'stretch',
16+
flexDirection: 'row',
17+
justifyContent: 'space-between',
18+
borderBottomColor: color.blackText,
19+
borderBottomWidth: 1,
20+
},
21+
name: {
22+
color: color.blackText,
23+
fontSize: font.sizeM,
24+
lineHeight: font.lineHeightM + 2 * 12,
25+
marginRight: 15,
26+
},
27+
wrapper: {
28+
flexDirection: 'row',
29+
alignItems: 'center',
30+
},
31+
});
32+
33+
const baseInputStyles = {
34+
fontFamily: 'OpenSans Regular',
35+
fontSize: font.sizeM,
36+
lineHeight: font.lineHeightM + 3,
37+
height: font.lineHeightM + 2 * 12,
38+
color: color.blackText,
39+
padding: 0,
40+
};
41+
42+
const pickerStyles = StyleSheet.create({
43+
inputIOS: {
44+
...baseInputStyles,
45+
opacity: 0.75,
46+
},
47+
inputAndroid: {
48+
...baseInputStyles,
49+
opacity: 0.5,
50+
},
51+
});
52+
53+
export const NamedFieldSelect = ({ name, style, ...props }) => (
54+
<View style={[namedSelectStyles.content, style]}>
55+
<Text style={namedSelectStyles.name}>{name}</Text>
56+
<View style={namedSelectStyles.wrapper}>
57+
<RNPickerSelect
58+
placeholder={{}}
59+
style={pickerStyles}
60+
useNativeAndroidPickerStyle={false}
61+
{...props}
62+
/>
63+
<ArrowDownIcon height={22} width={22} stroke="#969596" />
64+
</View>
65+
</View>
66+
);
67+
68+
NamedFieldSelect.propTypes = {
69+
name: PropTypes.string,
70+
style: ViewPropTypes.style,
71+
};

src/computed/payment.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ const ComputedPayment = store => {
1010
get paymentAmountLabel() {
1111
return toLabel(store.payment.amount, store.settings);
1212
},
13+
get paymentFeeEstimateItems() {
14+
return store.payment.feeEstimates.map(e => {
15+
const feeLabel = toLabel(e.fee, store.settings);
16+
return {
17+
label: `${e.prio} ${feeLabel} ${store.unitLabel || ''}`.trim(),
18+
value: e.targetConf,
19+
};
20+
});
21+
},
1322
get paymentFeeLabel() {
1423
return toLabel(store.payment.fee, store.settings);
1524
},

src/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ module.exports.PREFIX_URI = `${prefixName}:`;
2424
module.exports.PREFIX_REGEX = /^[a-zA-Z]*:/;
2525

2626
module.exports.DEFAULT_ROUTE = 'Welcome';
27-
module.exports.SEND_TARGET_CONF = 6;
27+
module.exports.LOW_TARGET_CONF = 26;
28+
module.exports.MED_TARGET_CONF = 16;
29+
module.exports.HIGH_TARGET_CONF = 4;
2830
module.exports.PIN_LENGTH = 6;
2931
module.exports.MIN_PASSWORD_LENGTH = 8;
3032
module.exports.STRONG_PASSWORD_LENGTH = 12;

0 commit comments

Comments
 (0)