|
1 | | -import { PREFIX_URI, WAIT_DELAY } from '../config'; |
| 1 | +import { PREFIX_URI } from '../config'; |
2 | 2 | import { |
3 | 3 | toSatoshis, |
4 | 4 | toAmount, |
@@ -64,23 +64,20 @@ class PaymentAction { |
64 | 64 |
|
65 | 65 | async decodeInvoice({ invoice }) { |
66 | 66 | try { |
67 | | - const timer = setTimeout(() => this._nav.goWait(), WAIT_DELAY); |
68 | 67 | const { payment, settings } = this._store; |
69 | 68 | const request = await this._grpc.sendCommand('decodePayReq', { |
70 | 69 | pay_req: invoice.replace(PREFIX_URI, ''), |
71 | 70 | }); |
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({ |
73 | 75 | destination: request.destination, |
74 | 76 | satAmt: request.num_satoshis, |
75 | 77 | }); |
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); |
80 | 78 | return true; |
81 | 79 | } catch (err) { |
82 | 80 | log.info(`Decoding payment request failed: ${err.message}`); |
83 | | - this._nav.goPay(); |
84 | 81 | return false; |
85 | 82 | } |
86 | 83 | } |
@@ -125,15 +122,15 @@ class PaymentAction { |
125 | 122 |
|
126 | 123 | async estimateLightningFee({ destination, satAmt }) { |
127 | 124 | try { |
| 125 | + const { payment, settings } = this._store; |
128 | 126 | const { routes } = await this._grpc.sendCommand('queryRoutes', { |
129 | 127 | pub_key: destination, |
130 | 128 | amt: satAmt, |
131 | 129 | num_routes: 1, |
132 | 130 | }); |
133 | | - return routes[0].total_fees; |
| 131 | + payment.fee = toAmount(parseSat(routes[0].total_fees), settings.unit); |
134 | 132 | } catch (err) { |
135 | | - log.info(`Unable to retrieve fee estimate: ${JSON.stringify(err)}`); |
136 | | - return 0; |
| 133 | + log.error(`Estimating lightning fee failed!`, err); |
137 | 134 | } |
138 | 135 | } |
139 | 136 | } |
|
0 commit comments