Feat: crypto balance notifications saving in DB

Chore: add new column "detail" to transactions table migration

Feat: check if older notification is valid before sending new one

Feat: error saving to database

Fix: fix error when invalidating notification on
clearCryptoBalanceNotifications
Chre: code refactor in new-settings-loader for simplicity
Chore: refactor code on notifier and merge similar functions
This commit is contained in:
Cesar 2020-12-10 18:26:13 +00:00 committed by Josh Harvey
parent 196a05549f
commit 3b3bdf839b
9 changed files with 224 additions and 34 deletions

View file

@ -1,5 +1,5 @@
const _ = require('lodash/fp')
const prettyMs = require('pretty-ms')
const utils = require("./utils")
const email = require('../email')
@ -66,28 +66,24 @@ function emailAlerts(alerts) {
return alerts.map(emailAlert).join('\n') + '\n'
}
function formatCurrency(num, code) {
return numeral(num).format('0,0.00') + ' ' + code
}
function emailAlert(alert) {
switch (alert.code) {
case PING:
if (alert.age) {
const pingAge = prettyMs(alert.age, { compact: true, verbose: true })
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 = prettyMs(alert.age, { compact: true, verbose: true })
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 = formatCurrency(alert.fiatBalance.balance, alert.fiatCode)
const balance = utils.formatCurrency(alert.fiatBalance.balance, alert.fiatCode)
return `Low balance in ${alert.cryptoCode} [${balance}]`
}
case HIGH_CRYPTO_BALANCE: {
const highBalance = formatCurrency(
const highBalance = utils.formatCurrency(
alert.fiatBalance.balance,
alert.fiatCode
)