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 () {
|
||||
const cryptoCodes = exports.getCryptoCodes()
|
||||
|
||||
return db.devices()
|
||||
.then(rows => {
|
||||
const balances = []
|
||||
cryptoCodes.forEach(cryptoCode => {
|
||||
const balanceRec = exports.fiatBalance(cryptoCode)
|
||||
const minBalance = rows.map(r => exports.fiatBalance(cryptoCode, r.device_id).balance)
|
||||
.reduce((min, cur) => Math.min(min, cur), Infinity)
|
||||
|
||||
if (!balanceRec) return
|
||||
const rec = {fiatBalance: balanceRec.balance, cryptoCode,
|
||||
fiatCode: deviceCurrency}
|
||||
const rec = {fiatBalance: minBalance, cryptoCode, fiatCode: deviceCurrency}
|
||||
balances.push(rec)
|
||||
})
|
||||
|
||||
return balances
|
||||
})
|
||||
}
|
||||
|
||||
exports.startCheckingNotification = function startCheckingNotification () {
|
||||
|
|
|
|||
|
|
@ -41,12 +41,12 @@ function buildRates (deviceId) {
|
|||
return rates
|
||||
}
|
||||
|
||||
function buildBalances () {
|
||||
function buildBalances (deviceId) {
|
||||
const cryptoCodes = plugins.getCryptoCodes()
|
||||
|
||||
const _balances = {}
|
||||
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 (Date.now() - balanceRec.timestamp > STALE_BALANCE) return logger.warn('Stale balance for ' + cryptoCode)
|
||||
_balances[cryptoCode] = balanceRec.balance
|
||||
|
|
@ -69,7 +69,7 @@ function poll (req, res) {
|
|||
let balances = {}
|
||||
|
||||
rates = buildRates(deviceId)
|
||||
balances = buildBalances()
|
||||
balances = buildBalances(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?
|
||||
|
||||
- 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