1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Added compliance for tests and properly accounts for N/A conversions.

This commit is contained in:
Kevin Serrano 2016-08-16 15:11:40 -07:00
parent 121af0c4b9
commit 666f3cd66c
4 changed files with 11 additions and 12 deletions

View File

@ -291,7 +291,7 @@ ConfigManager.prototype.updateConversionRate = function () {
this.setConversionDate(parsedResponse.timestamp) this.setConversionDate(parsedResponse.timestamp)
}).catch((err) => { }).catch((err) => {
console.error('Error in conversion.', err) console.error('Error in conversion.', err)
this.setConversionPrice('N/A') this.setConversionPrice(0)
this.setConversionDate('N/A') this.setConversionDate('N/A')
}) })
} }
@ -310,12 +310,12 @@ ConfigManager.prototype.setConversionDate = function (datestring) {
ConfigManager.prototype.getConversionRate = function () { ConfigManager.prototype.getConversionRate = function () {
var data = this.getData() var data = this.getData()
return ('conversionRate' in data) && data.conversionRate return (('conversionRate' in data) && data.conversionRate) || 0
} }
ConfigManager.prototype.getConversionDate = function () { ConfigManager.prototype.getConversionDate = function () {
var data = this.getData() var data = this.getData()
return ('conversionDate' in data) && data.conversionDate return (('conversionDate' in data) && data.conversionDate) || 'N/A'
} }
ConfigManager.prototype.setShouldntShowWarning = function () { ConfigManager.prototype.setShouldntShowWarning = function () {

View File

@ -24,16 +24,16 @@ describe('config-manager', function() {
describe('#setCurrentFiat', function() { describe('#setCurrentFiat', function() {
it('should make getCurrentFiat return true once set', function() { it('should make getCurrentFiat return true once set', function() {
assert.equal(configManager.getCurrentFiat(), false) assert.equal(configManager.getCurrentFiat(), false)
configManager.setCurrentFiat('usd') configManager.setCurrentFiat('USD')
var result = configManager.getCurrentFiat() var result = configManager.getCurrentFiat()
assert.equal(result, 'usd') assert.equal(result, 'USD')
}) })
it('should work with other currencies as well', function() { it('should work with other currencies as well', function() {
assert.equal(configManager.getCurrentFiat(), false) assert.equal(configManager.getCurrentFiat(), false)
configManager.setCurrentFiat('jpy') configManager.setCurrentFiat('JPY')
var result = configManager.getCurrentFiat() 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) assert.equal(configManager.getConversionRate(), false)
var promise = new Promise( var promise = new Promise(
function (resolve, reject) { function (resolve, reject) {
configManager.setCurrentFiat('usd') configManager.setCurrentFiat('USD')
configManager.updateConversionRate().then(function() { configManager.updateConversionRate().then(function() {
resolve() resolve()
}) })
@ -71,7 +71,7 @@ describe('config-manager', function() {
assert.equal(configManager.getConversionRate(), false) assert.equal(configManager.getConversionRate(), false)
var promise = new Promise( var promise = new Promise(
function (resolve, reject) { function (resolve, reject) {
configManager.setCurrentFiat('jpy') configManager.setCurrentFiat('JPY')
configManager.updateConversionRate().then(function() { configManager.updateConversionRate().then(function() {
resolve() resolve()
}) })
@ -80,7 +80,6 @@ describe('config-manager', function() {
promise.then(function() { promise.then(function() {
var result = configManager.getConversionRate() var result = configManager.getConversionRate()
assert.equal(typeof result, 'number') assert.equal(typeof result, 'number')
done()
}).catch(function(err) { }).catch(function(err) {
console.log(err) console.log(err)
}) })

View File

@ -52,7 +52,7 @@ EthBalanceComponent.prototype.renderBalance = function (value, state) {
var ethSuffix = splitBalance[1] var ethSuffix = splitBalance[1]
if (state.conversionRate !== 'N/A') { if (state.conversionRate !== 0) {
fiatNumber = (Number(splitBalance[0]) * state.conversionRate).toFixed(2) fiatNumber = (Number(splitBalance[0]) * state.conversionRate).toFixed(2)
} else { } else {
fiatNumber = 'N/A' fiatNumber = 'N/A'

View File

@ -16,7 +16,7 @@ function reduceMetamask (state, action) {
identities: {}, identities: {},
unconfTxs: {}, unconfTxs: {},
currentFiat: 'USD', currentFiat: 'USD',
conversionRate: 'N/A', conversionRate: 0,
conversionDate: 'N/A', conversionDate: 'N/A',
}, state.metamask) }, state.metamask)