aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/controllers/shapeshift.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/shapeshift.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/shapeshift.js')
-rw-r--r--app/scripts/lib/controllers/shapeshift.js104
1 files changed, 0 insertions, 104 deletions
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