Browse Source
Prevent Infinity % by taking the first non-empty balance instead of first one
master
meriadec
7 years ago
No known key found for this signature in database
GPG Key ID: 1D2FC2305E2CB399
1 changed files with
5 additions and
2 deletions
-
src/components/CalculateBalance.js
|
|
@ -3,7 +3,7 @@ |
|
|
|
import { PureComponent } from 'react' |
|
|
|
import { connect } from 'react-redux' |
|
|
|
import moment from 'moment' |
|
|
|
import first from 'lodash/first' |
|
|
|
import find from 'lodash/find' |
|
|
|
import last from 'lodash/last' |
|
|
|
|
|
|
|
import type { MapStateToProps } from 'react-redux' |
|
|
@ -30,10 +30,13 @@ function calculateBalance(props) { |
|
|
|
interval, |
|
|
|
}).map(e => ({ name: e.date, value: e.balance })) |
|
|
|
|
|
|
|
const firstNonEmptyDay = find(allBalances, e => e.value) |
|
|
|
const sinceBalance = firstNonEmptyDay ? firstNonEmptyDay.value : 0 |
|
|
|
|
|
|
|
return { |
|
|
|
allBalances, |
|
|
|
totalBalance: last(allBalances).value, |
|
|
|
sinceBalance: first(allBalances).value, |
|
|
|
sinceBalance, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|