fix fiatBalance callers
This commit is contained in:
parent
910bdd5f69
commit
5d6cc78b37
3 changed files with 20 additions and 13 deletions
|
|
@ -788,17 +788,20 @@ function checkNotification () {
|
||||||
|
|
||||||
function checkBalances () {
|
function checkBalances () {
|
||||||
const cryptoCodes = exports.getCryptoCodes()
|
const cryptoCodes = exports.getCryptoCodes()
|
||||||
|
return db.devices()
|
||||||
|
.then(rows => {
|
||||||
|
const balances = []
|
||||||
|
cryptoCodes.forEach(cryptoCode => {
|
||||||
|
const minBalance = rows.map(r => exports.fiatBalance(cryptoCode, r.device_id).balance)
|
||||||
|
.reduce((min, cur) => Math.min(min, cur), Infinity)
|
||||||
|
|
||||||
const balances = []
|
if (!balanceRec) return
|
||||||
cryptoCodes.forEach(cryptoCode => {
|
const rec = {fiatBalance: minBalance, cryptoCode, fiatCode: deviceCurrency}
|
||||||
const balanceRec = exports.fiatBalance(cryptoCode)
|
balances.push(rec)
|
||||||
if (!balanceRec) return
|
})
|
||||||
const rec = {fiatBalance: balanceRec.balance, cryptoCode,
|
|
||||||
fiatCode: deviceCurrency}
|
return balances
|
||||||
balances.push(rec)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return balances
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.startCheckingNotification = function startCheckingNotification () {
|
exports.startCheckingNotification = function startCheckingNotification () {
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,12 @@ function buildRates (deviceId) {
|
||||||
return rates
|
return rates
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildBalances () {
|
function buildBalances (deviceId) {
|
||||||
const cryptoCodes = plugins.getCryptoCodes()
|
const cryptoCodes = plugins.getCryptoCodes()
|
||||||
|
|
||||||
const _balances = {}
|
const _balances = {}
|
||||||
cryptoCodes.forEach(cryptoCode => {
|
cryptoCodes.forEach(cryptoCode => {
|
||||||
const balanceRec = plugins.fiatBalance(cryptoCode)
|
const balanceRec = plugins.fiatBalance(cryptoCode, deviceId)
|
||||||
if (!balanceRec) return logger.warn('No balance for ' + cryptoCode + ' yet')
|
if (!balanceRec) return logger.warn('No balance for ' + cryptoCode + ' yet')
|
||||||
if (Date.now() - balanceRec.timestamp > STALE_BALANCE) return logger.warn('Stale balance for ' + cryptoCode)
|
if (Date.now() - balanceRec.timestamp > STALE_BALANCE) return logger.warn('Stale balance for ' + cryptoCode)
|
||||||
_balances[cryptoCode] = balanceRec.balance
|
_balances[cryptoCode] = balanceRec.balance
|
||||||
|
|
@ -69,7 +69,7 @@ function poll (req, res) {
|
||||||
let balances = {}
|
let balances = {}
|
||||||
|
|
||||||
rates = buildRates(deviceId)
|
rates = buildRates(deviceId)
|
||||||
balances = buildBalances()
|
balances = buildBalances(deviceId)
|
||||||
|
|
||||||
const config = plugins.getConfig(deviceId)
|
const config = plugins.getConfig(deviceId)
|
||||||
|
|
||||||
|
|
|
||||||
6
todo.txt
6
todo.txt
|
|
@ -98,4 +98,8 @@ options: configure per machine; configure per crypto/fiat
|
||||||
- what to do if validation fails?
|
- what to do if validation fails?
|
||||||
|
|
||||||
- need to rethink cachedConfig, don't use global variables [later]
|
- need to rethink cachedConfig, don't use global variables [later]
|
||||||
- add notifications to admin
|
|
||||||
|
-------------
|
||||||
|
|
||||||
|
- fiatBalance should really be per machine
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue