|
|
@ -4,6 +4,7 @@ import { PureComponent } from 'react' |
|
|
|
import { connect } from 'react-redux' |
|
|
|
import moment from 'moment' |
|
|
|
import find from 'lodash/find' |
|
|
|
import first from 'lodash/first' |
|
|
|
import last from 'lodash/last' |
|
|
|
|
|
|
|
import type { MapStateToProps } from 'react-redux' |
|
|
@ -31,12 +32,13 @@ function calculateBalance(props) { |
|
|
|
}).map(e => ({ name: e.date, value: e.balance })) |
|
|
|
|
|
|
|
const firstNonEmptyDay = find(allBalances, e => e.value) |
|
|
|
const sinceBalance = firstNonEmptyDay ? firstNonEmptyDay.value : 0 |
|
|
|
const refBalance = firstNonEmptyDay ? firstNonEmptyDay.value : 0 |
|
|
|
|
|
|
|
return { |
|
|
|
allBalances, |
|
|
|
totalBalance: last(allBalances).value, |
|
|
|
sinceBalance, |
|
|
|
sinceBalance: first(allBalances).value, |
|
|
|
refBalance, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -51,6 +53,7 @@ type State = { |
|
|
|
allBalances: Array<Object>, |
|
|
|
totalBalance: number, |
|
|
|
sinceBalance: number, |
|
|
|
refBalance: number, |
|
|
|
} |
|
|
|
|
|
|
|
class CalculateBalance extends PureComponent<Props, State> { |
|
|
@ -72,9 +75,9 @@ class CalculateBalance extends PureComponent<Props, State> { |
|
|
|
|
|
|
|
render() { |
|
|
|
const { render } = this.props |
|
|
|
const { allBalances, totalBalance, sinceBalance } = this.state |
|
|
|
const { allBalances, totalBalance, sinceBalance, refBalance } = this.state |
|
|
|
|
|
|
|
return render({ allBalances, totalBalance, sinceBalance }) |
|
|
|
return render({ allBalances, totalBalance, sinceBalance, refBalance }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|