Skip to content

Commit

Permalink
message of reverts reasons for toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehor Podporinov authored and Yehor Podporinov committed Jan 29, 2024
1 parent 46d1771 commit a916034
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/helpers/error-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { errors } from '@/errors'
import { bus, BUS_EVENTS } from '@/helpers'
import { i18n } from '@/localization'
import { capitalize } from './text.helpers'
import log from 'loglevel'

export class ErrorHandler {
Expand Down Expand Up @@ -76,7 +77,13 @@ export class ErrorHandler {
errorMessage = t('errors.provider-json-rpc-version-not-supported')
break
default: {
errorMessage = t('errors.default')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const reason = (error as any)?.reason

errorMessage =
typeof reason === 'string' && reason.length
? capitalize(reason)
: t('errors.default')
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/text.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ export function abbrCenter(text: string, amount = 4): string {
text.length,
)}`
}

export function capitalize(text: string): string {
if (!text.length) return ''
return text[0].toUpperCase().concat(text.slice(1))
}

0 comments on commit a916034

Please sign in to comment.