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

Improve error handling in frontend #60

Merged
merged 6 commits into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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