Skip to content

Commit

Permalink
chore(account): fixed TypeError for accounts with 3+ tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuggins committed Aug 18, 2018
1 parent b7194b4 commit 6993ec8
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import styles from './Breakdown.scss';

const COLORS = ['#5ebb46', '#b5d433', '#0b99e3'];

function reduceOthers(data) {
function reduceSum(data) {
return reduce(data, (sum, datum) => sum + datum.value, 0);
}

Expand Down Expand Up @@ -72,15 +72,22 @@ export default class Breakdown extends React.PureComponent {
return data;
}

const [item1, item2, ...items] = data;

// HACK: removing this console.log causes `TypeError: Assignment to constant variable` in the
// distributable version of the app for some reason. It's unclear why, but it may be a
// babel transpilation issue.
console.log('sum:', reduceSum(items));

return [
...data.splice(0, 2),
{ label: 'OTHERS', value: reduceOthers(data) }
item1,
item2,
{ label: 'OTHERS', value: reduceSum(items) }
];
}

getTotalValue = () => {
const value = reduce(this.props.data, (sum, datum) => sum + datum.value, 0);
return this.formatValue(value);
return this.formatValue(reduceSum(this.props.data));
}

formatValue = (value) => {
Expand Down

0 comments on commit 6993ec8

Please sign in to comment.