Skip to content

Commit

Permalink
Fix CoinValue component
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksey Dmitriev committed Jul 12, 2018
1 parent 20a7497 commit db85a64
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions client/src/components/common/coin-value/coin-value.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,34 @@ interface ICoinValueProps {

export class CoinValueComponent extends React.PureComponent<ICoinValueProps> {
render (): JSX.Element {
return (
<div className='bi-coin-value'>
{ this.getFormattedValue() } { environment.blockchain.coinName.toUpperCase() }
</div>
);
}

private getFormattedValue (): string {
const { value } = this.props;

let formattedValue = value/1e8;
const formattedValue = value / 1e8;

if (formattedValue < 1) {
formattedValue = value;
return formattedValue.toFixed(8)
.split('')
.reduceRight((arr: string[], i: string) => {
if (i === '0' && arr.length === 0) {
return arr;
}

arr.push(i);

return arr;
}, [])
.reverse()
.join('');
}

return (
<div className='bi-coin-value'>
{ formattedValue } { environment.blockchain.coinName.toUpperCase() }
</div>
);
return formattedValue.toString();
}
}

0 comments on commit db85a64

Please sign in to comment.