aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-02-04 13:36:04 +0800
committerDan Finlay <dan@danfinlay.com>2017-02-04 13:36:04 +0800
commit5d37f90787cdeec130537e61626f92d6f8a7b5e3 (patch)
tree83b19e61e263ee2aef2667e1c5cbd2978879e0c1 /app
parentc9024655d3f4fa4d86735556e9e25f0eb63dfdb8 (diff)
downloadtangerine-wallet-browser-5d37f90787cdeec130537e61626f92d6f8a7b5e3.tar
tangerine-wallet-browser-5d37f90787cdeec130537e61626f92d6f8a7b5e3.tar.gz
tangerine-wallet-browser-5d37f90787cdeec130537e61626f92d6f8a7b5e3.tar.bz2
tangerine-wallet-browser-5d37f90787cdeec130537e61626f92d6f8a7b5e3.tar.lz
tangerine-wallet-browser-5d37f90787cdeec130537e61626f92d6f8a7b5e3.tar.xz
tangerine-wallet-browser-5d37f90787cdeec130537e61626f92d6f8a7b5e3.tar.zst
tangerine-wallet-browser-5d37f90787cdeec130537e61626f92d6f8a7b5e3.zip
Automatically remove shapeshift txs over 11 minutes old with no payment
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/controllers/shapeshift.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/app/scripts/lib/controllers/shapeshift.js b/app/scripts/lib/controllers/shapeshift.js
index bcfe3e14c..6d1c95323 100644
--- a/app/scripts/lib/controllers/shapeshift.js
+++ b/app/scripts/lib/controllers/shapeshift.js
@@ -4,6 +4,9 @@ const extend = require('xtend')
// every three seconds when an incomplete tx is waiting
const POLLING_INTERVAL = 3000
+// drop txs that haven't been paid to in 11 mins
+const TIMEOUT_LIMIT = 660000
+
class ShapeshiftController {
constructor (opts = {}) {
@@ -24,11 +27,21 @@ class ShapeshiftController {
}
getPendingTxs () {
+ this.removeOldTxs()
const txs = this.getShapeShiftTxList()
const pending = txs.filter(tx => tx.response && tx.response.status !== 'complete')
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 () {
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) {
const state = this.store.getState()
let { shapeShiftTxList } = state