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

Commit 969c4b8

Browse files
committed
Asynchronously estimate fee
1 parent 28c2a7c commit 969c4b8

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/action/payment.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PREFIX_URI, WAIT_DELAY } from '../config';
1+
import { PREFIX_URI } from '../config';
22
import {
33
toSatoshis,
44
toAmount,
@@ -64,23 +64,20 @@ class PaymentAction {
6464

6565
async decodeInvoice({ invoice }) {
6666
try {
67-
const timer = setTimeout(() => this._nav.goWait(), WAIT_DELAY);
6867
const { payment, settings } = this._store;
6968
const request = await this._grpc.sendCommand('decodePayReq', {
7069
pay_req: invoice.replace(PREFIX_URI, ''),
7170
});
72-
const fee = await this.estimateLightningFee({
71+
payment.amount = toAmount(parseSat(request.num_satoshis), settings.unit);
72+
payment.note = request.description;
73+
// asynchronously estimate fee to not block the UI
74+
this.estimateLightningFee({
7375
destination: request.destination,
7476
satAmt: request.num_satoshis,
7577
});
76-
payment.amount = toAmount(parseSat(request.num_satoshis), settings.unit);
77-
payment.note = request.description;
78-
payment.fee = toAmount(parseSat(fee), settings.unit);
79-
clearTimeout(timer);
8078
return true;
8179
} catch (err) {
8280
log.info(`Decoding payment request failed: ${err.message}`);
83-
this._nav.goPay();
8481
return false;
8582
}
8683
}
@@ -125,15 +122,15 @@ class PaymentAction {
125122

126123
async estimateLightningFee({ destination, satAmt }) {
127124
try {
125+
const { payment, settings } = this._store;
128126
const { routes } = await this._grpc.sendCommand('queryRoutes', {
129127
pub_key: destination,
130128
amt: satAmt,
131129
num_routes: 1,
132130
});
133-
return routes[0].total_fees;
131+
payment.fee = toAmount(parseSat(routes[0].total_fees), settings.unit);
134132
} catch (err) {
135-
log.info(`Unable to retrieve fee estimate: ${JSON.stringify(err)}`);
136-
return 0;
133+
log.error(`Estimating lightning fee failed!`, err);
137134
}
138135
}
139136
}

src/config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports.RETRY_DELAY = 3000;
22
module.exports.LND_INIT_DELAY = 5000;
33
module.exports.NOTIFICATION_DELAY = 5000;
4-
module.exports.WAIT_DELAY = 500;
54

65
module.exports.LND_PORT = 10009;
76
module.exports.LND_PEER_PORT = 10019;

0 commit comments

Comments
 (0)