aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <somniac@me.com>2016-08-19 22:50:37 +0800
committerGitHub <noreply@github.com>2016-08-19 22:50:37 +0800
commit9c29328085fbad82ce7bce4659ce6968405a7b3c (patch)
treece79c43cb24dc87202410697184501f94db9a5fa
parent90d6bec3ed51ba4b2d4696132642a4d97712dec9 (diff)
parentd53b056425ea69e82987acdd0eaa91948b943ca7 (diff)
downloadtangerine-wallet-browser-9c29328085fbad82ce7bce4659ce6968405a7b3c.tar
tangerine-wallet-browser-9c29328085fbad82ce7bce4659ce6968405a7b3c.tar.gz
tangerine-wallet-browser-9c29328085fbad82ce7bce4659ce6968405a7b3c.tar.bz2
tangerine-wallet-browser-9c29328085fbad82ce7bce4659ce6968405a7b3c.tar.lz
tangerine-wallet-browser-9c29328085fbad82ce7bce4659ce6968405a7b3c.tar.xz
tangerine-wallet-browser-9c29328085fbad82ce7bce4659ce6968405a7b3c.tar.zst
tangerine-wallet-browser-9c29328085fbad82ce7bce4659ce6968405a7b3c.zip
Merge pull request #557 from MetaMask/balance-fix
Fix rounding issues.
-rw-r--r--CHANGELOG.md1
-rw-r--r--ui/app/components/account-eth-balance.js17
-rw-r--r--ui/app/util.js15
3 files changed, 20 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b7833e9d1..a196f9d22 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
## Current Master
- Added feature to reflect current conversion rates of current vault balance.
+- Modify balance display logic.
## 2.8.0 2016-08-15
diff --git a/ui/app/components/account-eth-balance.js b/ui/app/components/account-eth-balance.js
index 6cdb33b73..8d693685f 100644
--- a/ui/app/components/account-eth-balance.js
+++ b/ui/app/components/account-eth-balance.js
@@ -46,16 +46,17 @@ EthBalanceComponent.prototype.render = function () {
EthBalanceComponent.prototype.renderBalance = function (value, state) {
if (value === 'None') return value
var balanceObj = generateBalanceObject(value, state.shorten ? 1 : 3)
- var balance, fiatNumber
+ var balance, fiatDisplayNumber, fiatTooltipNumber
var splitBalance = value.split(' ')
var ethNumber = splitBalance[0]
var ethSuffix = splitBalance[1]
if (state.conversionRate !== 0) {
- fiatNumber = (Number(splitBalance[0]) * state.conversionRate).toFixed(2)
+ fiatTooltipNumber = Number(splitBalance[0]) * state.conversionRate
+ fiatDisplayNumber = fiatTooltipNumber.toFixed(2)
} else {
- fiatNumber = 'N/A'
+ fiatDisplayNumber = 'N/A'
}
var fiatSuffix = state.currentFiat
@@ -99,16 +100,16 @@ EthBalanceComponent.prototype.renderBalance = function (value, state) {
]),
h(Tooltip, {
position: 'bottom',
- title: `${fiatNumber} ${fiatSuffix}`,
+ title: `${fiatTooltipNumber} ${fiatSuffix}`,
}, [
- fiatDisplay(fiatNumber, fiatSuffix),
+ fiatDisplay(fiatDisplayNumber, fiatSuffix),
]),
])
)
}
-function fiatDisplay (fiatNumber, fiatSuffix) {
- if (fiatNumber !== 'N/A') {
+function fiatDisplay (fiatDisplayNumber, fiatSuffix) {
+ if (fiatDisplayNumber !== 'N/A') {
return h('.flex-row', {
style: {
alignItems: 'flex-end',
@@ -124,7 +125,7 @@ function fiatDisplay (fiatNumber, fiatSuffix) {
fontSize: '12px',
color: '#333333',
},
- }, fiatNumber),
+ }, fiatDisplayNumber),
h('div', {
style: {
color: '#AEAEAE',
diff --git a/ui/app/util.js b/ui/app/util.js
index e1fd6e399..2d1c753dd 100644
--- a/ui/app/util.js
+++ b/ui/app/util.js
@@ -141,16 +141,21 @@ function shortenBalance (balance, decimalsToKeep = 1) {
var convertedBalance = parseFloat(balance)
if (convertedBalance > 1000000) {
truncatedValue = (balance / 1000000).toFixed(decimalsToKeep)
- return `>${truncatedValue}m`
+ return `${truncatedValue}m`
} else if (convertedBalance > 1000) {
truncatedValue = (balance / 1000).toFixed(decimalsToKeep)
- return `>${truncatedValue}k`
+ return `${truncatedValue}k`
} else if (convertedBalance === 0) {
return '0'
+ } else if (convertedBalance < 0.001) {
+ return '<0.001'
} else if (convertedBalance < 1) {
- var exponent = balance.match(/\.0*/)[0].length
- truncatedValue = (convertedBalance * Math.pow(10, exponent)).toFixed(decimalsToKeep)
- return `<${truncatedValue}e-${exponent}`
+ var stringBalance = convertedBalance.toString()
+ if (stringBalance.split('.')[1].length > 3) {
+ return convertedBalance.toFixed(3)
+ } else {
+ return stringBalance
+ }
} else {
return convertedBalance.toFixed(decimalsToKeep)
}