Skip to content

Commit

Permalink
Merge pull request #1138 from edenia/fix/improve-accounts-errors-mess…
Browse files Browse the repository at this point in the history
…ages-1120

feat(webapp): improve error message in Accounts and Contracts page
  • Loading branch information
xavier506 authored Jan 25, 2023
2 parents 1ffa545 + 1511c93 commit 23efc1b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 22 deletions.
8 changes: 4 additions & 4 deletions webapp/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"executeTransaction": "Execute Transaction",
"bugRequest": "Report a bug / Request a feature",
"moreInfo": "More Info",
"openLink": "Visit Site"
"openLink": "Visit Site",
"table": "Table"
},
"routes": {
"/>sidebar": "Dashboard",
Expand Down Expand Up @@ -164,12 +165,11 @@
"accountsRoute": {
"loginBeforeUseAction": "Please login before execute an action",
"unknownError": "Unknown error processing action",
"accountNotFound": "Account not found",
"tableNotFound": "Table not found",
"notFound": "not found",
"successMessage": "Success transaction",
"placeholder": "Account or Contract Name",
"title": "Search for account information, view tables and execute actions for any contract.",
"endpointFailure": "Endpoint failure"
"endpointFailure": "Endpoint failure. Try again later"
},
"bpJsonRoute": {
"loadText": "Loading node information . . .",
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/language/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
"footer2": "Desarrollado por Edenia",
"bugRequest": "Reportar un problema / Solicitar una característica ",
"moreInfo": "Más Información",
"openLink": "Visitar Sitio"
"openLink": "Visitar Sitio",
"table": "Tabla"
},
"routes": {
"/>sidebar": "Panel",
Expand Down Expand Up @@ -170,12 +171,11 @@
"accountsRoute": {
"loginBeforeUseAction": "Inicie sesión antes de ejecutar una acción",
"unknownError": "Error desconocido al procesar la acción",
"accountNotFound": "Cuenta no encontrada",
"tableNotFound": "Tabla no encontrada",
"notFound": "no encontrada",
"successMessage": "Transacción exitosa",
"placeholder": "Cuenta o Nombre del Contrato",
"title": "Busque información de cuenta, vea tablas y ejecute acciones para cualquier contrato.",
"endpointFailure": "Fallo en el endpoint"
"endpointFailure": "Fallo en el endpoint. Vuelva a intentarlo más tarde"
},
"bpJsonRoute": {
"loadText": "Cargando información del nodo . . .",
Expand Down
60 changes: 46 additions & 14 deletions webapp/src/routes/Accounts/useAccountState.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'
import queryString from 'query-string'

import { signTransaction } from '../../utils/eos'
import eosApi from '../../utils/eosapi'
import eosApi, { ENDPOINTS_ERROR } from '../../utils/eosapi'
import getTransactionUrl from '../../utils/get-transaction-url'
import { useSnackbarMessageState } from '../../context/snackbar-message.context'
import { useSharedState } from '../../context/state.context'
Expand Down Expand Up @@ -54,6 +54,20 @@ const useAccountState = () => {
INITIAL_ACCOUNT_STATE,
)

const getErrorMessage = useCallback((error, resultRequested = '') => {
if (error?.message === ENDPOINTS_ERROR) {
return t('endpointFailure')
} else {
try {
const actionError = JSON.parse(error?.message).error.details[0].message

return actionError ? `${resultRequested} ${t('notFound')}` : ''
} catch (error) {
return t('unknownError')
}
}
}, [t])

const handleSubmitAction = async (action) => {
if (!ual.activeUser) {
showMessage({
Expand Down Expand Up @@ -124,17 +138,18 @@ const useAccountState = () => {
} catch (error) {
showMessage({
type: 'error',
content: t('tableNotFound'),
content: getErrorMessage(error, `${t('table')} ${payload?.table}`),
})

console.log(error)
}
dispatch({ payload: false, type: 'SET_LOADING' })
},
[showMessage, t, state.tableData, state.loading],
[showMessage, getErrorMessage, t, state.tableData, state.loading],
)

const handleOnSearch = async (valueAccount) => {
const accountName = valueAccount?.owner ?? ''
const tableName = valueAccount?.table ?? ''

if (!accountName) return

Expand All @@ -147,27 +162,39 @@ const useAccountState = () => {
const account = await eosApi.getAccount(accountName)

dispatch({ payload: account, type: 'SET_ACCOUNT' })
} catch (error) {
showMessage({
type: 'error',
content: t('accountNotFound'),
})
}

try {
const { abi } = await eosApi.getAbi(accountName)

dispatch({ payload: abi, type: 'SET_ABI' })

if (abi?.tables?.length) {
const defaultTable =
accountName === 'eosio' ? 'producers' : abi?.tables[0]?.name
let tableName = valueAccount?.table ?? ''

if (tableName) {
tableName =
abi?.tables.find((table) => table.name === tableName)?.name ?? ''

if (!tableName) {
showMessage({
type: 'error',
content: t(
`${t('table')} ${valueAccount?.table} ${t('notFound')}`,
),
})
}
} else {
tableName =
accountName === 'eosio' &&
abi?.tables.find((table) => table.name === 'producers')
? 'producers'
: abi?.tables[0]?.name
}

dispatch({
type: 'SET_FILTERS',
payload: {
owner: accountName,
table: tableName || defaultTable,
table: tableName,
},
})
}
Expand All @@ -176,6 +203,11 @@ const useAccountState = () => {

dispatch({ payload: hash, type: 'SET_HASH' })
} catch (error) {
showMessage({
type: 'error',
content: getErrorMessage(error, `${t('account')} ${accountName}`),
})

console.log(error)
}

Expand Down

0 comments on commit 23efc1b

Please sign in to comment.