From e2f36d493512874fe0c3494ea9ecedff88e6dc16 Mon Sep 17 00:00:00 2001 From: janherich Date: Mon, 25 Sep 2017 10:32:57 +0200 Subject: [PATCH] Be more defensive when checking user balance --- resources/js/bots/wallet/bot.js | 15 ++++++++++++++- resources/js/bots/wallet/translations.js | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/resources/js/bots/wallet/bot.js b/resources/js/bots/wallet/bot.js index f6d32279ff..8426079fd4 100644 --- a/resources/js/bots/wallet/bot.js +++ b/resources/js/bots/wallet/bot.js @@ -321,7 +321,20 @@ function validateSend(params, context) { }; } - var balance = web3.eth.getBalance(context.from); + try { + var balance = web3.eth.getBalance(context.from); + if (isNaN(balance)) { + throw new Error(); + } + } catch (err) { + return { + markup: status.components.validationMessage( + I18n.t('validation_internal_title'), + I18n.t('validation_balance') + ) + }; + } + var fee = calculateFee( params["bot-db"]["sliderValue"], { diff --git a/resources/js/bots/wallet/translations.js b/resources/js/bots/wallet/translations.js index 13af3ac9eb..814f31aca0 100644 --- a/resources/js/bots/wallet/translations.js +++ b/resources/js/bots/wallet/translations.js @@ -22,6 +22,8 @@ I18n.translations = { request_requesting: 'Requesting ', request_requesting_from: 'from ', + validation_internal_title: 'Internal error', + validation_balance: 'Could not fetch current balance', validation_title: 'Amount', validation_tx_title: 'Transaction', validation_tx_failed: 'Transaction failed',