From 9132f085070a99499a75d6353983bd1683f7a3f0 Mon Sep 17 00:00:00 2001 From: Zac Mitton Date: Mon, 20 Jun 2016 18:46:29 -0400 Subject: [PATCH 1/4] added a failing case and fixed it by refactoring everything to strings --- test/unit/util_test.js | 16 +++++++++++++++- ui/app/util.js | 18 ++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/test/unit/util_test.js b/test/unit/util_test.js index 12a16999e..e2390c8d4 100644 --- a/test/unit/util_test.js +++ b/test/unit/util_test.js @@ -25,12 +25,26 @@ describe('util', function() { }) }) describe('parseBalance', function() { - it('should render 0.01 eth correctly', function() { + it('should render 12.023 eth correctly', function() { const input = 'A6DA46CCA6858000' const output = util.parseBalance(input) assert.deepEqual(output, ['12', '023']) }) }) + describe('parseBalance', function() { + it('should render 0.0000000342422 eth correctly', function() { + const input = '0x7F8FE81C0' + const output = util.parseBalance(input) + assert.deepEqual(output, ['0', '0000000342422']) + }) + }) + describe('parseBalance', function() { + it('should render 0 eth correctly', function() { + const input = '0x0' + const output = util.parseBalance(input) + assert.deepEqual(output, ['0', '0']) + }) + }) describe('addressSummary', function() { it('should add case-sensitive checksum', function() { diff --git a/ui/app/util.js b/ui/app/util.js index 6ece28a9e..56a16a4cd 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -85,22 +85,20 @@ function weiToEth(bn) { // Takes hex, returns [beforeDecimal, afterDecimal] function parseBalance(balance) { - if (!balance || balance === '0x0') return ['0', '0'] - var wei = numericBalance(balance).toString(10) - var eth = String(wei/valueTable['wei']) - var beforeDecimal = String(Math.floor(eth)) - var afterDecimal - if(eth.indexOf('.') > -1){ - afterDecimal = eth.slice(eth.indexOf('.') + 1) - }else{ - afterDecimal = '0' - } + let beforeDecimal, afterDecimal + let wei = numericBalance(balance).toString() + let trailingZeros = /0+$/ + + beforeDecimal = wei.length > 18 ? wei.slice(0, wei.length - 18) : '0' + afterDecimal = ("000000000000000000" + wei).slice(-18).replace(trailingZeros, "") + if(afterDecimal == ""){afterDecimal = "0" } return [beforeDecimal, afterDecimal] } // Takes wei hex, returns "None" or "${formattedAmount} ETH" function formatBalance(balance, decimalsToKeep) { var parsed = parseBalance(balance) + console.log(parsed) var beforeDecimal = parsed[0] var afterDecimal = parsed[1] var formatted = "None" From 30da8486110f2cfeadfd3605c6c8090e90ce2dee Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 21 Jun 2016 00:39:27 -0700 Subject: [PATCH 2/4] id-mgmt - add missing deps --- app/scripts/lib/id-management.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/scripts/lib/id-management.js b/app/scripts/lib/id-management.js index 30a3141f1..5de1f438f 100644 --- a/app/scripts/lib/id-management.js +++ b/app/scripts/lib/id-management.js @@ -1,7 +1,10 @@ const ethUtil = require('ethereumjs-util') +const Transaction = require('ethereumjs-tx') +const configManager = require('./config-manager-singleton') module.exports = IdManagement + function IdManagement(opts) { if (!opts) opts = {} From 6fdece459d1d2674acc5349b70e68c1d5033dd38 Mon Sep 17 00:00:00 2001 From: kumavis Date: Tue, 21 Jun 2016 00:51:59 -0700 Subject: [PATCH 3/4] 2.4.1 --- app/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/manifest.json b/app/manifest.json index 2e2d28f37..dede7402a 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_appName__", "short_name": "Metamask", - "version": "2.4.0", + "version": "2.4.1", "manifest_version": 2, "description": "__MSG_appDescription__", "icons": { From bd6ee81d097f3da2fcfbfb7b7d29d5daf706eb1d Mon Sep 17 00:00:00 2001 From: Zac Mitton Date: Tue, 21 Jun 2016 10:52:41 -0500 Subject: [PATCH 4/4] tweek --- ui/app/util.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/app/util.js b/ui/app/util.js index 56a16a4cd..9e08e0bb2 100644 --- a/ui/app/util.js +++ b/ui/app/util.js @@ -98,7 +98,6 @@ function parseBalance(balance) { // Takes wei hex, returns "None" or "${formattedAmount} ETH" function formatBalance(balance, decimalsToKeep) { var parsed = parseBalance(balance) - console.log(parsed) var beforeDecimal = parsed[0] var afterDecimal = parsed[1] var formatted = "None"