Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: chain number format #39

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/components/ChainInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { useTranslation } from 'next-i18next';

import { ChainInfoCard } from '~/components';
import { useData, useCustomTheme } from '~/hooks';
import { getDescription } from '~/utils';

export const ChainInformation = () => {
const { t } = useTranslation();
const { chainData } = useData();

const getDescription = (data: string | number | undefined) => data ?? t('CHAIN.CHAININFORMATION.notAvailable');
const notAvailable = t('CHAIN.CHAININFORMATION.notAvailable');

return (
<article>
Expand All @@ -18,7 +18,7 @@ export const ChainInformation = () => {
<DataContainer>
<ChainInfoCard
title={t('CHAIN.CHAININFORMATION.chainType')}
description={getDescription(chainData?.chainType)}
description={getDescription(chainData?.chainType, notAvailable)}
isDataAvailable={!!chainData?.chainType}
icon='chainType'
size={22}
Expand All @@ -27,7 +27,7 @@ export const ChainInformation = () => {

<ChainInfoCard
title={t('CHAIN.CHAININFORMATION.lastBlock')}
description={getDescription(chainData?.l2ChainInfo?.lastBlock)}
description={getDescription(chainData?.l2ChainInfo?.lastBlock, notAvailable)}
isDataAvailable={!!chainData?.l2ChainInfo?.lastBlock}
icon='block'
size={22}
Expand All @@ -36,7 +36,7 @@ export const ChainInformation = () => {

<ChainInfoCard
title={t('CHAIN.CHAININFORMATION.lastBlockVerified')}
description={getDescription(chainData?.l2ChainInfo?.lastBlockVerified)}
description={getDescription(chainData?.l2ChainInfo?.lastBlockVerified, notAvailable)}
isDataAvailable={!!chainData?.l2ChainInfo?.lastBlockVerified}
icon='checkBlock'
size={22}
Expand All @@ -45,7 +45,7 @@ export const ChainInformation = () => {

<ChainInfoCard
title={t('CHAIN.CHAININFORMATION.transactionsPerSecond')}
description={getDescription(chainData?.l2ChainInfo?.tps)}
description={getDescription(chainData?.l2ChainInfo?.tps, notAvailable)}
isDataAvailable={!!chainData?.l2ChainInfo?.tps}
icon='speed'
size={22}
Expand All @@ -54,7 +54,7 @@ export const ChainInformation = () => {

<ChainInfoCard
title={t('CHAIN.CHAININFORMATION.totalBatchesCommitted')}
description={getDescription(chainData?.batchesInfo?.commited)}
description={getDescription(Number(chainData?.batchesInfo?.commited), notAvailable)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These Number() are necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backend is providing a string type for batchesInfo

isDataAvailable={!!chainData?.batchesInfo?.commited}
icon='block'
size={22}
Expand All @@ -63,7 +63,7 @@ export const ChainInformation = () => {

<ChainInfoCard
title={t('CHAIN.CHAININFORMATION.totalBatchesExecuted')}
description={getDescription(chainData?.batchesInfo?.executed)}
description={getDescription(Number(chainData?.batchesInfo?.executed), notAvailable)}
isDataAvailable={!!chainData?.batchesInfo?.executed}
icon='block'
size={22}
Expand All @@ -72,7 +72,7 @@ export const ChainInformation = () => {

<ChainInfoCard
title={t('CHAIN.CHAININFORMATION.totalBatchesVerified')}
description={getDescription(chainData?.batchesInfo?.verified)}
description={getDescription(Number(chainData?.batchesInfo?.verified), notAvailable)}
isDataAvailable={!!chainData?.batchesInfo?.verified}
icon='checkBlock'
size={22}
Expand All @@ -81,7 +81,7 @@ export const ChainInformation = () => {

<ChainInfoCard
title={t('CHAIN.CHAININFORMATION.averageBlockTime')}
description={getDescription(chainData?.l2ChainInfo?.avgBlockTime)}
description={getDescription(chainData?.l2ChainInfo?.avgBlockTime, notAvailable)}
isDataAvailable={!!chainData?.l2ChainInfo?.avgBlockTime}
icon='speed'
size={22}
Expand Down
12 changes: 6 additions & 6 deletions src/components/FeeParams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import { useTranslation } from 'next-i18next';

import { ChainInfoCard, STitle, DataContainer } from '~/components';
import { useData } from '~/hooks';
import { getDescription } from '~/utils';

export const FeeParams = () => {
const { t } = useTranslation();
const { chainData } = useData();

const getDescription = (data: string | number | undefined) => data ?? t('CHAIN.CHAININFORMATION.notAvailable');
const notAvailable = t('CHAIN.CHAININFORMATION.notAvailable');

return (
<article>
<STitle>{t('CHAIN.FEEPARAMS.title')} </STitle>
<DataContainer>
<ChainInfoCard
title={t('CHAIN.FEEPARAMS.batch')}
description={getDescription(chainData?.feeParams.batchOverheadL1Gas)}
description={getDescription(chainData?.feeParams.batchOverheadL1Gas, notAvailable)}
isDataAvailable={!!chainData?.feeParams.batchOverheadL1Gas}
icon='tag'
size={20}
Expand All @@ -24,7 +24,7 @@ export const FeeParams = () => {

<ChainInfoCard
title={t('CHAIN.FEEPARAMS.compute')}
description={getDescription(chainData?.feeParams.maxPubdataPerBatch)}
description={getDescription(chainData?.feeParams.maxPubdataPerBatch, notAvailable)}
isDataAvailable={!!chainData?.feeParams.maxPubdataPerBatch}
icon='block'
size={20}
Expand All @@ -33,7 +33,7 @@ export const FeeParams = () => {

<ChainInfoCard
title={t('CHAIN.FEEPARAMS.lastBlockVerified')}
description={getDescription(chainData?.l2ChainInfo?.lastBlockVerified)}
description={getDescription(chainData?.l2ChainInfo?.lastBlockVerified, notAvailable)}
isDataAvailable={!!chainData?.l2ChainInfo?.lastBlockVerified}
icon='checkBlock'
size={20}
Expand All @@ -42,7 +42,7 @@ export const FeeParams = () => {

<ChainInfoCard
title={t('CHAIN.FEEPARAMS.maxGasBatch')}
description={getDescription(chainData?.feeParams.maxL2GasPerBatch)}
description={getDescription(chainData?.feeParams.maxL2GasPerBatch, notAvailable)}
isDataAvailable={!!chainData?.feeParams.maxL2GasPerBatch}
icon='max'
size={20}
Expand Down
30 changes: 21 additions & 9 deletions src/components/RPC.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from 'react';
import { useTranslation } from 'next-i18next';
import { Box, Typography, Tooltip, styled } from '@mui/material';
import { Box, Typography, Tooltip, styled, Skeleton } from '@mui/material';
import { CheckCircle as CheckIcon, Cancel as CancelIcon } from '@mui/icons-material';

import { useData, useCustomTheme } from '~/hooks';
Expand All @@ -11,9 +11,11 @@ export const RPC = () => {
const { t } = useTranslation();
const { chainData } = useData();
const [rpcData, setRpcData] = useState<{ url: string; status: boolean }[]>([]);
const [rpcIsLoading, setRpcIsLoading] = useState(true);

useEffect(() => {
const updateRpcStatuses = async () => {
setRpcIsLoading(true);
if (!chainData?.metadata?.publicRpcs) return;

const updatedRpcData = await Promise.all(
Expand All @@ -24,6 +26,7 @@ export const RPC = () => {
);

setRpcData(updatedRpcData);
setRpcIsLoading(false);
};

updateRpcStatuses();
Expand All @@ -33,14 +36,23 @@ export const RPC = () => {
<article>
<STitle>{t('CHAIN.RPC.title')}</STitle>
<DataContainer>
{rpcData.map((rpc, index) => (
<RPCBox key={index}>
<Tooltip title={rpc.status ? t('CHAIN.RPC.statusActive') : t('CHAIN.RPC.statusInactive')}>
{rpc.status ? <CheckIcon color='success' /> : <CancelIcon color='error' />}
</Tooltip>
<RPCUrl>{rpc.url}</RPCUrl>
</RPCBox>
))}
{rpcIsLoading &&
Array.from({ length: 4 }).map((_, index) => (
<RPCBox key={index}>
<Skeleton variant='circular' width={20} height={20} />
<Skeleton variant='text' width='100%' />
</RPCBox>
))}

{!rpcIsLoading &&
rpcData.map((rpc, index) => (
<RPCBox key={index}>
<Tooltip title={rpc.status ? t('CHAIN.RPC.statusActive') : t('CHAIN.RPC.statusInactive')}>
{rpc.status ? <CheckIcon color='success' /> : <CancelIcon color='error' />}
</Tooltip>
<RPCUrl>{rpc.url}</RPCUrl>
</RPCBox>
))}
</DataContainer>
</article>
);
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './config';
export * from './format';
export * from './services';
export * from './addNetwork';
export * from './misc';
18 changes: 18 additions & 0 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { formatDataNumber } from './format';

export const getDescription = (data: string | number | undefined, notAvailable: string) => {
if (data === undefined || data === null) {
return notAvailable;
}

if (typeof data === 'number') {
return formatDataNumber(data);
}

if (typeof data === 'string') {
return data;
}

// Fallback: return notAvailable message
return notAvailable;
};
Loading