feat: longer lifespan for filtered coins cache
This commit is contained in:
parent
9808a67945
commit
2b1fd83a99
2 changed files with 15 additions and 2 deletions
|
|
@ -29,7 +29,7 @@ const CHECK_NOTIFICATION_INTERVAL = 20 * T.seconds
|
||||||
|
|
||||||
const PENDING_INTERVAL = 10 * T.seconds
|
const PENDING_INTERVAL = 10 * T.seconds
|
||||||
|
|
||||||
const coinFilter = []
|
const coinFilter = ['ETH']
|
||||||
|
|
||||||
let _pi, _settings
|
let _pi, _settings
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ function fetchWallet (settings, cryptoCode) {
|
||||||
const lastBalance = {}
|
const lastBalance = {}
|
||||||
|
|
||||||
function _balance (settings, cryptoCode) {
|
function _balance (settings, cryptoCode) {
|
||||||
|
console.log('checking ' + cryptoCode + ' balance')
|
||||||
return fetchWallet(settings, cryptoCode)
|
return fetchWallet(settings, cryptoCode)
|
||||||
.then(r => r.wallet.balance(r.account, cryptoCode))
|
.then(r => r.wallet.balance(r.account, cryptoCode))
|
||||||
.then(balance => ({ balance, timestamp: Date.now() }))
|
.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,
|
maxAge: FETCH_INTERVAL,
|
||||||
cacheKey: (settings, cryptoCode) => cryptoCode
|
cacheKey: (settings, cryptoCode) => cryptoCode
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const balanceFiltered = mem(_balance, {
|
||||||
|
maxAge: 3 * FETCH_INTERVAL,
|
||||||
|
cacheKey: (settings, cryptoCode) => cryptoCode
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
balance,
|
balance,
|
||||||
sendCoins,
|
sendCoins,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue