diff options
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/config-manager.js | 27 | ||||
-rw-r--r-- | app/scripts/lib/idStore.js | 4 |
2 files changed, 30 insertions, 1 deletions
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 +} 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) |