Implement fee selection in payment action

parent 967e6cb9
......@@ -7,9 +7,18 @@ import {
PREFIX_REGEX,
PAYMENT_TIMEOUT,
POLL_STORE_TIMEOUT,
SEND_TARGET_CONF,
LOW_TARGET_CONF,
MED_TARGET_CONF,
HIGH_TARGET_CONF,
} from '../config';
import { toSatoshis, toAmount, isLnUri, isAddress, nap } from '../helper';
import {
toSatoshis,
toAmount,
toAmountLabel,
isLnUri,
isAddress,
nap,
} from '../helper';
import * as log from './log';
class PaymentAction {
......@@ -105,6 +114,7 @@ class PaymentAction {
init() {
this._store.payment.address = '';
this._store.payment.amount = '';
this._store.payment.targetConf = MED_TARGET_CONF;
this._store.payment.fee = '';
this._store.payment.note = '';
this._store.payment.useScanner = false;
......@@ -223,14 +233,40 @@ class PaymentAction {
* @return {Promise<undefined>}
*/
async estimateFee() {
const { payment } = this._store;
payment.feeEstimates = [];
await this._fetchEstimate(LOW_TARGET_CONF, 'Low');
await this._fetchEstimate(MED_TARGET_CONF, 'Med');
await this._fetchEstimate(HIGH_TARGET_CONF, 'High');
payment.fee = payment.feeEstimates[1].fee;
}
async _fetchEstimate(targetConf, prio) {
const { payment, settings } = this._store;
const AddrToAmount = {};
AddrToAmount[payment.address] = toSatoshis(payment.amount, settings);
const { feeSat } = await this._grpc.sendCommand('estimateFee', {
AddrToAmount,
targetConf: SEND_TARGET_CONF,
const { feeSat, feerateSatPerByte } = await this._grpc.sendCommand(
'estimateFee',
{
AddrToAmount,
targetConf,
}
);
payment.feeEstimates.push({
targetConf,
prio,
satPerByte: feerateSatPerByte,
fee: toAmount(feeSat, settings),
feeLabel: toAmountLabel(feeSat, settings),
});
payment.fee = toAmount(feeSat, settings);
}
setTargetConf({ targetConf }) {
const { payment } = this._store;
payment.targetConf = targetConf;
payment.fee = payment.feeEstimates.find(
e => e.targetConf === targetConf
).fee;
}
/**
......@@ -286,7 +322,7 @@ class PaymentAction {
await this._grpc.sendCommand('sendCoins', {
addr: payment.address,
amount,
targetConf: SEND_TARGET_CONF,
targetConf: payment.targetConf,
sendAll: payment.sendAll,
});
}
......
......@@ -24,7 +24,9 @@ module.exports.PREFIX_URI = `${prefixName}:`;
module.exports.PREFIX_REGEX = /^[a-zA-Z]*:/;
module.exports.DEFAULT_ROUTE = 'Welcome';
module.exports.SEND_TARGET_CONF = 6;
module.exports.LOW_TARGET_CONF = 26;
module.exports.MED_TARGET_CONF = 16;
module.exports.HIGH_TARGET_CONF = 4;
module.exports.PIN_LENGTH = 6;
module.exports.MIN_PASSWORD_LENGTH = 8;
module.exports.STRONG_PASSWORD_LENGTH = 12;
......
......@@ -14,7 +14,12 @@ import ComputedPayment from './computed/payment';
import ComputedNotification from './computed/notification';
import ComputedSetting from './computed/setting';
import ComputedSeed from './computed/seed';
import { DEFAULT_ROUTE, DEFAULT_UNIT, DEFAULT_FIAT } from './config';
import {
DEFAULT_ROUTE,
DEFAULT_UNIT,
DEFAULT_FIAT,
MED_TARGET_CONF,
} from './config';
export class Store {
constructor() {
......@@ -69,6 +74,8 @@ export class Store {
payment: {
address: '',
amount: '',
targetConf: MED_TARGET_CONF,
feeEstimates: [],
fee: '',
note: '',
sendAll: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment