1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

ui - util - fixes#110 formatBalance

This commit is contained in:
kumavis 2016-04-14 21:19:08 -07:00
parent 1e989fb8a4
commit cef1f2a65f

View File

@ -66,11 +66,11 @@ function weiToEth(bn) {
var decimalsToKeep = 4
function formatBalance(balance) {
if (!balance) return 'None'
if (!balance || balance === '0x0') return 'None'
var wei = numericBalance(balance)
var padded = wei.toString(10)
var len = padded.length
var nonZeroIndex = padded.match(/[^0]/).index
var nonZeroIndex = padded.match(/[^0]/) && padded.match(/[^0]/).index
var beforeDecimal = padded.substr(nonZeroIndex ? nonZeroIndex : 0, len - 18)
var afterDecimal = padded.substr(len - 18, decimalsToKeep)
return `${beforeDecimal}.${afterDecimal} ETH`