Browse Source

Polish and retrieve original value from balance history

master
meriadec 7 years ago
parent
commit
8a7d54e149
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 4
      src/components/BalanceSummary/index.js
  2. 14
      src/components/CalculateBalance.js
  3. 4
      src/components/CounterValue/index.js
  4. 17
      src/components/base/Chart/Tooltip.js
  5. 2
      src/components/base/Chart/handleMouseEvents.js

4
src/components/BalanceSummary/index.js

@ -80,7 +80,9 @@ const BalanceSummary = ({
fiat={counterValue} fiat={counterValue}
val={d.value} val={d.value}
/> />
<Box mt="auto">{d.date.toISOString().substr(0, 10)}</Box> <Box ff="Open Sans|Regular" color="grey" fontSize={3} mt={2}>
{d.date.toISOString().substr(0, 10)}
</Box>
</Fragment> </Fragment>
) )
: null : null

14
src/components/CalculateBalance.js

@ -26,10 +26,18 @@ type Props = OwnProps & {
const mapStateToProps = (state: State, props: OwnProps) => { const mapStateToProps = (state: State, props: OwnProps) => {
const counterValueCurrency = counterValueCurrencySelector(state) const counterValueCurrency = counterValueCurrencySelector(state)
let isAvailable = true let isAvailable = true
// create array of original values, used to reconciliate
// with counter values after calculation
const originalValues = []
const balanceHistory = getBalanceHistorySum( const balanceHistory = getBalanceHistorySum(
props.accounts, props.accounts,
props.daysCount, props.daysCount,
(account, value, date) => { (account, value, date) => {
// keep track of original value
originalValues.push(value)
const cv = CounterValues.calculateSelector(state, { const cv = CounterValues.calculateSelector(state, {
value, value,
date, date,
@ -44,6 +52,12 @@ const mapStateToProps = (state: State, props: OwnProps) => {
return cv return cv
}, },
) )
// reconciliate balance history with original values
balanceHistory.forEach((item, i) => {
item.originalValue = originalValues[i] || 0
})
return { return {
isAvailable, isAvailable,
balanceHistory, balanceHistory,

4
src/components/CounterValue/index.js

@ -49,7 +49,9 @@ const mapStateToProps = (state: State, props: OwnProps) => {
class CounterValue extends PureComponent<Props> { class CounterValue extends PureComponent<Props> {
render() { render() {
const { value, counterValueCurrency, date, ...props } = this.props const { value, counterValueCurrency, date, ...props } = this.props
if (!value && value !== 0) return null if (!value && value !== 0) {
return null
}
return ( return (
<FormattedVal <FormattedVal
val={value} val={value}

17
src/components/base/Chart/Tooltip.js

@ -5,7 +5,6 @@ import styled from 'styled-components'
import type { Account } from '@ledgerhq/live-common/lib/types' import type { Account } from '@ledgerhq/live-common/lib/types'
import CounterValue from 'components/CounterValue'
import FormattedVal from 'components/base/FormattedVal' import FormattedVal from 'components/base/FormattedVal'
import Box from 'components/base/Box' import Box from 'components/base/Box'
@ -20,7 +19,6 @@ const Container = styled(Box).attrs({
border: 1px solid #d8d8d8; border: 1px solid #d8d8d8;
border-radius: 4px; border-radius: 4px;
width: 150px; width: 150px;
height: 90px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.03); box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.03);
` `
@ -54,17 +52,18 @@ const Tooltip = ({
fontSize={5} fontSize={5}
alwaysShowSign={false} alwaysShowSign={false}
showCode showCode
unit={account.currency.units[0]} fiat="USD"
val={item.value} val={item.value}
/> />
<CounterValue <FormattedVal
account={account} color="grey"
currency={account.currency} fontSize={3}
value={item.value} alwaysShowSign={false}
disableRounding
showCode showCode
unit={account.unit}
val={item.originalValue}
/> />
<Box ff="Open Sans|Regular" color="grey" fontSize={3} mt="auto"> <Box ff="Open Sans|Regular" color="grey" fontSize={3} mt={2}>
{item.date.toISOString().substr(0, 10)} {item.date.toISOString().substr(0, 10)}
</Box> </Box>
</Fragment> </Fragment>

2
src/components/base/Chart/handleMouseEvents.js

@ -100,7 +100,7 @@ export default function handleMouseEvents({
NODES.xBar NODES.xBar
.attr('x1', x(d.parsedDate)) .attr('x1', x(d.parsedDate))
.attr('x2', x(d.parsedDate)) .attr('x2', x(d.parsedDate))
.attr('y1', 0) .attr('y1', -30) // ensure that xbar is covered
.attr('y2', HEIGHT) .attr('y2', HEIGHT)
} }

Loading…
Cancel
Save