From 666f3cd66ce56013e5688d514e3c1fc3ec8a6ac4 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 16 Aug 2016 15:11:40 -0700 Subject: [PATCH] Added compliance for tests and properly accounts for N/A conversions. --- app/scripts/lib/config-manager.js | 6 +++--- test/unit/config-manager-test.js | 13 ++++++------- ui/app/components/account-eth-balance.js | 2 +- ui/app/reducers/metamask.js | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 44617f0ed..c56f52e48 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -291,7 +291,7 @@ ConfigManager.prototype.updateConversionRate = function () { this.setConversionDate(parsedResponse.timestamp) }).catch((err) => { console.error('Error in conversion.', err) - this.setConversionPrice('N/A') + this.setConversionPrice(0) this.setConversionDate('N/A') }) } @@ -310,12 +310,12 @@ ConfigManager.prototype.setConversionDate = function (datestring) { ConfigManager.prototype.getConversionRate = function () { var data = this.getData() - return ('conversionRate' in data) && data.conversionRate + return (('conversionRate' in data) && data.conversionRate) || 0 } ConfigManager.prototype.getConversionDate = function () { var data = this.getData() - return ('conversionDate' in data) && data.conversionDate + return (('conversionDate' in data) && data.conversionDate) || 'N/A' } ConfigManager.prototype.setShouldntShowWarning = function () { diff --git a/test/unit/config-manager-test.js b/test/unit/config-manager-test.js index 6eeaa7c51..b34089163 100644 --- a/test/unit/config-manager-test.js +++ b/test/unit/config-manager-test.js @@ -24,16 +24,16 @@ describe('config-manager', function() { describe('#setCurrentFiat', function() { it('should make getCurrentFiat return true once set', function() { assert.equal(configManager.getCurrentFiat(), false) - configManager.setCurrentFiat('usd') + configManager.setCurrentFiat('USD') var result = configManager.getCurrentFiat() - assert.equal(result, 'usd') + assert.equal(result, 'USD') }) it('should work with other currencies as well', function() { assert.equal(configManager.getCurrentFiat(), false) - configManager.setCurrentFiat('jpy') + configManager.setCurrentFiat('JPY') var result = configManager.getCurrentFiat() - assert.equal(result, 'jpy') + assert.equal(result, 'JPY') }) }) @@ -50,7 +50,7 @@ describe('config-manager', function() { assert.equal(configManager.getConversionRate(), false) var promise = new Promise( function (resolve, reject) { - configManager.setCurrentFiat('usd') + configManager.setCurrentFiat('USD') configManager.updateConversionRate().then(function() { resolve() }) @@ -71,7 +71,7 @@ describe('config-manager', function() { assert.equal(configManager.getConversionRate(), false) var promise = new Promise( function (resolve, reject) { - configManager.setCurrentFiat('jpy') + configManager.setCurrentFiat('JPY') configManager.updateConversionRate().then(function() { resolve() }) @@ -80,7 +80,6 @@ describe('config-manager', function() { promise.then(function() { var result = configManager.getConversionRate() assert.equal(typeof result, 'number') - done() }).catch(function(err) { console.log(err) }) diff --git a/ui/app/components/account-eth-balance.js b/ui/app/components/account-eth-balance.js index bcef40096..6cdb33b73 100644 --- a/ui/app/components/account-eth-balance.js +++ b/ui/app/components/account-eth-balance.js @@ -52,7 +52,7 @@ EthBalanceComponent.prototype.renderBalance = function (value, state) { var ethSuffix = splitBalance[1] - if (state.conversionRate !== 'N/A') { + if (state.conversionRate !== 0) { fiatNumber = (Number(splitBalance[0]) * state.conversionRate).toFixed(2) } else { fiatNumber = 'N/A' diff --git a/ui/app/reducers/metamask.js b/ui/app/reducers/metamask.js index 7af805f06..7f18480cb 100644 --- a/ui/app/reducers/metamask.js +++ b/ui/app/reducers/metamask.js @@ -16,7 +16,7 @@ function reduceMetamask (state, action) { identities: {}, unconfTxs: {}, currentFiat: 'USD', - conversionRate: 'N/A', + conversionRate: 0, conversionDate: 'N/A', }, state.metamask)