Feat: save highVolumeTxs on DB and plugins code refactor
Fix: remove unused module and add space before '('
Chore: add jest tests for transactionNotify
This commit is contained in:
parent
75bfb4b991
commit
2ced230020
8 changed files with 646 additions and 414 deletions
|
|
@ -1,5 +1,7 @@
|
|||
const _ = require('lodash/fp')
|
||||
const crypto = require('crypto')
|
||||
|
||||
const coinUtils = require('../coin-utils')
|
||||
const {
|
||||
CODES_DISPLAY,
|
||||
NETWORK_DOWN_TIME,
|
||||
|
|
@ -96,6 +98,51 @@ function sendNoAlerts(plugins, smsEnabled, emailEnabled) {
|
|||
return plugins.sendMessage(rec)
|
||||
}
|
||||
|
||||
const buildTransactionMessage = (tx, rec, highValueTx, machineName, customer) => {
|
||||
const isCashOut = tx.direction === 'cashOut'
|
||||
const direction = isCashOut ? 'Cash Out' : 'Cash In'
|
||||
const crypto = `${coinUtils.toUnit(tx.cryptoAtoms, tx.cryptoCode)} ${
|
||||
tx.cryptoCode
|
||||
}`
|
||||
const fiat = `${tx.fiat} ${tx.fiatCode}`
|
||||
const customerName = customer.name || customer.id
|
||||
const phone = customer.phone ? `- Phone: ${customer.phone}` : ''
|
||||
|
||||
let status = null
|
||||
if (rec.error) {
|
||||
status = `Error - ${rec.error}`
|
||||
} else {
|
||||
status = !isCashOut
|
||||
? 'Successful'
|
||||
: !rec.isRedemption
|
||||
? 'Successful & awaiting redemption'
|
||||
: 'Successful & dispensed'
|
||||
}
|
||||
|
||||
const body = `
|
||||
- Transaction ID: ${tx.id}
|
||||
- Status: ${status}
|
||||
- Machine name: ${machineName}
|
||||
- ${direction}
|
||||
- ${fiat}
|
||||
- ${crypto}
|
||||
- Customer: ${customerName}
|
||||
${phone}
|
||||
`
|
||||
const smsSubject = `A ${highValueTx ? 'high value ' : ''}${direction.toLowerCase()} transaction just happened at ${machineName} for ${fiat}`
|
||||
const emailSubject = `A ${highValueTx ? 'high value ' : ''}transaction just happened`
|
||||
|
||||
return [{
|
||||
sms: {
|
||||
body: `${smsSubject} – ${status}`
|
||||
},
|
||||
email: {
|
||||
emailSubject,
|
||||
body
|
||||
}
|
||||
}, highValueTx]
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
codeDisplay,
|
||||
parseEventNote,
|
||||
|
|
@ -107,5 +154,6 @@ module.exports = {
|
|||
setAlertFingerprint,
|
||||
shouldNotAlert,
|
||||
buildAlertFingerprint,
|
||||
sendNoAlerts
|
||||
sendNoAlerts,
|
||||
buildTransactionMessage
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue