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

Commit

Permalink
fix(wallet): prevent double count of unconfirmed force close balance
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed May 23, 2020
1 parent c54f83c commit d06657a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
18 changes: 16 additions & 2 deletions renderer/reducers/balance/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions renderer/reducers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ export const receiveTransactions = (transactions, updateOnly = false) => (dispat
}
})

// Fetch updated balance.
// Fetch updated channels and balance.
dispatch(fetchBalance())
dispatch(fetchChannels())
}

/**
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d06657a

Please sign in to comment.