Files
explore/ui/stats/NumberWidgetsList.tsx
tom goriunovandGitHub 932add9d96 Change zero to <0.001 value within different pages (#3150)
* basic components and address page refactoring

* second part of refactoring

* third part of refactoring

* NativeCoinValue component

* more refactoring

* rename TruncatedValue into TruncatedText

* minor fixes

* refactor block details

* fix layout of value and fee in tx table

* update screenshots

* different units for tooltip and stats widget small value fix

* update screenshots

* update tx table screenshot

* fix copy button vertical alignment
2025-12-05 16:04:27 +01:00

58 lines
1.6 KiB
TypeScript

import { Grid } from '@chakra-ui/react';
import React from 'react';
import useApiQuery from 'lib/api/useApiQuery';
import { STATS_COUNTER } from 'stubs/stats';
import StatsWidget from 'ui/shared/stats/StatsWidget';
import DataFetchAlert from '../shared/DataFetchAlert';
const UNITS_WITHOUT_SPACE = [ 's' ];
const NumberWidgetsList = () => {
const { data, isPlaceholderData, isError } = useApiQuery('stats:counters', {
queryOptions: {
placeholderData: { counters: Array(10).fill(STATS_COUNTER) },
},
});
if (isError) {
return <DataFetchAlert/>;
}
return (
<Grid
gridTemplateColumns={{ base: 'repeat(2, 50%)', lg: 'repeat(4, 25%)' }}
gridGap={{ base: 1, lg: 2 }}
>
{
data?.counters?.map(({ id, title, value, units, description }, index) => {
let unitsStr = '';
if (units && UNITS_WITHOUT_SPACE.includes(units)) {
unitsStr = units;
} else if (units) {
unitsStr = ' ' + units;
}
const valueNum = Number(value);
const maximumFractionDigits = valueNum < 10 ** -3 ? undefined : 3;
return (
<StatsWidget
key={ id + (isPlaceholderData ? index : '') }
label={ title }
value={ Number(value).toLocaleString(undefined, { maximumFractionDigits, notation: 'compact' }) }
valuePostfix={ unitsStr }
isLoading={ isPlaceholderData }
hint={ description }
/>
);
})
}
</Grid>
);
};
export default NumberWidgetsList;