Commit 19283abb authored by tom goriunov's avatar tom goriunov Committed by GitHub

Top accounts percentage of funds is not displayed correctly (#1274)

Fixes #1267
parent 6f422b9c
...@@ -5,6 +5,7 @@ import React from 'react'; ...@@ -5,6 +5,7 @@ import React from 'react';
import type { AddressesItem } from 'types/api/addresses'; import type { AddressesItem } from 'types/api/addresses';
import config from 'configs/app'; import config from 'configs/app';
import { ZERO } from 'lib/consts';
import Tag from 'ui/shared/chakra/Tag'; import Tag from 'ui/shared/chakra/Tag';
import AddressEntity from 'ui/shared/entities/address/AddressEntity'; import AddressEntity from 'ui/shared/entities/address/AddressEntity';
import ListItemMobile from 'ui/shared/ListItemMobile/ListItemMobile'; import ListItemMobile from 'ui/shared/ListItemMobile/ListItemMobile';
...@@ -12,7 +13,7 @@ import ListItemMobile from 'ui/shared/ListItemMobile/ListItemMobile'; ...@@ -12,7 +13,7 @@ import ListItemMobile from 'ui/shared/ListItemMobile/ListItemMobile';
type Props = { type Props = {
item: AddressesItem; item: AddressesItem;
index: number; index: number;
totalSupply: string; totalSupply: BigNumber;
isLoading?: boolean; isLoading?: boolean;
} }
...@@ -47,7 +48,7 @@ const AddressesListItem = ({ ...@@ -47,7 +48,7 @@ const AddressesListItem = ({
<span>{ addressBalance.dp(8).toFormat() }</span> <span>{ addressBalance.dp(8).toFormat() }</span>
</Skeleton> </Skeleton>
</HStack> </HStack>
{ totalSupply && totalSupply !== '0' && ( { !totalSupply.eq(ZERO) && (
<HStack spacing={ 3 }> <HStack spacing={ 3 }>
<Skeleton isLoaded={ !isLoading } fontSize="sm" fontWeight={ 500 }>Percentage</Skeleton> <Skeleton isLoaded={ !isLoading } fontSize="sm" fontWeight={ 500 }>Percentage</Skeleton>
<Skeleton isLoaded={ !isLoading } fontSize="sm" color="text_secondary"> <Skeleton isLoaded={ !isLoading } fontSize="sm" color="text_secondary">
......
import { Table, Tbody, Tr, Th } from '@chakra-ui/react'; import { Table, Tbody, Tr, Th } from '@chakra-ui/react';
import type BigNumber from 'bignumber.js';
import React from 'react'; import React from 'react';
import type { AddressesItem } from 'types/api/addresses'; import type { AddressesItem } from 'types/api/addresses';
import config from 'configs/app'; import config from 'configs/app';
import { ZERO } from 'lib/consts';
import { default as Thead } from 'ui/shared/TheadSticky'; import { default as Thead } from 'ui/shared/TheadSticky';
import AddressesTableItem from './AddressesTableItem'; import AddressesTableItem from './AddressesTableItem';
interface Props { interface Props {
items: Array<AddressesItem>; items: Array<AddressesItem>;
totalSupply: string; totalSupply: BigNumber;
pageStartIndex: number; pageStartIndex: number;
top: number; top: number;
isLoading?: boolean; isLoading?: boolean;
} }
const AddressesTable = ({ items, totalSupply, pageStartIndex, top, isLoading }: Props) => { const AddressesTable = ({ items, totalSupply, pageStartIndex, top, isLoading }: Props) => {
const hasPercentage = Boolean(totalSupply && totalSupply !== '0'); const hasPercentage = !totalSupply.eq(ZERO);
return ( return (
<Table variant="simple" size="sm"> <Table variant="simple" size="sm">
<Thead top={ top }> <Thead top={ top }>
......
...@@ -11,7 +11,7 @@ import AddressEntity from 'ui/shared/entities/address/AddressEntity'; ...@@ -11,7 +11,7 @@ import AddressEntity from 'ui/shared/entities/address/AddressEntity';
type Props = { type Props = {
item: AddressesItem; item: AddressesItem;
index: number; index: number;
totalSupply: string; totalSupply: BigNumber;
hasPercentage: boolean; hasPercentage: boolean;
isLoading?: boolean; isLoading?: boolean;
} }
...@@ -55,7 +55,7 @@ const AddressesTableItem = ({ ...@@ -55,7 +55,7 @@ const AddressesTableItem = ({
</Td> </Td>
{ hasPercentage && ( { hasPercentage && (
<Td isNumeric> <Td isNumeric>
<Text lineHeight="24px">{ addressBalance.div(BigNumber(totalSupply)).multipliedBy(100).dp(8).toFormat() + '%' }</Text> <Text lineHeight="24px">{ addressBalance.div(totalSupply).multipliedBy(100).dp(8).toFormat() + '%' }</Text>
</Td> </Td>
) } ) }
<Td isNumeric> <Td isNumeric>
......
import { Hide, Show } from '@chakra-ui/react'; import { Hide, Show } from '@chakra-ui/react';
import BigNumber from 'bignumber.js';
import React from 'react'; import React from 'react';
import { TOP_ADDRESS } from 'stubs/address'; import { TOP_ADDRESS } from 'stubs/address';
...@@ -39,13 +40,17 @@ const Accounts = () => { ...@@ -39,13 +40,17 @@ const Accounts = () => {
); );
const pageStartIndex = (pagination.page - 1) * PAGE_SIZE + 1; const pageStartIndex = (pagination.page - 1) * PAGE_SIZE + 1;
const totalSupply = React.useMemo(() => {
return BigNumber(data?.total_supply || '0');
}, [ data?.total_supply ]);
const content = data?.items ? ( const content = data?.items ? (
<> <>
<Hide below="lg" ssr={ false }> <Hide below="lg" ssr={ false }>
<AddressesTable <AddressesTable
top={ pagination.isVisible ? 80 : 0 } top={ pagination.isVisible ? 80 : 0 }
items={ data.items } items={ data.items }
totalSupply={ data.total_supply } totalSupply={ totalSupply }
pageStartIndex={ pageStartIndex } pageStartIndex={ pageStartIndex }
isLoading={ isPlaceholderData } isLoading={ isPlaceholderData }
/> />
...@@ -57,7 +62,7 @@ const Accounts = () => { ...@@ -57,7 +62,7 @@ const Accounts = () => {
key={ item.hash + (isPlaceholderData ? index : '') } key={ item.hash + (isPlaceholderData ? index : '') }
item={ item } item={ item }
index={ pageStartIndex + index } index={ pageStartIndex + index }
totalSupply={ data.total_supply } totalSupply={ totalSupply }
isLoading={ isPlaceholderData } isLoading={ isPlaceholderData }
/> />
); );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment