@@ -7,9 +7,18 @@ 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' ;
12- import { toSatoshis , toAmount , isLnUri , isAddress , nap } from '../helper' ;
14+ import {
15+ toSatoshis ,
16+ toAmount ,
17+ toAmountLabel ,
18+ isLnUri ,
19+ isAddress ,
20+ nap ,
21+ } from '../helper' ;
1322import * as log from './log' ;
1423
1524class PaymentAction {
@@ -105,6 +114,7 @@ class PaymentAction {
105114 init ( ) {
106115 this . _store . payment . address = '' ;
107116 this . _store . payment . amount = '' ;
117+ this . _store . payment . targetConf = MED_TARGET_CONF ;
108118 this . _store . payment . fee = '' ;
109119 this . _store . payment . note = '' ;
110120 this . _store . payment . useScanner = false ;
@@ -223,14 +233,40 @@ class PaymentAction {
223233 * @return {Promise<undefined> }
224234 */
225235 async estimateFee ( ) {
236+ const { payment } = this . _store ;
237+ payment . feeEstimates = [ ] ;
238+ await this . _fetchEstimate ( LOW_TARGET_CONF , 'Low' ) ;
239+ await this . _fetchEstimate ( MED_TARGET_CONF , 'Med' ) ;
240+ await this . _fetchEstimate ( HIGH_TARGET_CONF , 'High' ) ;
241+ payment . fee = payment . feeEstimates [ 1 ] . fee ;
242+ }
243+
244+ async _fetchEstimate ( targetConf , prio ) {
226245 const { payment, settings } = this . _store ;
227246 const AddrToAmount = { } ;
228247 AddrToAmount [ payment . address ] = toSatoshis ( payment . amount , settings ) ;
229- const { feeSat } = await this . _grpc . sendCommand ( 'estimateFee' , {
230- AddrToAmount,
231- targetConf : SEND_TARGET_CONF ,
248+ const { feeSat, feerateSatPerByte } = await this . _grpc . sendCommand (
249+ 'estimateFee' ,
250+ {
251+ AddrToAmount,
252+ targetConf,
253+ }
254+ ) ;
255+ payment . feeEstimates . push ( {
256+ targetConf,
257+ prio,
258+ satPerByte : feerateSatPerByte ,
259+ fee : toAmount ( feeSat , settings ) ,
260+ feeLabel : toAmountLabel ( feeSat , settings ) ,
232261 } ) ;
233- payment . fee = toAmount ( feeSat , settings ) ;
262+ }
263+
264+ setTargetConf ( { targetConf } ) {
265+ const { payment } = this . _store ;
266+ payment . targetConf = targetConf ;
267+ payment . fee = payment . feeEstimates . find (
268+ e => e . targetConf === targetConf
269+ ) . fee ;
234270 }
235271
236272 /**
@@ -286,7 +322,7 @@ class PaymentAction {
286322 await this . _grpc . sendCommand ( 'sendCoins' , {
287323 addr : payment . address ,
288324 amount,
289- targetConf : SEND_TARGET_CONF ,
325+ targetConf : payment . targetConf ,
290326 sendAll : payment . sendAll ,
291327 } ) ;
292328 }
0 commit comments