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

2
app/components/Pay/PaySummaryOnChain.js

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

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

@ -74,9 +74,9 @@ export function getTransactions(lnd) {
* @param {[type]} amount [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) => {
lnd.sendCoins({ addr, amount }, (err, data) => {
lnd.sendCoins({ addr, amount, target_conf, sat_per_byte }, (err, data) => {
if (err) {
return reject(err)
}

7
app/reducers/transaction.js

@ -86,13 +86,16 @@ export const receiveTransactions = (event, { transactions }) => (dispatch, getSt
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
const amount = btc.convert(currency, 'sats', value)
// submit the transaction to LND
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
// we will do the loading/success UX on the main page

Loading…
Cancel
Save