This commit is contained in:
Josh Harvey 2016-04-23 21:54:46 +03:00
parent 8a4b447db3
commit e930925818
5 changed files with 15 additions and 31 deletions

View file

@ -5,9 +5,18 @@ var numeral = require('numeral')
var db = null
var getBalances = null
function init (_db, _getBalances) {
var LOW_BALANCE_THRESHOLD = 1000
var STALE_STATE = 2 * 60 * 1000
var NETWORK_DOWN_TIME = 60 * 1000
function init (_db, _getBalances, config) {
db = _db
getBalances = _getBalances
console.log(config)
if (config && config.lowBalanceThreshold) {
LOW_BALANCE_THRESHOLD = config.lowBalanceThreshold
}
}
exports.init = init
@ -22,7 +31,6 @@ function sameState (a, b) {
}
function checkBalance (rec) {
var LOW_BALANCE_THRESHOLD = 10
return rec.fiatBalance < LOW_BALANCE_THRESHOLD
? {code: 'lowBalance', cryptoCode: rec.cryptoCode, fiatBalance: rec.fiatBalance, fiatCode: rec.fiatCode}
: null
@ -36,7 +44,6 @@ function checkBalances () {
function checkPing (deviceEvents) {
var sortedEvents = R.sortBy(R.compose(toInt10, R.prop('device_time')), R.map(jsonParse, deviceEvents))
var lastEvent = R.last(sortedEvents)
var NETWORK_DOWN_TIME = 2 * 60 * 1000
if (!lastEvent) {
return [{code: 'ping'}]
@ -54,7 +61,6 @@ function checkStuckScreen (deviceEvents) {
var sortedEvents = R.sortBy(R.compose(toInt10, R.prop('device_time')), R.map(jsonParse, deviceEvents))
var noRepeatEvents = R.dropRepeatsWith(sameState, sortedEvents)
var lastEvent = R.last(noRepeatEvents)
var STALE_STATE = 60 * 1000
if (!lastEvent) {
return []