Browse Source

feat(wallet): apply fastest fee for onchain txs

renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
210ceae251
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 6
      app/components/Pay/Pay.js
  2. 2
      app/components/Pay/PaySummaryOnChain.js
  3. 4
      app/lib/lnd/methods/walletController.js
  4. 7
      app/reducers/transaction.js

6
app/components/Pay/Pay.js

@ -131,6 +131,7 @@ class Pay extends React.Component {
isQueryingFees: false, isQueryingFees: false,
isQueryingRoutes: false, isQueryingRoutes: false,
nodes: [], nodes: [],
onchainFees: {},
routes: [] routes: []
} }
@ -186,13 +187,14 @@ class Pay extends React.Component {
*/ */
onSubmit = values => { onSubmit = values => {
const { currentStep, isOnchain } = this.state const { currentStep, isOnchain } = this.state
const { cryptoCurrency, payInvoice, sendCoins } = this.props const { cryptoCurrency, onchainFees, payInvoice, sendCoins } = this.props
if (currentStep === 'summary') { if (currentStep === 'summary') {
return isOnchain return isOnchain
? sendCoins({ ? sendCoins({
value: values.amountCrypto, value: values.amountCrypto,
addr: values.payReq, addr: values.payReq,
currency: cryptoCurrency currency: cryptoCurrency,
satPerByte: onchainFees.fastestFee
}) })
: payInvoice(values.payReq) : payInvoice(values.payReq)
} else { } else {

2
app/components/Pay/PaySummaryOnChain.js

@ -51,7 +51,7 @@ class PaySummaryOnChain extends React.Component {
onchainFees: {} onchainFees: {}
} }
componenDidMount() { componentDidMount() {
const { queryFees } = this.props const { queryFees } = this.props
queryFees() queryFees()
} }

4
app/lib/lnd/methods/walletController.js

@ -74,9 +74,9 @@ export function getTransactions(lnd) {
* @param {[type]} amount [description] * @param {[type]} amount [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
export function sendCoins(lnd, { addr, amount }) { export function sendCoins(lnd, { addr, amount, target_conf, sat_per_byte }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
lnd.sendCoins({ addr, amount }, (err, data) => { lnd.sendCoins({ addr, amount, target_conf, sat_per_byte }, (err, data) => {
if (err) { if (err) {
return reject(err) return reject(err)
} }

7
app/reducers/transaction.js

@ -86,13 +86,16 @@ export const receiveTransactions = (event, { transactions }) => (dispatch, getSt
dispatch(fetchBalance()) dispatch(fetchBalance())
} }
export const sendCoins = ({ value, addr, currency }) => dispatch => { export const sendCoins = ({ value, addr, currency, targetConf, satPerByte }) => dispatch => {
// backend needs amount in satoshis no matter what currency we are using // backend needs amount in satoshis no matter what currency we are using
const amount = btc.convert(currency, 'sats', value) const amount = btc.convert(currency, 'sats', value)
// submit the transaction to LND // submit the transaction to LND
dispatch(sendTransaction()) dispatch(sendTransaction())
ipcRenderer.send('lnd', { msg: 'sendCoins', data: { amount, addr } }) ipcRenderer.send('lnd', {
msg: 'sendCoins',
data: { amount, addr, currency, target_conf: targetConf, sat_per_byte: satPerByte }
})
// Close the form modal once the payment was sent to LND // Close the form modal once the payment was sent to LND
// we will do the loading/success UX on the main page // we will do the loading/success UX on the main page

Loading…
Cancel
Save