Skip to content
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
25 changes: 25 additions & 0 deletions lib/networks/getNetworkUtilizationParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default function getNetworkUtilizationParams(value: number) {
const load = (() => {
if (value > 80) {
return 'high';
}

if (value > 50) {
return 'medium';
}

return 'low';
})();

const colors = {
high: 'red.600',
medium: 'orange.600',
low: 'green.600',
};
const color = colors[load];

return {
load,
color,
};
}
13 changes: 10 additions & 3 deletions ui/blocks/BlocksTabSlot.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Flex, Box, Text } from '@chakra-ui/react';
import { upperFirst } from 'es-toolkit';
import React from 'react';

import type { PaginationParams } from 'ui/shared/pagination/types';

import { route } from 'nextjs-routes';

import useApiQuery from 'lib/api/useApiQuery';
import getNetworkUtilizationParams from 'lib/networks/getNetworkUtilizationParams';
import { HOMEPAGE_STATS } from 'stubs/stats';
import { Link } from 'toolkit/chakra/link';
import { Skeleton } from 'toolkit/chakra/skeleton';
import { Tooltip } from 'toolkit/chakra/tooltip';
import { nbsp } from 'toolkit/utils/htmlEntities';
import IconSvg from 'ui/shared/IconSvg';
import Pagination from 'ui/shared/pagination/Pagination';
Expand All @@ -24,16 +27,20 @@ const BlocksTabSlot = ({ pagination }: Props) => {
},
});

const networkUtilization = getNetworkUtilizationParams(statsQuery.data?.network_utilization_percentage ?? 0);

return (
<Flex alignItems="center" columnGap={ 8 } display={{ base: 'none', lg: 'flex' }}>
{ statsQuery.data?.network_utilization_percentage !== undefined && (
<Box>
<Text as="span" fontSize="sm">
Network utilization (last 50 blocks):{ nbsp }
</Text>
<Skeleton display="inline-block" fontSize="sm" color="blue.500" fontWeight={ 600 } loading={ statsQuery.isPlaceholderData }>
<span>{ statsQuery.data.network_utilization_percentage.toFixed(2) }%</span>
</Skeleton>
<Tooltip content={ `${ upperFirst(networkUtilization.load) } load` }>
<Skeleton display="inline-block" fontSize="sm" color={ networkUtilization.color } fontWeight={ 600 } loading={ statsQuery.isPlaceholderData }>
<span>{ statsQuery.data.network_utilization_percentage.toFixed(2) }%</span>
</Skeleton>
</Tooltip>
</Box>
) }
<Link href={ route({ pathname: '/block/countdown' }) }>
Expand Down
20 changes: 2 additions & 18 deletions ui/gasTracker/GasTrackerNetworkUtilization.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { chakra } from '@chakra-ui/react';
import React from 'react';

import getNetworkUtilizationParams from 'lib/networks/getNetworkUtilizationParams';
import { Skeleton } from 'toolkit/chakra/skeleton';
import { mdash } from 'toolkit/utils/htmlEntities';

Expand All @@ -10,24 +11,7 @@ interface Props {
}

const GasTrackerNetworkUtilization = ({ percentage, isLoading }: Props) => {
const load = (() => {
if (percentage > 80) {
return 'high';
}

if (percentage > 50) {
return 'medium';
}

return 'low';
})();

const colors = {
high: 'red.600',
medium: 'orange.600',
low: 'green.600',
};
const color = colors[load];
const { load, color } = getNetworkUtilizationParams(percentage);

return (
<Skeleton loading={ isLoading } whiteSpace="pre-wrap">
Expand Down
13 changes: 10 additions & 3 deletions ui/home/LatestBlocks.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { chakra, Box, Flex, Text, VStack } from '@chakra-ui/react';
import { useQueryClient } from '@tanstack/react-query';
import { upperFirst } from 'es-toolkit';
import React from 'react';

import type { SocketMessage } from 'lib/socket/types';
Expand All @@ -11,13 +12,15 @@ import config from 'configs/app';
import useApiQuery, { getResourceKey } from 'lib/api/useApiQuery';
import useInitialList from 'lib/hooks/useInitialList';
import useIsMobile from 'lib/hooks/useIsMobile';
import getNetworkUtilizationParams from 'lib/networks/getNetworkUtilizationParams';
import useSocketChannel from 'lib/socket/useSocketChannel';
import useSocketMessage from 'lib/socket/useSocketMessage';
import { BLOCK } from 'stubs/block';
import { HOMEPAGE_STATS } from 'stubs/stats';
import { Heading } from 'toolkit/chakra/heading';
import { Link } from 'toolkit/chakra/link';
import { Skeleton } from 'toolkit/chakra/skeleton';
import { Tooltip } from 'toolkit/chakra/tooltip';
import { nbsp } from 'toolkit/utils/htmlEntities';

import LatestBlocksItem from './LatestBlocksItem';
Expand Down Expand Up @@ -101,6 +104,8 @@ const LatestBlocks = () => {
);
}

const networkUtilization = getNetworkUtilizationParams(statsQueryResult.data?.network_utilization_percentage ?? 0);

return (
<Box width={{ base: '100%', lg: '280px' }} flexShrink={ 0 }>
<Heading level="3">Latest blocks</Heading>
Expand All @@ -109,9 +114,11 @@ const LatestBlocks = () => {
<Text as="span">
Network utilization:{ nbsp }
</Text>
<Text as="span" color="blue.500" fontWeight={ 700 }>
{ statsQueryResult.data?.network_utilization_percentage.toFixed(2) }%
</Text>
<Tooltip content={ `${ upperFirst(networkUtilization.load) } load` }>
<Text as="span" color={ networkUtilization.color } fontWeight={ 700 }>
{ statsQueryResult.data?.network_utilization_percentage.toFixed(2) }%
</Text>
</Tooltip>
</Skeleton>
) }
{ statsQueryResult.data?.celo && (
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ui/home/__screenshots__/LatestBlocks.pw.tsx_default_L2-view-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading