diff options
author | Kevin Serrano <kevgagser@gmail.com> | 2016-07-22 07:44:50 +0800 |
---|---|---|
committer | Kevin Serrano <kevgagser@gmail.com> | 2016-07-22 07:44:50 +0800 |
commit | a612fcee64422ca43c470d7832a263f5e490611d (patch) | |
tree | c6cd96d20a9dfb9d0ebc9d9a66a364d94ee60870 /app/scripts/lib | |
parent | 716e65424d2ba490a384bfc1f0591685eb2867fa (diff) | |
download | tangerine-wallet-browser-a612fcee64422ca43c470d7832a263f5e490611d.tar tangerine-wallet-browser-a612fcee64422ca43c470d7832a263f5e490611d.tar.gz tangerine-wallet-browser-a612fcee64422ca43c470d7832a263f5e490611d.tar.bz2 tangerine-wallet-browser-a612fcee64422ca43c470d7832a263f5e490611d.tar.lz tangerine-wallet-browser-a612fcee64422ca43c470d7832a263f5e490611d.tar.xz tangerine-wallet-browser-a612fcee64422ca43c470d7832a263f5e490611d.tar.zst tangerine-wallet-browser-a612fcee64422ca43c470d7832a263f5e490611d.zip |
Change function names. Add interval polling for api. Refactor functions.
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/config-manager.js | 25 |
1 files changed, 18 insertions, 7 deletions
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 |