Browse Source

hotfix(fetchBalance): fetch balance after payments/transactions are sent/received

renovate/lint-staged-8.x
Jack Mallers 7 years ago
parent
commit
bbb20214d1
  1. 2
      app/lnd/index.js
  2. 2
      app/lnd/subscribe/index.js
  3. 5
      app/lnd/subscribe/transactions.js
  4. 4
      app/main.dev.js
  5. 4
      app/reducers/balance.js
  6. 4
      app/reducers/invoice.js
  7. 4
      app/reducers/payment.js
  8. 7
      app/reducers/transaction.js
  9. BIN
      resources/bin/darwin/lnd
  10. BIN
      resources/bin/linux/lnd
  11. BIN
      resources/bin/win32/lnd.exe

2
app/lnd/index.js

@ -5,7 +5,7 @@ import methods from './methods'
export default (callback) => {
const lnd = lightning(config.lightningRpc, config.lightningHost)
const lndSubscribe = mainWindow => subscribe(mainWindow, lnd)
const lndMethods = (event, msg, data) => methods(lnd, event, msg, data)

2
app/lnd/subscribe/index.js

@ -2,6 +2,8 @@ import subscribeToTransactions from './transactions'
import subscribeToInvoices from './invoices'
export default (mainWindow, lnd) => {
console.log('mainWindow: ', mainWindow)
console.log('lnd: ', lnd)
subscribeToTransactions(mainWindow, lnd)
subscribeToInvoices(mainWindow, lnd)
}

5
app/lnd/subscribe/transactions.js

@ -3,7 +3,10 @@
export default function subscribeToTransactions(mainWindow, lnd) {
const call = lnd.subscribeTransactions({})
call.on('data', transaction => mainWindow.send('newTransaction', { transaction }))
call.on('data', transaction => {
console.log('TRANSACTION: ', transaction)
mainWindow.send('newTransaction', { transaction })
})
call.on('end', () => console.log('end'))
call.on('error', error => console.log('error: ', error))
call.on('status', status => console.log('status: ', status))

4
app/main.dev.js

@ -117,7 +117,6 @@ app.on('ready', async () => {
// After the certs are generated, it's time to start LND
console.log('STARTING LND')
const lndPath = path.join(__dirname, '..', 'resources', 'bin', plat, plat === 'win32' ? 'lnd.exe' : 'lnd')
neutrino = spawn(lndPath,
[
'--bitcoin.active',
@ -126,7 +125,8 @@ app.on('ready', async () => {
'--neutrino.connect=faucet.lightning.community:18333',
'--autopilot.active',
'--debuglevel=debug',
'--no-macaroons'
'--no-macaroons',
'--noencryptwallet'
]
)
.on('error', error => console.log(`lnd error: ${error}`))

4
app/reducers/balance.js

@ -21,9 +21,9 @@ export const fetchBalance = () => async (dispatch) => {
}
// Receive IPC event for balance
export const receiveBalance = (event, { walletBalance, channelBalance }) => dispatch => (
export const receiveBalance = (event, { walletBalance, channelBalance }) => dispatch => {
dispatch({ type: RECEIVE_BALANCE, walletBalance, channelBalance })
)
}
// ------------------------------------
// Action Handlers

4
app/reducers/invoice.js

@ -1,6 +1,7 @@
import { createSelector } from 'reselect'
import { ipcRenderer } from 'electron'
import { fetchBalance } from './balance'
import { setFormType } from './form'
import { setPayInvoice } from './payform'
import { resetRequestForm } from './requestform'
@ -120,6 +121,9 @@ export const createdInvoice = (event, invoice) => (dispatch) => {
export const invoiceUpdate = (event, { invoice }) => (dispatch) => {
dispatch({ type: UPDATE_INVOICE, invoice })
// Fetch new balance
dispatch(fetchBalance())
// HTML 5 desktop notification for the invoice update
const notifTitle = 'You\'ve been Zapped'
const notifBody = 'Congrats, someone just paid an invoice of yours'

4
app/reducers/payment.js

@ -1,5 +1,6 @@
import { createSelector } from 'reselect'
import { ipcRenderer } from 'electron'
import { fetchBalance } from './balance'
import { setFormType } from './form'
import { resetPayForm } from './payform'
import { showModal } from './modal'
@ -81,6 +82,9 @@ export const paymentSuccessful = () => (dispatch) => {
// Reset the payment form
dispatch(resetPayForm())
// Fetch new balance
dispatch(fetchBalance())
}

7
app/reducers/transaction.js

@ -1,6 +1,7 @@
import { ipcRenderer } from 'electron'
import { showNotification } from '../notifications'
import { btc, usd } from '../utils'
import { fetchBalance } from './balance'
import { setFormType } from './form'
import { resetPayForm } from './payform'
import { showModal } from './modal'
@ -60,6 +61,8 @@ export const transactionSuccessful = (event, { amount, addr, txid }) => (dispatc
// TODO: Add successful on-chain payment to payments list once payments list supports on-chain and LN
// dispatch({ type: PAYMENT_SUCCESSFULL, payment: { amount, addr, txid, pending: true } })
dispatch({ type: TRANSACTION_SUCCESSFULL })
// Fetch new balance
dispatch(fetchBalance())
// Reset the payment form
dispatch(resetPayForm())
}
@ -70,6 +73,10 @@ export const transactionError = () => (dispatch) => {
// Listener for when a new transaction is pushed from the subscriber
export const newTransaction = (event, { transaction }) => (dispatch) => {
console.log('transaction: ', transaction)
// Fetch new balance
dispatch(fetchBalance())
dispatch({ type: ADD_TRANSACTION, transaction })
// HTML 5 desktop notification for the new transaction

BIN
resources/bin/darwin/lnd

Binary file not shown.

BIN
resources/bin/linux/lnd

Binary file not shown.

BIN
resources/bin/win32/lnd.exe

Binary file not shown.
Loading…
Cancel
Save