diff --git a/.changelog/1278.bugfix.md b/.changelog/1278.bugfix.md new file mode 100644 index 0000000000..ad35f6ed7f --- /dev/null +++ b/.changelog/1278.bugfix.md @@ -0,0 +1 @@ +Show errors in runtime events diff --git a/src/app/components/RuntimeEvents/EventError.tsx b/src/app/components/RuntimeEvents/EventError.tsx new file mode 100644 index 0000000000..30d03a45e6 --- /dev/null +++ b/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 = ({ 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 ( + <> + + {t('common.failed')} +   + + + {errorMessage} + + ) +} + +export const MaybeEventErrorLine: FC = ({ event }) => { + const { t } = useTranslation() + return ( + event.body.error && ( + <> +
{t('common.status')}
+
+ +
+ + ) + ) +} diff --git a/src/app/components/RuntimeEvents/RuntimeEventDetails.tsx b/src/app/components/RuntimeEvents/RuntimeEventDetails.tsx index b9b5e2c260..a52038de46 100644 --- a/src/app/components/RuntimeEvents/RuntimeEventDetails.tsx +++ b/src/app/components/RuntimeEvents/RuntimeEventDetails.tsx @@ -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 @@ -244,6 +245,7 @@ export const RuntimeEventDetails: FC<{
+
{t('common.from')}
+
{t('common.from')}
+
{t('common.from')}
+
{t('common.from')}
({ +export const ErrorBox = styled(Box)(() => ({ display: 'flex', justifyContent: 'center', alignItems: 'center', diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index a16e267fb2..a6b2e99394 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -200,6 +200,7 @@ }, "errors": { "code": "error code", + "module": "module", "error": "Error", "loadFirstPage": "load the first page", "unknown": "Unknown error",