From 066c278ed8d5275c34f35941348d683f2570885d Mon Sep 17 00:00:00 2001 From: Josh Harvey Date: Wed, 12 Jul 2017 20:41:06 +0300 Subject: [PATCH] better of handling of wallet balance errors --- lib/wallet.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/wallet.js b/lib/wallet.js index 033a2ea3..6285c1bf 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -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) {