Browse Source

feat(wallet): apply fee limit for offchain txs

renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
62c7f1a3f1
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 5
      app/components/Pay/Pay.js
  2. 18
      app/lib/lnd/methods/paymentsController.js
  3. 4
      app/reducers/payment.js

5
app/components/Pay/Pay.js

@ -187,7 +187,8 @@ class Pay extends React.Component {
*/ */
onSubmit = values => { onSubmit = values => {
const { currentStep, isOnchain } = this.state 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') { if (currentStep === 'summary') {
return isOnchain return isOnchain
? sendCoins({ ? sendCoins({
@ -196,7 +197,7 @@ class Pay extends React.Component {
currency: cryptoCurrency, currency: cryptoCurrency,
satPerByte: onchainFees.fastestFee satPerByte: onchainFees.fastestFee
}) })
: payInvoice(values.payReq) : payInvoice(values.payReq, feeLimit)
} else { } else {
this.nextStep() this.nextStep()
} }

18
app/lib/lnd/methods/paymentsController.js

@ -4,16 +4,19 @@
* @param {[type]} paymentRequest [description] * @param {[type]} paymentRequest [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function sendPaymentSync(lnd, { paymentRequest }) { export function sendPaymentSync(lnd, { paymentRequest, feeLimit }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.sendPaymentSync({ payment_request: paymentRequest }, (error, data) => { lnd.sendPaymentSync(
{ payment_request: paymentRequest, fee_limit: { fixed: feeLimit } },
(error, data) => {
if (error) { if (error) {
return reject(error) return reject(error)
} else if (!data || !data.payment_route) { } else if (!data || !data.payment_route) {
return reject(data.payment_error) return reject(data.payment_error)
} }
resolve(data) resolve(data)
}) }
)
}) })
} }
@ -23,15 +26,18 @@ export function sendPaymentSync(lnd, { paymentRequest }) {
* @param {[type]} paymentRequest [description] * @param {[type]} paymentRequest [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function sendPayment(lnd, { paymentRequest }) { export function sendPayment(lnd, { paymentRequest, feeLimit }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.sendPayment({ payment_request: paymentRequest }, (err, data) => { lnd.sendPayment(
{ payment_request: paymentRequest, fee_limit: { fixed: feeLimit } },
(err, data) => {
if (err) { if (err) {
return reject(err) return reject(err)
} }
resolve(data) resolve(data)
}) }
)
}) })
} }

4
app/reducers/payment.js

@ -119,9 +119,9 @@ export const paymentFailed = (event, { error }) => dispatch => {
dispatch(setError(error)) dispatch(setError(error))
} }
export const payInvoice = paymentRequest => (dispatch, getState) => { export const payInvoice = (paymentRequest, feeLimit) => (dispatch, getState) => {
dispatch(sendPayment()) 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 // 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 // 0 and throws an error. We also call setPaymentInterval so we are storing the interval. This allows us to clear the

Loading…
Cancel
Save