diff --git a/renderer/reducers/balance/selectors.js b/renderer/reducers/balance/selectors.js index 1c07fd91939..db24301b48d 100644 --- a/renderer/reducers/balance/selectors.js +++ b/renderer/reducers/balance/selectors.js @@ -69,9 +69,23 @@ export const limboBalance = state => state.channels.pendingChannels.totalLimboBa */ export const totalBalance = createSelector( channelBalance, - walletBalance, + walletBalanceConfirmed, + walletBalanceUnconfirmed, limboBalance, - (c = 0, w = 0, l = 0) => CoinBig.sum(c, w, l).toString() + (c = '0', wc = '0', wuc = '0', l = '0') => { + // when a force close channel passes its maturity height the balance from it + // appears in both unconfirmed wallet balance and in total limbo balance. + // Here we try to prevent the double counting. + const dedupedUnconfirmed = CoinBig(wuc).minus(l) + const unconfirmed = CoinBig.max(0, dedupedUnconfirmed) + + // Total balance is the sum of + // - channel balances + // - confirmed wallet balance + // - deduped unconfirmed wallet balance + // - limbo balance + return CoinBig.sum(c, wc, unconfirmed, l).toString() + } ) export default { diff --git a/renderer/reducers/transaction.js b/renderer/reducers/transaction.js index d3f85e90fa8..36cb24d5225 100644 --- a/renderer/reducers/transaction.js +++ b/renderer/reducers/transaction.js @@ -142,8 +142,9 @@ export const receiveTransactions = (transactions, updateOnly = false) => (dispat } }) - // Fetch updated balance. + // Fetch updated channels and balance. dispatch(fetchBalance()) + dispatch(fetchChannels()) } /** @@ -252,8 +253,6 @@ export const receiveTransactionData = transaction => (dispatch, getState) => { showSystemNotification(intl.formatMessage(messages.transaction_received_title), { body: intl.formatMessage(messages.transaction_received_body), }) - // Fetch updated channels. - dispatch(fetchChannels()) } else { showSystemNotification(intl.formatMessage(messages.transaction_sent_title), { body: intl.formatMessage(messages.transaction_sent_body),