Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix(wallet): add all new invoices to invoice list
Browse files Browse the repository at this point in the history
Add invoices that are created/paid in the background to the activity
list.

Previously, only invoices created without Zap would be visible within
Zap without doing a manual refresh on the activity list.

Fix #912
  • Loading branch information
mrfelton committed Nov 27, 2018
1 parent 706b314 commit a24d459
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions app/reducers/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export const fetchInvoices = () => dispatch => {

// Receive IPC event for invoices
export const receiveInvoices = (event, { invoices }) => dispatch => {
dispatch({ type: RECEIVE_INVOICES, invoices })
invoices.forEach(decorateInvoice)
dispatch({ type: RECEIVE_INVOICES, invoices })
}

// Send IPC event for creating an invoice
Expand Down Expand Up @@ -137,13 +137,13 @@ export const invoiceFailed = (event, { error }) => dispatch => {

// Listen for invoice updates pushed from backend from subscribeToInvoices
export const invoiceUpdate = (event, { invoice }) => dispatch => {
decorateInvoice(invoice)

dispatch({ type: UPDATE_INVOICE, invoice })

// Fetch new balance
dispatch(fetchBalance())

decorateInvoice(invoice)

if (invoice.settled) {
// HTML 5 desktop notification for the invoice update
const notifTitle = "You've been Zapped"
Expand Down Expand Up @@ -171,22 +171,27 @@ const ACTION_HANDLERS = {
[INVOICE_SUCCESSFUL]: (state, { invoice }) => ({
...state,
invoiceLoading: false,
invoices: [invoice, ...state.invoices]
invoices: [...state.invoices, invoice]
}),
[INVOICE_FAILED]: state => ({ ...state, invoiceLoading: false, data: null }),

[UPDATE_INVOICE]: (state, action) => {
let isNew = true
const updatedInvoices = state.invoices.map(invoice => {
if (invoice.r_hash.toString('hex') !== action.invoice.r_hash.toString('hex')) {
return invoice
}

return {
...invoice,
...action.invoice
if (invoice.r_hash.toString('hex') === action.invoice.r_hash.toString('hex')) {
isNew = false
return {
...invoice,
...action.invoice
}
}
return invoice
})

if (isNew) {
updatedInvoices.push(action.invoice)
}

return { ...state, invoices: updatedInvoices }
}
}
Expand Down

0 comments on commit a24d459

Please sign in to comment.