-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Show errors in runtime events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')} | ||
| ||
<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> | ||
</> | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters