Browse Source

fix(wallet): add all new invoices to invoice list

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
renovate/lint-staged-8.x
Tom Kirkpatrick 6 years ago
parent
commit
a24d459b25
No known key found for this signature in database GPG Key ID: 72203A8EC5967EA8
  1. 27
      app/reducers/invoice.js

27
app/reducers/invoice.js

@ -95,8 +95,8 @@ export const fetchInvoices = () => dispatch => {
// Receive IPC event for invoices // Receive IPC event for invoices
export const receiveInvoices = (event, { invoices }) => dispatch => { export const receiveInvoices = (event, { invoices }) => dispatch => {
dispatch({ type: RECEIVE_INVOICES, invoices })
invoices.forEach(decorateInvoice) invoices.forEach(decorateInvoice)
dispatch({ type: RECEIVE_INVOICES, invoices })
} }
// Send IPC event for creating an invoice // Send IPC event for creating an invoice
@ -137,13 +137,13 @@ export const invoiceFailed = (event, { error }) => dispatch => {
// Listen for invoice updates pushed from backend from subscribeToInvoices // Listen for invoice updates pushed from backend from subscribeToInvoices
export const invoiceUpdate = (event, { invoice }) => dispatch => { export const invoiceUpdate = (event, { invoice }) => dispatch => {
decorateInvoice(invoice)
dispatch({ type: UPDATE_INVOICE, invoice }) dispatch({ type: UPDATE_INVOICE, invoice })
// Fetch new balance // Fetch new balance
dispatch(fetchBalance()) dispatch(fetchBalance())
decorateInvoice(invoice)
if (invoice.settled) { if (invoice.settled) {
// HTML 5 desktop notification for the invoice update // HTML 5 desktop notification for the invoice update
const notifTitle = "You've been Zapped" const notifTitle = "You've been Zapped"
@ -171,22 +171,27 @@ const ACTION_HANDLERS = {
[INVOICE_SUCCESSFUL]: (state, { invoice }) => ({ [INVOICE_SUCCESSFUL]: (state, { invoice }) => ({
...state, ...state,
invoiceLoading: false, invoiceLoading: false,
invoices: [invoice, ...state.invoices] invoices: [...state.invoices, invoice]
}), }),
[INVOICE_FAILED]: state => ({ ...state, invoiceLoading: false, data: null }), [INVOICE_FAILED]: state => ({ ...state, invoiceLoading: false, data: null }),
[UPDATE_INVOICE]: (state, action) => { [UPDATE_INVOICE]: (state, action) => {
let isNew = true
const updatedInvoices = state.invoices.map(invoice => { const updatedInvoices = state.invoices.map(invoice => {
if (invoice.r_hash.toString('hex') !== action.invoice.r_hash.toString('hex')) { if (invoice.r_hash.toString('hex') === action.invoice.r_hash.toString('hex')) {
return invoice isNew = false
} return {
...invoice,
return { ...action.invoice
...invoice, }
...action.invoice
} }
return invoice
}) })
if (isNew) {
updatedInvoices.push(action.invoice)
}
return { ...state, invoices: updatedInvoices } return { ...state, invoices: updatedInvoices }
} }
} }

Loading…
Cancel
Save