|
|
@ -4,6 +4,9 @@ const extend = require('xtend') |
|
|
|
// every three seconds when an incomplete tx is waiting
|
|
|
|
// every three seconds when an incomplete tx is waiting
|
|
|
|
const POLLING_INTERVAL = 3000 |
|
|
|
const POLLING_INTERVAL = 3000 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// drop txs that haven't been paid to in 11 mins
|
|
|
|
|
|
|
|
const TIMEOUT_LIMIT = 660000 |
|
|
|
|
|
|
|
|
|
|
|
class ShapeshiftController { |
|
|
|
class ShapeshiftController { |
|
|
|
|
|
|
|
|
|
|
|
constructor (opts = {}) { |
|
|
|
constructor (opts = {}) { |
|
|
@ -24,11 +27,21 @@ class ShapeshiftController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getPendingTxs () { |
|
|
|
getPendingTxs () { |
|
|
|
|
|
|
|
this.removeOldTxs() |
|
|
|
const txs = this.getShapeShiftTxList() |
|
|
|
const txs = this.getShapeShiftTxList() |
|
|
|
const pending = txs.filter(tx => tx.response && tx.response.status !== 'complete') |
|
|
|
const pending = txs.filter(tx => tx.response && tx.response.status !== 'complete') |
|
|
|
return pending |
|
|
|
return pending |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
removeOldTxs() { |
|
|
|
|
|
|
|
const { shapeShiftTxList } = this.store.getState() |
|
|
|
|
|
|
|
const now = new Date().getTime() |
|
|
|
|
|
|
|
const old = shapeShiftTxList.find((tx) => { |
|
|
|
|
|
|
|
return tx.time + TIMEOUT_LIMIT < now |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
old.forEach(tx => this.removeShapeShiftTx(tx)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pollForUpdates () { |
|
|
|
pollForUpdates () { |
|
|
|
const pendingTxs = this.getPendingTxs() |
|
|
|
const pendingTxs = this.getPendingTxs() |
|
|
|
|
|
|
|
|
|
|
@ -68,6 +81,15 @@ class ShapeshiftController { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
createShapeShiftTx (depositAddress, depositType) { |
|
|
|
const state = this.store.getState() |
|
|
|
const state = this.store.getState() |
|
|
|
let { shapeShiftTxList } = state |
|
|
|
let { shapeShiftTxList } = state |
|
|
|