Skip to content

Commit

Permalink
Show errors in runtime events
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Feb 21, 2024
1 parent eb1f1fe commit 5741282
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changelog/1278.bugfix.md
@@ -0,0 +1 @@
Show errors in runtime events
58 changes: 58 additions & 0 deletions src/app/components/RuntimeEvents/EventError.tsx
@@ -0,0 +1,58 @@
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
import CancelIcon from '@mui/icons-material/Cancel'
import { RuntimeEvent } from '../../../oasis-nexus/api'
import { ErrorBox, StyledBox } from '../StatusIcon'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { RuntimeEventType } from '../../../oasis-nexus/api'

/**
* https://github.com/oasisprotocol/oasis-sdk/blob/9fb148a/client-sdk/go/modules/consensusaccounts/types.go#L145-L217
*
* Can appear in:
* - {@link RuntimeEventType.consensus_accountsdeposit}
* - {@link RuntimeEventType.consensus_accountswithdraw}
* - {@link RuntimeEventType.consensus_accountsdelegate}
* - {@link RuntimeEventType.consensus_accountsundelegate_start}
*/
type ConsensusError = {
module: string
code: number
}

type EventErrorProps = {
event: RuntimeEvent
}

export const EventError: FC<EventErrorProps> = ({ event }) => {
const { t } = useTranslation()
const error: ConsensusError | undefined = event.body.error
if (!error) return null

const errorMessage = `${t('errors.code')} ${error.code}, ${t('errors.module')}: ${error.module}`
return (
<>
<StyledBox success={false} error={undefined} withText={true}>
{t('common.failed')}
&nbsp;
<CancelIcon color="error" fontSize="inherit" />
</StyledBox>
<ErrorBox>{errorMessage}</ErrorBox>
</>
)
}

export const MaybeEventErrorLine: FC<EventErrorProps> = ({ event }) => {
const { t } = useTranslation()
return (
event.body.error && (
<>
<dt>{t('common.status')}</dt>
<dd style={{ flexWrap: 'wrap', gap: '10px' }}>
<EventError event={event} />
</dd>
</>
)
)
}
5 changes: 5 additions & 0 deletions src/app/components/RuntimeEvents/RuntimeEventDetails.tsx
Expand Up @@ -28,6 +28,7 @@ import { getPreciseNumberFormat } from '../../../locales/getPreciseNumberFormat'
import { UndelegateStartIcon } from '../CustomIcons/UndelegateStart'
import { UndelegateFinishIcon } from '../CustomIcons/UndelegateFinish'
import { DelegateIcon } from '../CustomIcons/Delegate'
import { MaybeEventErrorLine } from './EventError'

export const EventTypeIcon: FC<{
eventType: RuntimeEventType
Expand Down Expand Up @@ -244,6 +245,7 @@ export const RuntimeEventDetails: FC<{
<div>
<EventTypeIcon eventType={event.type} eventName={eventName} />
<StyledDescriptionList titleWidth={isMobile ? '100px' : '200px'}>
<MaybeEventErrorLine event={event} />
<dt>{t('common.from')}</dt>
<dd>
<AccountLink
Expand Down Expand Up @@ -279,6 +281,7 @@ export const RuntimeEventDetails: FC<{
<div>
<EventTypeIcon eventType={event.type} eventName={eventName} />
<StyledDescriptionList titleWidth={isMobile ? '100px' : '200px'}>
<MaybeEventErrorLine event={event} />
<dt>{t('common.from')}</dt>
<dd>
<AccountLink
Expand Down Expand Up @@ -314,6 +317,7 @@ export const RuntimeEventDetails: FC<{
<div>
<EventTypeIcon eventType={event.type} eventName={eventName} />
<StyledDescriptionList titleWidth={isMobile ? '100px' : '200px'}>
<MaybeEventErrorLine event={event} />
<dt>{t('common.from')}</dt>
<dd>
<AccountLink
Expand Down Expand Up @@ -348,6 +352,7 @@ export const RuntimeEventDetails: FC<{
<div>
<EventTypeIcon eventType={event.type} eventName={eventName} />
<StyledDescriptionList titleWidth={isMobile ? '100px' : '200px'}>
<MaybeEventErrorLine event={event} />
<dt>{t('common.from')}</dt>
<dd>
<AccountLink
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/StatusIcon/index.tsx
Expand Up @@ -50,7 +50,7 @@ export const StyledBox = styled(Box, {
}
})

const ErrorBox = styled(Box)(() => ({
export const ErrorBox = styled(Box)(() => ({
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Expand Up @@ -200,6 +200,7 @@
},
"errors": {
"code": "error code",
"module": "module",
"error": "Error",
"loadFirstPage": "load the first page",
"unknown": "Unknown error",
Expand Down

0 comments on commit 5741282

Please sign in to comment.