From aac810b1eb3414c907010c30537b7014f303d20f Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 21 Jul 2016 08:47:03 -0700 Subject: Progress on config manager. Plus tests. --- app/scripts/lib/config-manager.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index caaae8a75..a5b319325 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -1,6 +1,7 @@ const Migrator = require('pojo-migrator') const MetamaskConfig = require('../config.js') const migrations = require('./migrations') +const rp = require('request-promise') const TESTNET_RPC = MetamaskConfig.network.testnet const MAINNET_RPC = MetamaskConfig.network.mainnet @@ -270,3 +271,29 @@ ConfigManager.prototype.getConfirmed = function () { return ('isConfirmed' in data) && data.isConfirmed } +ConfigManager.prototype.setCurrentFiat = function (currency) { + var data = this.getData() + data.fiatCurrency = currency + this.setData(data) +} + +ConfigManager.prototype.getCurrentFiat = function () { + var data = this.getData() + return ('fiatCurrency' in data) && data.fiatCurrency +} + +ConfigManager.prototype.setConversionRate = function () { + var data = this.getData() + return rp(`https://www.cryptonator.com/api/ticker/eth-${data.fiatCurrency}`) + .then(function (response) { + data.conversionRate = Number(JSON.parse(response).ticker.price) + this.setData(data) + }.bind(this)).catch(function (err) { + console.log('Error in conversion.', err) + }) +} + +ConfigManager.prototype.getConversionRate = function () { + var data = this.getData() + return ('conversionRate' in data) && data.conversionRate +} -- cgit v1.2.3 From 4a9d5b1c258912acedd6f1e89fb632526d9c910b Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 21 Jul 2016 10:15:34 -0700 Subject: Add data field to pass up parameters up to reducer. --- app/scripts/lib/idStore.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 2c8e9108b..94aaad1d1 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -99,6 +99,8 @@ IdentityStore.prototype.getState = function () { unconfMsgs: messageManager.unconfirmedMsgs(), messages: messageManager.getMsgList(), selectedAddress: configManager.getSelectedAccount(), + currentFiat: configManager.getCurrentFiat(), + currentConversion: configManager.getConversionRate(), })) } @@ -199,7 +201,7 @@ IdentityStore.prototype.addUnconfirmedTransaction = function (txParams, onTxDone time: time, status: 'unconfirmed', } - + console.log('addUnconfirmedTransaction:', txData) // keep the onTxDoneCb around for after approval/denial (requires user interaction) -- cgit v1.2.3 From 66941f0808cd8052bd5a90b10900e49e071ba727 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 21 Jul 2016 13:33:22 -0700 Subject: Provide date access. --- app/scripts/lib/config-manager.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index a5b319325..cd0d37e98 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -286,7 +286,9 @@ ConfigManager.prototype.setConversionRate = function () { var data = this.getData() return rp(`https://www.cryptonator.com/api/ticker/eth-${data.fiatCurrency}`) .then(function (response) { - data.conversionRate = Number(JSON.parse(response).ticker.price) + const parsedResponse = JSON.parse(response) + data.conversionRate = Number(parsedResponse.ticker.price) + data.conversionLastUpdated = new Date(parsedResponse.timestamp).toString() this.setData(data) }.bind(this)).catch(function (err) { console.log('Error in conversion.', err) @@ -297,3 +299,8 @@ ConfigManager.prototype.getConversionRate = function () { var data = this.getData() return ('conversionRate' in data) && data.conversionRate } + +ConfigManager.prototype.getConversionLastUpdated = function () { + var data = this.getData() + return ('conversionLastUpdated' in data) && data.conversionLastUpdated +} -- cgit v1.2.3 From 716e65424d2ba490a384bfc1f0591685eb2867fa Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 21 Jul 2016 14:08:26 -0700 Subject: Add date access throughout the data flow. --- app/scripts/lib/config-manager.js | 6 +++--- app/scripts/lib/idStore.js | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index cd0d37e98..03f8c054d 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -288,7 +288,7 @@ ConfigManager.prototype.setConversionRate = function () { .then(function (response) { const parsedResponse = JSON.parse(response) data.conversionRate = Number(parsedResponse.ticker.price) - data.conversionLastUpdated = new Date(parsedResponse.timestamp).toString() + data.conversionDate = new Date(parsedResponse.timestamp).toString() this.setData(data) }.bind(this)).catch(function (err) { console.log('Error in conversion.', err) @@ -300,7 +300,7 @@ ConfigManager.prototype.getConversionRate = function () { return ('conversionRate' in data) && data.conversionRate } -ConfigManager.prototype.getConversionLastUpdated = function () { +ConfigManager.prototype.getConversionDate = function () { var data = this.getData() - return ('conversionLastUpdated' in data) && data.conversionLastUpdated + return ('conversionDate' in data) && data.conversionDate } diff --git a/app/scripts/lib/idStore.js b/app/scripts/lib/idStore.js index 94aaad1d1..b6c136b8f 100644 --- a/app/scripts/lib/idStore.js +++ b/app/scripts/lib/idStore.js @@ -100,7 +100,8 @@ IdentityStore.prototype.getState = function () { messages: messageManager.getMsgList(), selectedAddress: configManager.getSelectedAccount(), currentFiat: configManager.getCurrentFiat(), - currentConversion: configManager.getConversionRate(), + conversionRate: configManager.getConversionRate(), + conversionDate: configManager.getConversionDate(), })) } -- cgit v1.2.3 From a612fcee64422ca43c470d7832a263f5e490611d Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Thu, 21 Jul 2016 16:44:50 -0700 Subject: Change function names. Add interval polling for api. Refactor functions. --- app/scripts/lib/config-manager.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 03f8c054d..14caa80c8 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -282,19 +282,30 @@ ConfigManager.prototype.getCurrentFiat = function () { return ('fiatCurrency' in data) && data.fiatCurrency } -ConfigManager.prototype.setConversionRate = function () { +ConfigManager.prototype.updateConversionRate = function () { var data = this.getData() return rp(`https://www.cryptonator.com/api/ticker/eth-${data.fiatCurrency}`) - .then(function (response) { + .then((response) => { const parsedResponse = JSON.parse(response) - data.conversionRate = Number(parsedResponse.ticker.price) - data.conversionDate = new Date(parsedResponse.timestamp).toString() - this.setData(data) - }.bind(this)).catch(function (err) { - console.log('Error in conversion.', err) + this.setConversionPrice(parsedResponse.ticker.price) + this.setConversionDate(parsedResponse.timestamp) + }).catch((err) => { + console.error('Error in conversion.', err) }) } +ConfigManager.prototype.setConversionPrice = function(price) { + var data = this.getData() + data.conversionRate = Number(parsedResponse.ticker.price) + this.setData(data) +} + +ConfigManager.prototype.setConversionDate = function (datestring) { + var data = this.getData() + data.conversionDate = datestring + this.setData(data) +} + ConfigManager.prototype.getConversionRate = function () { var data = this.getData() return ('conversionRate' in data) && data.conversionRate -- cgit v1.2.3 From 22528002e1edef84ade67d5bc30b2580e6542c05 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 22 Jul 2016 10:15:39 -0700 Subject: Linting! --- app/scripts/lib/config-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 14caa80c8..e0f389ed4 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -296,7 +296,7 @@ ConfigManager.prototype.updateConversionRate = function () { ConfigManager.prototype.setConversionPrice = function(price) { var data = this.getData() - data.conversionRate = Number(parsedResponse.ticker.price) + data.conversionRate = Number(price) this.setData(data) } -- cgit v1.2.3 From 260de6532c50dceebee93acab70a3319afdb16fb Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Fri, 5 Aug 2016 12:18:44 -0700 Subject: Get fiat numbers rendering on tooltip. Need to find way to create line breaks. --- app/scripts/lib/config-manager.js | 6 ------ 1 file changed, 6 deletions(-) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index 9c37a2c6f..49eb7be4f 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -293,12 +293,6 @@ ConfigManager.prototype.updateConversionRate = function () { const parsedResponse = JSON.parse(response) this.setConversionPrice(parsedResponse.ticker.price) this.setConversionDate(parsedResponse.timestamp) - console.log('=================') - console.log('Updated currency!') - console.log('=================') - console.log(this.getConversionRate()) - console.log(this.getCurrentFiat()) - console.log(parsedResponse) }).catch((err) => { console.error('Error in conversion.', err) }) -- cgit v1.2.3 From 6041ba1ed24b16ec2614c954b05ab03488301d72 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 16 Aug 2016 14:07:06 -0700 Subject: Add fallback to API failure. --- app/scripts/lib/config-manager.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/scripts/lib') diff --git a/app/scripts/lib/config-manager.js b/app/scripts/lib/config-manager.js index f3164ec09..44617f0ed 100644 --- a/app/scripts/lib/config-manager.js +++ b/app/scripts/lib/config-manager.js @@ -291,6 +291,8 @@ ConfigManager.prototype.updateConversionRate = function () { this.setConversionDate(parsedResponse.timestamp) }).catch((err) => { console.error('Error in conversion.', err) + this.setConversionPrice('N/A') + this.setConversionDate('N/A') }) } -- cgit v1.2.3 From 666f3cd66ce56013e5688d514e3c1fc3ec8a6ac4 Mon Sep 17 00:00:00 2001 From: Kevin Serrano Date: Tue, 16 Aug 2016 15:11:40 -0700 Subject: Added compliance for tests and properly accounts for N/A conversions. --- app/scripts/lib/config-manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'app/scripts/lib') 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 () { -- cgit v1.2.3