From b17ce6c9a5666756a5ecd02d16c233ff958d7c5d Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 9 Nov 2016 13:16:17 +0100 Subject: [PATCH] Updated blance display with max decimals (#3266) --- js/src/ui/Balance/balance.css | 2 +- js/src/ui/Balance/balance.js | 29 ++++++++++++++++++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/js/src/ui/Balance/balance.css b/js/src/ui/Balance/balance.css index 6fe1b2a51..f36133fe6 100644 --- a/js/src/ui/Balance/balance.css +++ b/js/src/ui/Balance/balance.css @@ -44,7 +44,7 @@ } .balanceValue { - margin: 0 1em 0 0; + margin: 0 0.5em 0 0; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; diff --git a/js/src/ui/Balance/balance.js b/js/src/ui/Balance/balance.js index 22b9fc1ae..bc98968ea 100644 --- a/js/src/ui/Balance/balance.js +++ b/js/src/ui/Balance/balance.js @@ -44,15 +44,30 @@ class Balance extends Component { .filter((balance) => new BigNumber(balance.value).gt(0)) .map((balance) => { const token = balance.token; - const value = token.format - ? new BigNumber(balance.value).div(new BigNumber(token.format)).toFormat(3) - : api.util.fromWei(balance.value).toFormat(3); + + let value; + if (token.format) { + const bnf = new BigNumber(token.format); + + let decimals = 0; + if (bnf.gte(1000)) { + decimals = 3; + } else if (bnf.gte(100)) { + decimals = 2; + } else if (bnf.gte(10)) { + decimals = 1; + } + + value = new BigNumber(balance.value).div(bnf).toFormat(decimals); + } else { + value = api.util.fromWei(balance.value).toFormat(3); + } + let imagesrc = token.image; if (!imagesrc) { - imagesrc = - images[token.address] - ? `${api.dappsUrl}${images[token.address]}` - : unknownImage; + imagesrc = images[token.address] + ? `${api.dappsUrl}${images[token.address]}` + : unknownImage; } return (