diff --git a/packages/app-explorer/src/SummarySession.tsx b/packages/app-explorer/src/SummarySession.tsx
index 44e5fb9021..79d6c57f3f 100644
--- a/packages/app-explorer/src/SummarySession.tsx
+++ b/packages/app-explorer/src/SummarySession.tsx
@@ -4,7 +4,7 @@
import { DerivedSessionInfo } from '@polkadot/api-derive/types';
-import React, { useEffect, useState } from 'react';
+import React, { useMemo } from 'react';
import { CardSummary } from '@polkadot/react-components';
import { useApi, useCall } from '@polkadot/react-hooks';
import { formatNumber } from '@polkadot/util';
@@ -12,75 +12,63 @@ import { formatNumber } from '@polkadot/util';
import { useTranslation } from './translate';
interface Props {
- sessionInfo?: DerivedSessionInfo;
withEra?: boolean;
withSession?: boolean;
}
-function renderSession ({ sessionInfo, withSession = true }: Props, t: (input: string) => string): React.ReactNode {
- if (!withSession || !sessionInfo) {
- return null;
- }
-
- const label = sessionInfo.isEpoch && sessionInfo.sessionLength.gtn(1)
- ? t('epoch')
- : t('session');
-
- return sessionInfo.sessionLength.gtn(0)
- ? (
-
- )
- : (
-
- {formatNumber(sessionInfo.currentIndex)}
-
- );
-}
-
-function renderEra ({ sessionInfo, withEra = true }: Props, t: (input: string) => string): React.ReactNode {
- if (!withEra || !sessionInfo) {
- return null;
- }
-
- const label = t('era');
-
- return sessionInfo.sessionLength.gtn(0)
- ? (
-
- )
- : (
-
- {formatNumber(sessionInfo.currentEra)}
-
- );
-}
-
-export default function SummarySession (props: Props): React.ReactElement {
+export default function SummarySession ({ withEra = true, withSession = true }: Props): React.ReactElement {
const { t } = useTranslation();
const { api } = useApi();
const sessionInfo = useCall(api.derive.session?.info, []);
- const [expanded, setExpanded] = useState(props);
-
- useEffect((): void => {
- setExpanded({ ...props, sessionInfo });
- }, [props, sessionInfo]);
+ const eraLabel = useMemo(() =>
+ t('era')
+ , [t]);
+ const sessionLabel = useMemo(() =>
+ sessionInfo?.isEpoch
+ ? t('epoch')
+ : t('session')
+ , [sessionInfo, t]);
return (
<>
- {renderSession(expanded, t)}
- {renderEra(expanded, t)}
+ {sessionInfo && (
+ <>
+ {withSession && (
+ sessionInfo.sessionLength.gtn(1)
+ ? (
+
+ )
+ : (
+
+ #{formatNumber(sessionInfo.currentIndex)}
+
+ )
+ )}
+ {withEra && (
+ sessionInfo.sessionLength.gtn(1)
+ ? (
+
+ )
+ : (
+
+ #{formatNumber(sessionInfo.currentEra)}
+
+ )
+ )}
+ >
+ )}
>
);
}