aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorDan Finlay <flyswatter@users.noreply.github.com>2017-03-09 02:16:50 +0800
committerGitHub <noreply@github.com>2017-03-09 02:16:50 +0800
commit67c3126e63aa073d4426b751004c357ee7ed7d60 (patch)
tree815f163d7983225c56a165dd26b7bc33d96bdad1 /app/scripts/lib
parent92b8443824bffca219b146028d5685e6aa1ffabf (diff)
parent26cac57838edc0783e42350d71c45d989329cf2a (diff)
downloadtangerine-wallet-browser-67c3126e63aa073d4426b751004c357ee7ed7d60.tar.gz
tangerine-wallet-browser-67c3126e63aa073d4426b751004c357ee7ed7d60.tar.zst
tangerine-wallet-browser-67c3126e63aa073d4426b751004c357ee7ed7d60.zip
Merge branch 'master' into kumavis-patch-1
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/controllers/currency.js70
-rw-r--r--app/scripts/lib/controllers/preferences.js33
-rw-r--r--app/scripts/lib/controllers/shapeshift.js104
3 files changed, 0 insertions, 207 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
diff --git a/app/scripts/lib/controllers/preferences.js b/app/scripts/lib/controllers/preferences.js
deleted file mode 100644
index c5e93a5b9..000000000
--- a/app/scripts/lib/controllers/preferences.js
+++ /dev/null
@@ -1,33 +0,0 @@
-const ObservableStore = require('obs-store')
-const normalizeAddress = require('eth-sig-util').normalize
-
-class PreferencesController {
-
- constructor (opts = {}) {
- const initState = opts.initState || {}
- this.store = new ObservableStore(initState)
- }
-
- //
- // PUBLIC METHODS
- //
-
- setSelectedAddress(_address) {
- return new Promise((resolve, reject) => {
- const address = normalizeAddress(_address)
- this.store.updateState({ selectedAddress: address })
- resolve()
- })
- }
-
- getSelectedAddress(_address) {
- return this.store.getState().selectedAddress
- }
-
- //
- // PRIVATE METHODS
- //
-
-}
-
-module.exports = PreferencesController
diff --git a/app/scripts/lib/controllers/shapeshift.js b/app/scripts/lib/controllers/shapeshift.js
deleted file mode 100644
index 3d955c01f..000000000
--- a/app/scripts/lib/controllers/shapeshift.js
+++ /dev/null
@@ -1,104 +0,0 @@
-const ObservableStore = require('obs-store')
-const extend = require('xtend')
-
-// every three seconds when an incomplete tx is waiting
-const POLLING_INTERVAL = 3000
-
-class ShapeshiftController {
-
- constructor (opts = {}) {
- const initState = extend({
- shapeShiftTxList: [],
- }, opts.initState)
- this.store = new ObservableStore(initState)
- this.pollForUpdates()
- }
-
- //
- // PUBLIC METHODS
- //
-
- getShapeShiftTxList () {
- const shapeShiftTxList = this.store.getState().shapeShiftTxList
- return shapeShiftTxList
- }
-
- getPendingTxs () {
- const txs = this.getShapeShiftTxList()
- const pending = txs.filter(tx => tx.response && tx.response.status !== 'complete')
- return pending
- }
-
- pollForUpdates () {
- const pendingTxs = this.getPendingTxs()
-
- if (pendingTxs.length === 0) {
- return
- }
-
- Promise.all(pendingTxs.map((tx) => {
- return this.updateTx(tx)
- }))
- .then((results) => {
- results.forEach(tx => this.saveTx(tx))
- this.timeout = setTimeout(this.pollForUpdates.bind(this), POLLING_INTERVAL)
- })
- }
-
- updateTx (tx) {
- const url = `https://shapeshift.io/txStat/${tx.depositAddress}`
- return fetch(url)
- .then((response) => {
- return response.json()
- }).then((json) => {
- tx.response = json
- if (tx.response.status === 'complete') {
- tx.time = new Date().getTime()
- }
- return tx
- })
- }
-
- saveTx (tx) {
- const { shapeShiftTxList } = this.store.getState()
- const index = shapeShiftTxList.indexOf(tx)
- if (index !== -1) {
- shapeShiftTxList[index] = tx
- this.store.updateState({ shapeShiftTxList })
- }
- }
-
- removeShapeShiftTx (tx) {
- const { shapeShiftTxList } = this.store.getState()
- const index = shapeShiftTxList.indexOf(index)
- if (index !== -1) {
- shapeShiftTxList.splice(index, 1)
- }
- this.updateState({ shapeShiftTxList })
- }
-
- createShapeShiftTx (depositAddress, depositType) {
- const state = this.store.getState()
- let { shapeShiftTxList } = state
-
- var shapeShiftTx = {
- depositAddress,
- depositType,
- key: 'shapeshift',
- time: new Date().getTime(),
- response: {},
- }
-
- if (!shapeShiftTxList) {
- shapeShiftTxList = [shapeShiftTx]
- } else {
- shapeShiftTxList.push(shapeShiftTx)
- }
-
- this.store.updateState({ shapeShiftTxList })
- this.pollForUpdates()
- }
-
-}
-
-module.exports = ShapeshiftController