From 2a6b6f56f1c3666efa52634290f16d34796c31c3 Mon Sep 17 00:00:00 2001 From: Matias Garat Ortiz Date: Fri, 3 Aug 2018 15:29:43 -0300 Subject: [PATCH] Improve error handling in frontend (#60) Closes #36 --- blockchain/.eslintignore | 1 + frontend/src/PoBA.js | 39 +++++++++++++++++++++++++-------------- frontend/src/alerts.js | 8 ++++---- 3 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 blockchain/.eslintignore diff --git a/blockchain/.eslintignore b/blockchain/.eslintignore new file mode 100644 index 0000000..4ebc8ae --- /dev/null +++ b/blockchain/.eslintignore @@ -0,0 +1 @@ +coverage diff --git a/frontend/src/PoBA.js b/frontend/src/PoBA.js index 0b00217..c5792d2 100644 --- a/frontend/src/PoBA.js +++ b/frontend/src/PoBA.js @@ -46,30 +46,41 @@ class PoBA extends Component { PobaContract.setProvider(web3.currentProvider) - this.pobaContract = await PobaContract.deployed() + try { + this.pobaContract = await PobaContract.deployed() - const registeredAcountsCount = await this.pobaContract.accountsLength.call(account) + const registeredAccountsCount = await this.pobaContract.accountsLength.call(account) - const whenAccounts = [] - for (let i = 0; i < registeredAcountsCount; i++) { - whenAccounts.push(this.pobaContract.accounts(account, i)) - } + const whenAccounts = [] + for (let i = 0; i < registeredAccountsCount; i++) { + whenAccounts.push(this.pobaContract.accounts(account, i)) + } - const registeredAccounts = await Promise.all(whenAccounts) + const registeredAccounts = await Promise.all(whenAccounts) - this.setState({ registeredAccounts }) + this.setState({ registeredAccounts }) + } catch (e) { + console.error('Contract is not deployed on this network', e) + errorAlert('Contract is not deployed on this network') + } } fetchBankAccounts = async token => { this.setState({ loading: true }) return getBankAccounts(token) - .then(bankAccounts => { - this.setState({ - token, - bankAccounts - }) - }) + .then( + bankAccounts => { + this.setState({ + token, + bankAccounts + }) + }, + e => { + console.error('There was a problem getting the bank accounts', e) + errorAlert('There was a problem getting the bank accounts') + } + ) .finally(() => this.setState({ loading: false })) } diff --git a/frontend/src/alerts.js b/frontend/src/alerts.js index ca72841..0c944f4 100644 --- a/frontend/src/alerts.js +++ b/frontend/src/alerts.js @@ -1,16 +1,16 @@ import sweetAlert2 from 'sweetalert2' -export function successAlert() { +export function successAlert(msg = 'Your bank account was successfully registered') { sweetAlert2({ - title: 'Bank account registration', - html: 'Your bank account was successfully registered', + title: 'Proof of Bank Account', + html: msg, type: 'success' }) } export function errorAlert(msg = 'There was a problem registering your bank account') { sweetAlert2({ - title: 'Bank account registration', + title: 'Proof of Bank Account', html: msg, type: 'error' })