fix all clear notification

This commit is contained in:
Josh Harvey 2016-12-12 18:18:26 +02:00
parent 77f487c03c
commit a4b35bab05
2 changed files with 16 additions and 11 deletions

View file

@ -162,7 +162,7 @@ function emailAlert (alert) {
const stuckAge = prettyMs(alert.age, {compact: true, verbose: true}) const stuckAge = prettyMs(alert.age, {compact: true, verbose: true})
return 'Machine is stuck on ' + alert.state + 'screen for ' + stuckAge return 'Machine is stuck on ' + alert.state + 'screen for ' + stuckAge
case 'lowBalance': case 'lowBalance':
const balance = formatCurrency(alert.fiatBalance, alert.fiatCode) const balance = formatCurrency(alert.fiatBalance.balance, alert.fiatCode)
return 'Low balance of ' + balance + ' in ' + alert.cryptoCode + ' wallet' return 'Low balance of ' + balance + ' in ' + alert.cryptoCode + ' wallet'
} }
} }
@ -190,10 +190,13 @@ function printEmailAlerts (alertRec) {
function alertSubject (alertRec) { function alertSubject (alertRec) {
let alerts = alertRec.general let alerts = alertRec.general
R.keys(alertRec.devices).forEach(function (device) { R.keys(alertRec.devices).forEach(function (device) {
alerts = R.concat(alerts, alertRec.devices[device]) alerts = R.concat(alerts, alertRec.devices[device])
}) })
if (alerts.length === 0) return null if (alerts.length === 0) return null
const alertTypes = R.uniq(R.pluck('code', alerts)).sort() const alertTypes = R.uniq(R.pluck('code', alerts)).sort()
return '[Lamassu] Errors reported: ' + alertTypes.join(', ') return '[Lamassu] Errors reported: ' + alertTypes.join(', ')
} }

View file

@ -1,5 +1,5 @@
const uuid = require('uuid') const uuid = require('uuid')
const R = require('ramda') const _ = require('lodash/fp')
const BigNumber = require('bignumber.js') const BigNumber = require('bignumber.js')
const argv = require('minimist')(process.argv.slice(2)) const argv = require('minimist')(process.argv.slice(2))
const crypto = require('crypto') const crypto = require('crypto')
@ -206,7 +206,7 @@ function plugins (settings) {
return wallet.newAddress(settings, cryptoCode, info) return wallet.newAddress(settings, cryptoCode, info)
.then(address => { .then(address => {
const newTx = R.assoc('toAddress', address, tx) const newTx = _.set('toAddress', address, tx)
return dbm.addInitialIncoming(deviceId, newTx, address) return dbm.addInitialIncoming(deviceId, newTx, address)
.then(() => address) .then(() => address)
@ -323,7 +323,6 @@ function plugins (settings) {
const filtered = marketTradesQueues const filtered = marketTradesQueues
.filter(tradeEntry => { .filter(tradeEntry => {
console.log('DEBUG33: %j, %s, %s, %s', tradeEntry, t1, tradeEntry.timestamp, TRADE_TTL)
return t1 - tradeEntry.timestamp < TRADE_TTL return t1 - tradeEntry.timestamp < TRADE_TTL
}) })
@ -366,7 +365,7 @@ function plugins (settings) {
return cryptoCodes.map(cryptoCode => ({fiatCode, cryptoCode})) return cryptoCodes.map(cryptoCode => ({fiatCode, cryptoCode}))
}) })
const tradesPromises = R.uniq(R.flatten(lists)) const tradesPromises = _.uniq(_.flatten(lists))
.map(r => executeTradesForMarket(settings, r.fiatCode, r.cryptoCode)) .map(r => executeTradesForMarket(settings, r.fiatCode, r.cryptoCode))
return Promise.all(tradesPromises) return Promise.all(tradesPromises)
@ -426,10 +425,11 @@ function plugins (settings) {
}) })
} }
function checkBalance (settings, rec) { function checkBalance (rec) {
const config = configManager.unscoped(settings.config) const config = configManager.unscoped(settings.config)
const lowBalanceThreshold = config.lowBalanceThreshold const lowBalanceThreshold = config.lowBalanceThreshold
return lowBalanceThreshold && rec.fiatBalance < lowBalanceThreshold
return rec.fiatBalance.balance <= lowBalanceThreshold
? {code: 'lowBalance', cryptoCode: rec.cryptoCode, fiatBalance: rec.fiatBalance, fiatCode: rec.fiatCode} ? {code: 'lowBalance', cryptoCode: rec.cryptoCode, fiatBalance: rec.fiatBalance, fiatCode: rec.fiatCode}
: null : null
} }
@ -442,12 +442,14 @@ function plugins (settings) {
return Promise.all(deviceBalancePromises) return Promise.all(deviceBalancePromises)
.then(arr => { .then(arr => {
const toMarket = r => r.fiatBalance + r.cryptoCode const toMarket = r => [r.fiatCode, r.cryptoCode].join('')
const min = R.minBy(r => r.fiatBalance) const min = _.minBy(r => r.fiatBalance)
return R.values(R.reduceBy(min, Infinity, toMarket, R.flatten(arr))) const byMarket = _.groupBy(toMarket, _.flatten(arr))
const minByMarket = _.flatMap(min, byMarket)
return _.reject(_.isNil, _.map(checkBalance, minByMarket))
}) })
}) })
.then(balances => R.reject(R.isNil, balances.map(balance => checkBalance)))
} }
function randomCode () { function randomCode () {