From db85a641930cbe5bbf87149835935c0f72e8860e Mon Sep 17 00:00:00 2001 From: Aleksey Dmitriev Date: Thu, 12 Jul 2018 15:05:25 +0300 Subject: [PATCH] Fix CoinValue component --- .../coin-value/coin-value.component.tsx | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/client/src/components/common/coin-value/coin-value.component.tsx b/client/src/components/common/coin-value/coin-value.component.tsx index 4ff17aef..58a29eb5 100644 --- a/client/src/components/common/coin-value/coin-value.component.tsx +++ b/client/src/components/common/coin-value/coin-value.component.tsx @@ -7,18 +7,34 @@ interface ICoinValueProps { export class CoinValueComponent extends React.PureComponent { render (): JSX.Element { + return ( +
+ { this.getFormattedValue() } { environment.blockchain.coinName.toUpperCase() } +
+ ); + } + + 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 ( -
- { formattedValue } { environment.blockchain.coinName.toUpperCase() } -
- ); + return formattedValue.toString(); } }