better of handling of wallet balance errors

This commit is contained in:
Josh Harvey 2017-07-12 20:41:06 +03:00
parent fafac16742
commit 066c278ed8

View file

@ -39,10 +39,20 @@ function fetchWallet (settings, cryptoCode) {
})
}
const lastBalance = {}
function balance (settings, cryptoCode) {
return fetchWallet(settings, cryptoCode)
.then(r => r.wallet.balance(r.account, cryptoCode))
.then(balance => ({balance, timestamp: Date.now()}))
.then(r => {
lastBalance[cryptoCode] = r
return r
})
.catch(err => {
console.error(err)
return lastBalance[cryptoCode]
})
}
function sendCoins (settings, toAddress, cryptoAtoms, cryptoCode) {