works with l-m again
This commit is contained in:
parent
5d6cc78b37
commit
03edd9c7e0
5 changed files with 62 additions and 51 deletions
|
|
@ -297,9 +297,9 @@ function buildCartridges (cartridges, virtualCartridges, rec) {
|
|||
|
||||
exports.pollQueries = function pollQueries (deviceId) {
|
||||
const config = getConfig(deviceId)
|
||||
const cartridges = [ config.fiat.topCashOutDenomination,
|
||||
config.fiat.bottomCashOutDenomination ]
|
||||
const virtualCartridges = [config.fiat.virtualCashOutDenomination]
|
||||
const cartridges = [ config.currencies.topCashOutDenomination,
|
||||
config.currencies.bottomCashOutDenomination ]
|
||||
const virtualCartridges = [config.currencies.virtualCashOutDenomination]
|
||||
|
||||
return db.cartridgeCounts(deviceId)
|
||||
.then(result => ({
|
||||
|
|
@ -426,8 +426,8 @@ exports.cashOut = function cashOut (deviceId, tx) {
|
|||
exports.dispenseAck = function (deviceId, tx) {
|
||||
console.log('DEBUG23: %j', tx)
|
||||
const config = getConfig(deviceId)
|
||||
const cartridges = [ config.fiat.topCashOutDenomination,
|
||||
config.fiat.bottomCashOutDenomination ]
|
||||
const cartridges = [ config.currencies.topCashOutDenomination,
|
||||
config.currencies.bottomCashOutDenomination ]
|
||||
|
||||
return db.addDispense(deviceId, tx, cartridges)
|
||||
}
|
||||
|
|
@ -707,12 +707,6 @@ exports.verifyTx = function verifyTx (data, cb) {
|
|||
idVerifierPlugin.verifyTransaction(data, cb)
|
||||
}
|
||||
|
||||
function getCryptoCodes () {
|
||||
console.log('DEBUG17 TODO: generalize')
|
||||
return ['BTC']
|
||||
}
|
||||
exports.getCryptoCodes = getCryptoCodes
|
||||
|
||||
function sendMessage (rec) {
|
||||
const pluginPromises = []
|
||||
const config = configManager.unscoped(cachedConfig)
|
||||
|
|
@ -786,16 +780,30 @@ function checkNotification () {
|
|||
})
|
||||
}
|
||||
|
||||
function checkBalances () {
|
||||
const cryptoCodes = exports.getCryptoCodes()
|
||||
function getCryptoCodes (deviceId) {
|
||||
return configManager.machineScoped(deviceId, cachedConfig).currencies.cryptoCurrencies
|
||||
}
|
||||
exports.getCryptoCodes = getCryptoCodes
|
||||
|
||||
// Get union of all cryptoCodes from all machines
|
||||
function getAllCryptoCodes () {
|
||||
return db.devices()
|
||||
.then(rows => {
|
||||
return rows.reduce((acc, r) => getCryptoCodes(r.device_id).forEach(c => acc.add(c)), new Set())
|
||||
})
|
||||
}
|
||||
|
||||
function checkBalances () {
|
||||
return Promise.all(getAllCryptoCodes(), db.devices())
|
||||
.then(arr => {
|
||||
const cryptoCodes = arr[0]
|
||||
const deviceIds = arr[1].map(r => r.device_id)
|
||||
const balances = []
|
||||
|
||||
cryptoCodes.forEach(cryptoCode => {
|
||||
const minBalance = rows.map(r => exports.fiatBalance(cryptoCode, r.device_id).balance)
|
||||
const minBalance = deviceIds.map(deviceId => exports.fiatBalance(cryptoCode, deviceId).balance)
|
||||
.reduce((min, cur) => Math.min(min, cur), Infinity)
|
||||
|
||||
if (!balanceRec) return
|
||||
const rec = {fiatBalance: minBalance, cryptoCode, fiatCode: deviceCurrency}
|
||||
balances.push(rec)
|
||||
})
|
||||
|
|
@ -806,9 +814,12 @@ function checkBalances () {
|
|||
|
||||
exports.startCheckingNotification = function startCheckingNotification () {
|
||||
const config = configManager.unscoped(cachedConfig)
|
||||
notifier.init(db, checkBalances, config.notifications)
|
||||
checkNotification()
|
||||
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
|
||||
return checkBalances()
|
||||
.then(balances => {
|
||||
notifier.init(db, balances, config.notifications)
|
||||
checkNotification()
|
||||
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
|
||||
})
|
||||
}
|
||||
|
||||
exports.getPhoneCode = function getPhoneCode (phone) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue