|
7 | 7 | PREFIX_REGEX, |
8 | 8 | PAYMENT_TIMEOUT, |
9 | 9 | POLL_STORE_TIMEOUT, |
10 | | - SEND_TARGET_CONF, |
| 10 | + LOW_TARGET_CONF, |
| 11 | + MED_TARGET_CONF, |
| 12 | + HIGH_TARGET_CONF, |
11 | 13 | } from '../config'; |
12 | 14 | import { toSatoshis, toAmount, isLnUri, isAddress, nap } from '../helper'; |
13 | 15 | import * as log from './log'; |
@@ -105,6 +107,7 @@ class PaymentAction { |
105 | 107 | init() { |
106 | 108 | this._store.payment.address = ''; |
107 | 109 | this._store.payment.amount = ''; |
| 110 | + this._store.payment.targetConf = MED_TARGET_CONF; |
108 | 111 | this._store.payment.fee = ''; |
109 | 112 | this._store.payment.note = ''; |
110 | 113 | this._store.payment.useScanner = false; |
@@ -223,14 +226,40 @@ class PaymentAction { |
223 | 226 | * @return {Promise<undefined>} |
224 | 227 | */ |
225 | 228 | 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) { |
226 | 238 | const { payment, settings } = this._store; |
227 | 239 | const AddrToAmount = {}; |
228 | 240 | AddrToAmount[payment.address] = toSatoshis(payment.amount, settings); |
229 | 241 | const { feeSat } = await this._grpc.sendCommand('estimateFee', { |
230 | 242 | AddrToAmount, |
231 | | - targetConf: SEND_TARGET_CONF, |
| 243 | + targetConf, |
232 | 244 | }); |
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; |
234 | 263 | } |
235 | 264 |
|
236 | 265 | /** |
@@ -286,7 +315,7 @@ class PaymentAction { |
286 | 315 | await this._grpc.sendCommand('sendCoins', { |
287 | 316 | addr: payment.address, |
288 | 317 | amount, |
289 | | - targetConf: SEND_TARGET_CONF, |
| 318 | + targetConf: payment.targetConf, |
290 | 319 | sendAll: payment.sendAll, |
291 | 320 | }); |
292 | 321 | } |
|
0 commit comments