From 62c7f1a3f17e38f93382396dccc887a18412c026 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Fri, 2 Nov 2018 17:27:38 +0100 Subject: [PATCH] feat(wallet): apply fee limit for offchain txs --- app/components/Pay/Pay.js | 5 ++-- app/lib/lnd/methods/paymentsController.js | 36 +++++++++++++---------- app/reducers/payment.js | 4 +-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/app/components/Pay/Pay.js b/app/components/Pay/Pay.js index e3f84fcc..8fc84d17 100644 --- a/app/components/Pay/Pay.js +++ b/app/components/Pay/Pay.js @@ -187,7 +187,8 @@ class Pay extends React.Component { */ onSubmit = values => { const { currentStep, isOnchain } = this.state - const { cryptoCurrency, onchainFees, payInvoice, sendCoins } = this.props + const { cryptoCurrency, onchainFees, payInvoice, routes, sendCoins } = this.props + const feeLimit = getMaxFee(routes) if (currentStep === 'summary') { return isOnchain ? sendCoins({ @@ -196,7 +197,7 @@ class Pay extends React.Component { currency: cryptoCurrency, satPerByte: onchainFees.fastestFee }) - : payInvoice(values.payReq) + : payInvoice(values.payReq, feeLimit) } else { this.nextStep() } diff --git a/app/lib/lnd/methods/paymentsController.js b/app/lib/lnd/methods/paymentsController.js index f497eb04..52a78f63 100644 --- a/app/lib/lnd/methods/paymentsController.js +++ b/app/lib/lnd/methods/paymentsController.js @@ -4,16 +4,19 @@ * @param {[type]} paymentRequest [description] * @return {[type]} [description] */ -export function sendPaymentSync(lnd, { paymentRequest }) { +export function sendPaymentSync(lnd, { paymentRequest, feeLimit }) { return new Promise((resolve, reject) => { - lnd.sendPaymentSync({ payment_request: paymentRequest }, (error, data) => { - if (error) { - return reject(error) - } else if (!data || !data.payment_route) { - return reject(data.payment_error) + lnd.sendPaymentSync( + { payment_request: paymentRequest, fee_limit: { fixed: feeLimit } }, + (error, data) => { + if (error) { + return reject(error) + } else if (!data || !data.payment_route) { + return reject(data.payment_error) + } + resolve(data) } - resolve(data) - }) + ) }) } @@ -23,15 +26,18 @@ export function sendPaymentSync(lnd, { paymentRequest }) { * @param {[type]} paymentRequest [description] * @return {[type]} [description] */ -export function sendPayment(lnd, { paymentRequest }) { +export function sendPayment(lnd, { paymentRequest, feeLimit }) { return new Promise((resolve, reject) => { - lnd.sendPayment({ payment_request: paymentRequest }, (err, data) => { - if (err) { - return reject(err) - } + lnd.sendPayment( + { payment_request: paymentRequest, fee_limit: { fixed: feeLimit } }, + (err, data) => { + if (err) { + return reject(err) + } - resolve(data) - }) + resolve(data) + } + ) }) } diff --git a/app/reducers/payment.js b/app/reducers/payment.js index 25dc379a..c6744776 100644 --- a/app/reducers/payment.js +++ b/app/reducers/payment.js @@ -119,9 +119,9 @@ export const paymentFailed = (event, { error }) => dispatch => { dispatch(setError(error)) } -export const payInvoice = paymentRequest => (dispatch, getState) => { +export const payInvoice = (paymentRequest, feeLimit) => (dispatch, getState) => { dispatch(sendPayment()) - ipcRenderer.send('lnd', { msg: 'sendPayment', data: { paymentRequest } }) + ipcRenderer.send('lnd', { msg: 'sendPayment', data: { paymentRequest, feeLimit } }) // Set an interval to call tick which will continuously tick down the ticker until the payment goes through or it hits // 0 and throws an error. We also call setPaymentInterval so we are storing the interval. This allows us to clear the