Take machineid into account for coinatmradar rates (#301)
* Take machineid into account for coinatmradar rates * Remove test leftovers
This commit is contained in:
parent
98cc3b18b7
commit
1a53ce5fa1
4 changed files with 21 additions and 14 deletions
|
|
@ -10,6 +10,7 @@ const mnemonicHelpers = require('../mnemonic-helpers')
|
|||
const configManager = require('../config-manager')
|
||||
const options = require('../options')
|
||||
const logger = require('../logger')
|
||||
const plugins = require('../plugins')
|
||||
|
||||
const TIMEOUT = 10000
|
||||
const MAX_CONTENT_LENGTH = 2000
|
||||
|
|
@ -19,9 +20,9 @@ const STALE_INTERVAL = '2 minutes'
|
|||
|
||||
module.exports = { update, mapRecord }
|
||||
|
||||
function mapCoin (info, deviceId, cryptoCode) {
|
||||
function mapCoin (info, deviceId, settings, cryptoCode) {
|
||||
const config = info.config
|
||||
const rates = info.rates[cryptoCode] || { cashIn: null, cashOut: null }
|
||||
const rates = plugins(settings, deviceId).buildRates(info.rates)[cryptoCode] || { cashIn: null, cashOut: null }
|
||||
const cryptoConfig = configManager.scoped(cryptoCode, deviceId, config)
|
||||
const unscoped = configManager.unscoped(config)
|
||||
const showRates = unscoped.coinAtmRadarShowRates
|
||||
|
|
@ -52,7 +53,7 @@ function mapIdentification (info, deviceId) {
|
|||
}
|
||||
}
|
||||
|
||||
function mapMachine (info, machineRow) {
|
||||
function mapMachine (info, settings, machineRow) {
|
||||
const deviceId = machineRow.device_id
|
||||
const config = info.config
|
||||
const machineConfig = configManager.machineScoped(deviceId, config)
|
||||
|
|
@ -66,7 +67,7 @@ function mapMachine (info, machineRow) {
|
|||
|
||||
const cryptoCurrencies = machineConfig.cryptoCurrencies
|
||||
const identification = mapIdentification(info, deviceId)
|
||||
const coins = _.map(_.partial(mapCoin, [info, deviceId]), cryptoCurrencies)
|
||||
const coins = _.map(_.partial(mapCoin, [info, deviceId, settings]), cryptoCurrencies)
|
||||
|
||||
return {
|
||||
machineId: deviceId,
|
||||
|
|
@ -97,14 +98,14 @@ function mapMachine (info, machineRow) {
|
|||
}
|
||||
}
|
||||
|
||||
function getMachines (info) {
|
||||
function getMachines (info, settings) {
|
||||
const sql = `select device_id, last_online, now() - last_online < $1 as stale from devices
|
||||
where display=TRUE and
|
||||
paired=TRUE
|
||||
order by created`
|
||||
|
||||
return db.any(sql, [STALE_INTERVAL])
|
||||
.then(_.map(_.partial(mapMachine, [info])))
|
||||
.then(_.map(_.partial(mapMachine, [info, settings])))
|
||||
}
|
||||
|
||||
function sendRadar (data) {
|
||||
|
|
@ -128,9 +129,9 @@ function sendRadar (data) {
|
|||
.then(r => console.log(r.status))
|
||||
}
|
||||
|
||||
function mapRecord (info) {
|
||||
function mapRecord (info, settings) {
|
||||
const timestamp = new Date().toISOString()
|
||||
return Promise.all([getMachines(info), fs.readFile(options.mnemonicPath, 'utf8')])
|
||||
return Promise.all([getMachines(info, settings), fs.readFile(options.mnemonicPath, 'utf8')])
|
||||
.then(([machines, mnemonic]) => {
|
||||
return {
|
||||
operatorId: computeOperatorId(mnemonicHelpers.toEntropyBuffer(mnemonic)),
|
||||
|
|
@ -145,12 +146,12 @@ function mapRecord (info) {
|
|||
})
|
||||
}
|
||||
|
||||
function update (info) {
|
||||
function update (info, settings) {
|
||||
const config = configManager.unscoped(info.config)
|
||||
|
||||
if (!config.coinAtmRadarActive) return Promise.resolve()
|
||||
|
||||
return mapRecord(info)
|
||||
return mapRecord(info, settings)
|
||||
.then(sendRadar)
|
||||
.catch(err => logger.error(`Failure to update CoinATMRadar`, err))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue