feat: longer lifespan for filtered coins cache

This commit is contained in:
Sérgio Salgado 2020-12-24 13:46:11 +00:00 committed by Josh Harvey
parent 9808a67945
commit 2b1fd83a99
2 changed files with 15 additions and 2 deletions

View file

@ -45,6 +45,7 @@ function fetchWallet (settings, cryptoCode) {
const lastBalance = {}
function _balance (settings, cryptoCode) {
console.log('checking ' + cryptoCode + ' balance')
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.balance(r.account, cryptoCode))
.then(balance => ({ balance, timestamp: Date.now() }))
@ -209,11 +210,23 @@ function isStrictAddress (settings, cryptoCode, toAddress) {
})
}
const balance = mem(_balance, {
const coinFilter = ['ETH']
const balance = (settings, cryptoCode) => {
if (_.includes(coinFilter, cryptoCode)) return balanceFiltered(settings, cryptoCode)
return balanceUnfiltered(settings, cryptoCode)
}
const balanceUnfiltered = mem(_balance, {
maxAge: FETCH_INTERVAL,
cacheKey: (settings, cryptoCode) => cryptoCode
})
const balanceFiltered = mem(_balance, {
maxAge: 3 * FETCH_INTERVAL,
cacheKey: (settings, cryptoCode) => cryptoCode
})
module.exports = {
balance,
sendCoins,