aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/controllers/currency.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-02-28 02:39:48 +0800
committerDan Finlay <dan@danfinlay.com>2017-02-28 02:40:37 +0800
commitb5d03cd52418cfd09ce51a23c01e78262d3ffc9b (patch)
treee19ca7c5a1880f8849376794a42c6b85fbf80fdb /app/scripts/lib/controllers/currency.js
parent5edb3db96939de2dee31fa19cb8e715dc649bfd6 (diff)
downloadtangerine-wallet-browser-b5d03cd52418cfd09ce51a23c01e78262d3ffc9b.tar
tangerine-wallet-browser-b5d03cd52418cfd09ce51a23c01e78262d3ffc9b.tar.gz
tangerine-wallet-browser-b5d03cd52418cfd09ce51a23c01e78262d3ffc9b.tar.bz2
tangerine-wallet-browser-b5d03cd52418cfd09ce51a23c01e78262d3ffc9b.tar.lz
tangerine-wallet-browser-b5d03cd52418cfd09ce51a23c01e78262d3ffc9b.tar.xz
tangerine-wallet-browser-b5d03cd52418cfd09ce51a23c01e78262d3ffc9b.tar.zst
tangerine-wallet-browser-b5d03cd52418cfd09ce51a23c01e78262d3ffc9b.zip
add controllers to root scripts folder
Diffstat (limited to 'app/scripts/lib/controllers/currency.js')
-rw-r--r--app/scripts/lib/controllers/currency.js70
1 files changed, 0 insertions, 70 deletions
diff --git a/app/scripts/lib/controllers/currency.js b/app/scripts/lib/controllers/currency.js
deleted file mode 100644
index c4904f8ac..000000000
--- a/app/scripts/lib/controllers/currency.js
+++ /dev/null
@@ -1,70 +0,0 @@
-const ObservableStore = require('obs-store')
-const extend = require('xtend')
-
-// every ten minutes
-const POLLING_INTERVAL = 600000
-
-class CurrencyController {
-
- constructor (opts = {}) {
- const initState = extend({
- currentCurrency: 'USD',
- conversionRate: 0,
- conversionDate: 'N/A',
- }, opts.initState)
- this.store = new ObservableStore(initState)
- }
-
- //
- // PUBLIC METHODS
- //
-
- getCurrentCurrency () {
- return this.store.getState().currentCurrency
- }
-
- setCurrentCurrency (currentCurrency) {
- this.store.updateState({ currentCurrency })
- }
-
- getConversionRate () {
- return this.store.getState().conversionRate
- }
-
- setConversionRate (conversionRate) {
- this.store.updateState({ conversionRate })
- }
-
- getConversionDate () {
- return this.store.getState().conversionDate
- }
-
- setConversionDate (conversionDate) {
- this.store.updateState({ conversionDate })
- }
-
- updateConversionRate () {
- const currentCurrency = this.getCurrentCurrency()
- return fetch(`https://www.cryptonator.com/api/ticker/eth-${currentCurrency}`)
- .then(response => response.json())
- .then((parsedResponse) => {
- this.setConversionRate(Number(parsedResponse.ticker.price))
- this.setConversionDate(Number(parsedResponse.timestamp))
- }).catch((err) => {
- console.warn('MetaMask - Failed to query currency conversion.')
- this.setConversionRate(0)
- this.setConversionDate('N/A')
- })
- }
-
- scheduleConversionInterval () {
- if (this.conversionInterval) {
- clearInterval(this.conversionInterval)
- }
- this.conversionInterval = setInterval(() => {
- this.updateConversionRate()
- }, POLLING_INTERVAL)
- }
-}
-
-module.exports = CurrencyController