|
| 1 | +import { FC } from 'react' |
| 2 | +import { useHref, useParams } from 'react-router-dom' |
| 3 | +import { useTranslation } from 'react-i18next' |
| 4 | +import Typography from '@mui/material/Typography' |
| 5 | +import { Layer, RoflInstance, useGetRuntimeRoflAppsIdInstancesRak } from '../../../oasis-nexus/api' |
| 6 | +import { SearchScope } from '../../../types/searchScope' |
| 7 | +import { AppErrors } from '../../../types/errors' |
| 8 | +import { RoflAppInstanceDetailsContext } from './hooks' |
| 9 | +import { useRequiredScopeParam } from '../../hooks/useScopeParam' |
| 10 | +import { useScreenSize } from '../../hooks/useScreensize' |
| 11 | +import { PageLayout } from '../../components/PageLayout' |
| 12 | +import { SubPageCard } from '../../components/SubPageCard' |
| 13 | +import { TextSkeleton } from '../../components/Skeleton' |
| 14 | +import { StyledDescriptionList } from '../../components/StyledDescriptionList' |
| 15 | +import { RouterTabs } from '../../components/RouterTabs' |
| 16 | +import { RoflAppLink } from '../../components/Rofl/RoflAppLink' |
| 17 | +import { CopyToClipboard } from '../../components/CopyToClipboard' |
| 18 | +import { useTypedSearchParam } from '../../hooks/useTypedSearchParam' |
| 19 | + |
| 20 | +export const RoflAppInstanceDetailsPage: FC = () => { |
| 21 | + const { t } = useTranslation() |
| 22 | + const scope = useRequiredScopeParam() |
| 23 | + const id = useParams().id! |
| 24 | + const rak = useParams().rak! |
| 25 | + const txLink = useHref('') |
| 26 | + const [method, setMethod] = useTypedSearchParam('method', 'any', { |
| 27 | + deleteParams: ['page'], |
| 28 | + }) |
| 29 | + const context: RoflAppInstanceDetailsContext = { scope, id, rak, method, setMethod } |
| 30 | + const instancesQuery = useGetRuntimeRoflAppsIdInstancesRak(scope.network, Layer.sapphire, id, rak) |
| 31 | + const { isLoading, isFetched, data } = instancesQuery |
| 32 | + const instance = data?.data |
| 33 | + |
| 34 | + if (!instance && isFetched) { |
| 35 | + throw AppErrors.NotFoundRoflAppInstance |
| 36 | + } |
| 37 | + |
| 38 | + return ( |
| 39 | + <PageLayout> |
| 40 | + <SubPageCard featured title={t('rofl.instanceDetails')}> |
| 41 | + <RoflAppInstanceDetailsView isLoading={isLoading} appId={id} instance={instance} scope={scope} /> |
| 42 | + </SubPageCard> |
| 43 | + <RouterTabs tabs={[{ label: t('common.transactions'), to: txLink }]} context={context} /> |
| 44 | + </PageLayout> |
| 45 | + ) |
| 46 | +} |
| 47 | + |
| 48 | +export const RoflAppInstanceDetailsView: FC<{ |
| 49 | + isLoading?: boolean |
| 50 | + appId: string |
| 51 | + instance: RoflInstance | undefined |
| 52 | + scope: SearchScope |
| 53 | +}> = ({ appId, instance, isLoading, scope }) => { |
| 54 | + const { t } = useTranslation() |
| 55 | + const { isMobile } = useScreenSize() |
| 56 | + |
| 57 | + if (isLoading) return <TextSkeleton numberOfRows={6} /> |
| 58 | + if (!instance) return <></> |
| 59 | + |
| 60 | + return ( |
| 61 | + <StyledDescriptionList titleWidth={isMobile ? '100px' : '200px'}> |
| 62 | + <dt>{t('rofl.rakAbbreviation')}</dt> |
| 63 | + <dd> |
| 64 | + <Typography variant="mono"> |
| 65 | + {instance.rak} <CopyToClipboard value={instance.rak} /> |
| 66 | + </Typography> |
| 67 | + </dd> |
| 68 | + <dt>{t('rofl.rekAbbreviation')}</dt> |
| 69 | + <dd> |
| 70 | + <Typography variant="mono"> |
| 71 | + {instance.rek} <CopyToClipboard value={instance.rek} /> |
| 72 | + </Typography> |
| 73 | + </dd> |
| 74 | + <dt>{t('rofl.expirationEpoch')}</dt> |
| 75 | + <dd>{instance.expiration_epoch.toLocaleString()}</dd> |
| 76 | + <dt>{t('rofl.roflAppId')}</dt> |
| 77 | + <dd> |
| 78 | + <RoflAppLink id={appId} network={scope.network} withSourceIndicator={false} /> |
| 79 | + <CopyToClipboard value={appId} /> |
| 80 | + </dd> |
| 81 | + <dt>{t('rofl.endorsingNodeId')}</dt> |
| 82 | + <dd> |
| 83 | + <Typography variant="mono"> |
| 84 | + {instance.endorsing_node_id} <CopyToClipboard value={instance.endorsing_node_id} /> |
| 85 | + </Typography> |
| 86 | + </dd> |
| 87 | + <dt>{t('rofl.extraKeys')}</dt> |
| 88 | + <dd> |
| 89 | + {instance.extra_keys.length ? ( |
| 90 | + <table> |
| 91 | + <tbody> |
| 92 | + {instance.extra_keys.map((key, index) => { |
| 93 | + const entries = Object.entries(JSON.parse(key)) |
| 94 | + const [keyType, keyValue] = entries[0] |
| 95 | + |
| 96 | + return ( |
| 97 | + <tr key={index}> |
| 98 | + <td> |
| 99 | + <Typography variant="mono">{keyType}:</Typography> |
| 100 | + </td> |
| 101 | + <td> |
| 102 | + <Typography variant="mono">{String(keyValue)}</Typography> |
| 103 | + </td> |
| 104 | + </tr> |
| 105 | + ) |
| 106 | + })} |
| 107 | + </tbody> |
| 108 | + </table> |
| 109 | + ) : ( |
| 110 | + t('common.missing') |
| 111 | + )} |
| 112 | + </dd> |
| 113 | + </StyledDescriptionList> |
| 114 | + ) |
| 115 | +} |
0 commit comments