Chore: fiatBalancesNotify refactor Chore: removed now-unused code in some files Feat: change column "detail" in database to use jsonb Chore: add notification center background and button Chore: notifications screen scaffolding Fix: change position of notification UI Feat: join backend and frontend Feat: notification icons and machine names Feat: add clear all button, stripe overlay on invalid notification Fix: rework notification styles Feat: use popper to render notifications Feat: make notification center UI Fix: fix css on notification center Fix: fix invalidateNotification Chore: apply PR requested changes Fix: PR fixes Fix: make toggleable body/root styles be handled by react Chore: delete old notifier file Fix: undo variable name changes for cryptobalance notifs
87 lines
2.5 KiB
JavaScript
87 lines
2.5 KiB
JavaScript
const _ = require('lodash/fp')
|
|
const utils = require('./utils')
|
|
|
|
const email = require('../email')
|
|
|
|
const {
|
|
PING,
|
|
STALE,
|
|
LOW_CRYPTO_BALANCE,
|
|
HIGH_CRYPTO_BALANCE,
|
|
CASH_BOX_FULL,
|
|
LOW_CASH_OUT
|
|
} = require('./codes')
|
|
|
|
function alertSubject (alertRec, config) {
|
|
let alerts = []
|
|
|
|
if (config.balance) {
|
|
alerts = _.concat(alerts, alertRec.general)
|
|
}
|
|
|
|
_.forEach(device => {
|
|
alerts = _.concat(alerts, utils.deviceAlerts(config, alertRec, device))
|
|
}, _.keys(alertRec.devices))
|
|
|
|
if (alerts.length === 0) return null
|
|
|
|
const alertTypes = _.flow(_.map('code'), _.uniq, _.map(utils.codeDisplay), _.sortBy(o => o))(alerts)
|
|
return '[Lamassu] Errors reported: ' + alertTypes.join(', ')
|
|
}
|
|
|
|
function printEmailAlerts (alertRec, config) {
|
|
let body = 'Errors were reported by your Lamassu Machines.\n'
|
|
|
|
if (config.balance && alertRec.general.length !== 0) {
|
|
body += '\nGeneral errors:\n'
|
|
body += emailAlerts(alertRec.general) + '\n'
|
|
}
|
|
|
|
_.forEach(device => {
|
|
const deviceName = alertRec.deviceNames[device]
|
|
body += '\nErrors for ' + deviceName + ':\n'
|
|
|
|
const alerts = utils.deviceAlerts(config, alertRec, device)
|
|
|
|
body += emailAlerts(alerts)
|
|
}, _.keys(alertRec.devices))
|
|
return body
|
|
}
|
|
|
|
function emailAlerts (alerts) {
|
|
return _.join('\n', _.map(emailAlert, alerts)) + '\n'
|
|
}
|
|
|
|
function emailAlert (alert) {
|
|
switch (alert.code) {
|
|
case PING:
|
|
if (alert.age) {
|
|
const pingAge = utils.formatAge(alert.age, { compact: true, verbose: true })
|
|
return `Machine down for ${pingAge}`
|
|
}
|
|
return 'Machine down for a while.'
|
|
case STALE: {
|
|
const stuckAge = utils.formatAge(alert.age, { compact: true, verbose: true })
|
|
return `Machine is stuck on ${alert.state} screen for ${stuckAge}`
|
|
}
|
|
case LOW_CRYPTO_BALANCE: {
|
|
const balance = utils.formatCurrency(alert.fiatBalance.balance, alert.fiatCode)
|
|
return `Low balance in ${alert.cryptoCode} [${balance}]`
|
|
}
|
|
case HIGH_CRYPTO_BALANCE: {
|
|
const highBalance = utils.formatCurrency(
|
|
alert.fiatBalance.balance,
|
|
alert.fiatCode
|
|
)
|
|
return `High balance in ${alert.cryptoCode} [${highBalance}]`
|
|
}
|
|
case CASH_BOX_FULL:
|
|
return `Cash box full on ${alert.machineName} [${alert.notes} banknotes]`
|
|
case LOW_CASH_OUT:
|
|
return `Cassette for ${alert.denomination} ${alert.fiatCode} low [${alert.notes} banknotes]`
|
|
}
|
|
}
|
|
|
|
const sendMessage = email.sendMessage
|
|
|
|
module.exports = { alertSubject, printEmailAlerts, sendMessage }
|