Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Commit

Permalink
Improve error handling in frontend (#60)
Browse files Browse the repository at this point in the history
Closes #36
  • Loading branch information
garatortiz committed Aug 3, 2018
1 parent a78e1bd commit 2a6b6f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions blockchain/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
39 changes: 25 additions & 14 deletions frontend/src/PoBA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
}

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/alerts.js
Original file line number Diff line number Diff line change
@@ -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'
})
Expand Down

0 comments on commit 2a6b6f5

Please sign in to comment.