Commit 88bfdb2b authored by tom's avatar tom

links on counters

parent 53197e00
...@@ -97,38 +97,42 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -97,38 +97,42 @@ const AddressDetails = ({ addressQuery }: Props) => {
</DetailsInfoItem> </DetailsInfoItem>
) } ) }
<AddressBalance data={ addressQuery.data }/> <AddressBalance data={ addressQuery.data }/>
<DetailsInfoItem { addressQuery.data.has_tokens && (
title="Tokens" <DetailsInfoItem
hint="All tokens in the account and total value." title="Tokens"
alignSelf="center" hint="All tokens in the account and total value."
py={ 0 } alignSelf="center"
> py={ 0 }
<TokenSelect/> >
</DetailsInfoItem> <TokenSelect/>
</DetailsInfoItem>
) }
<DetailsInfoItem <DetailsInfoItem
title="Transactions" title="Transactions"
hint="Number of transactions related to this address." hint="Number of transactions related to this address."
> >
<AddressCounterItem prop="transactions_count" query={ countersQuery }/> <AddressCounterItem prop="transactions_count" query={ countersQuery } address={ addressQuery.data.hash }/>
</DetailsInfoItem>
<DetailsInfoItem
title="Transfers"
hint="Number of transfers to/from this address."
>
<AddressCounterItem prop="token_transfers_count" query={ countersQuery }/>
</DetailsInfoItem> </DetailsInfoItem>
{ addressQuery.data.has_token_transfers && (
<DetailsInfoItem
title="Transfers"
hint="Number of transfers to/from this address."
>
<AddressCounterItem prop="token_transfers_count" query={ countersQuery } address={ addressQuery.data.hash }/>
</DetailsInfoItem>
) }
<DetailsInfoItem <DetailsInfoItem
title="Gas used" title="Gas used"
hint="Gas used by the address." hint="Gas used by the address."
> >
<AddressCounterItem prop="gas_usage_count" query={ countersQuery }/> <AddressCounterItem prop="gas_usage_count" query={ countersQuery } address={ addressQuery.data.hash }/>
</DetailsInfoItem> </DetailsInfoItem>
{ addressQuery.data.has_validated_blocks && ( { addressQuery.data.has_validated_blocks && (
<DetailsInfoItem <DetailsInfoItem
title="Blocks validated" title="Blocks validated"
hint="Number of blocks validated by this validator." hint="Number of blocks validated by this validator."
> >
<AddressCounterItem prop="validations_count" query={ countersQuery }/> <AddressCounterItem prop="validations_count" query={ countersQuery } address={ addressQuery.data.hash }/>
</DetailsInfoItem> </DetailsInfoItem>
) } ) }
{ addressQuery.data.block_number_balance_updated_at && ( { addressQuery.data.block_number_balance_updated_at && (
......
import { Skeleton } from '@chakra-ui/react'; import { Link, Skeleton } from '@chakra-ui/react';
import type { UseQueryResult } from '@tanstack/react-query'; import type { UseQueryResult } from '@tanstack/react-query';
import BigNumber from 'bignumber.js'; import BigNumber from 'bignumber.js';
import NextLink from 'next/link';
import React from 'react'; import React from 'react';
import type { AddressCounters } from 'types/api/address'; import type { AddressCounters } from 'types/api/address';
import link from 'lib/link/link';
interface Props { interface Props {
prop: keyof AddressCounters; prop: keyof AddressCounters;
query: UseQueryResult<AddressCounters>; query: UseQueryResult<AddressCounters>;
address: string;
} }
const AddressCounterItem = ({ prop, query }: Props) => { const PROP_TO_TAB = {
transactions_count: 'txs',
token_transfers_count: 'token_transfers',
validations_count: 'blocks_validated',
};
const AddressCounterItem = ({ prop, query, address }: Props) => {
if (query.isLoading) { if (query.isLoading) {
return <Skeleton h={ 5 } w="80px" borderRadius="full"/>; return <Skeleton h={ 5 } w="80px" borderRadius="full"/>;
} }
...@@ -26,8 +36,18 @@ const AddressCounterItem = ({ prop, query }: Props) => { ...@@ -26,8 +36,18 @@ const AddressCounterItem = ({ prop, query }: Props) => {
return <span>{ BigNumber(data).toFormat() }</span>; return <span>{ BigNumber(data).toFormat() }</span>;
case 'transactions_count': case 'transactions_count':
case 'token_transfers_count': case 'token_transfers_count':
case 'validations_count': case 'validations_count': {
return <span>{ Number(data).toLocaleString() }</span>; if (data === '0') {
return <span>0</span>;
}
return (
<NextLink href={ link('address_index', { id: address }, { tab: PROP_TO_TAB[prop] }) } passHref>
<Link>
{ Number(data).toLocaleString() }
</Link>
</NextLink>
);
}
} }
}; };
......
import { Box, Flex, Icon, IconButton, Skeleton, Tooltip } from '@chakra-ui/react'; import { Box, Flex, Icon, IconButton, Skeleton, Tooltip } from '@chakra-ui/react';
import { useQueryClient, useIsFetching } from '@tanstack/react-query'; import { useQueryClient, useIsFetching } from '@tanstack/react-query';
import NextLink from 'next/link';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React from 'react'; import React from 'react';
...@@ -9,6 +10,7 @@ import type { Address } from 'types/api/address'; ...@@ -9,6 +10,7 @@ import type { Address } from 'types/api/address';
import walletIcon from 'icons/wallet.svg'; import walletIcon from 'icons/wallet.svg';
import useApiQuery, { getResourceKey } from 'lib/api/useApiQuery'; import useApiQuery, { getResourceKey } from 'lib/api/useApiQuery';
import useIsMobile from 'lib/hooks/useIsMobile'; import useIsMobile from 'lib/hooks/useIsMobile';
import link from 'lib/link/link';
import useSocketChannel from 'lib/socket/useSocketChannel'; import useSocketChannel from 'lib/socket/useSocketChannel';
import useSocketMessage from 'lib/socket/useSocketMessage'; import useSocketMessage from 'lib/socket/useSocketMessage';
...@@ -21,7 +23,8 @@ const TokenSelect = () => { ...@@ -21,7 +23,8 @@ const TokenSelect = () => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const [ blockNumber, setBlockNumber ] = React.useState<number>(); const [ blockNumber, setBlockNumber ] = React.useState<number>();
const addressResourceKey = getResourceKey('address', { pathParams: { id: router.query.id?.toString() } }); const addressHash = router.query.id?.toString();
const addressResourceKey = getResourceKey('address', { pathParams: { id: addressHash } });
const addressQueryData = queryClient.getQueryData<Address>(addressResourceKey); const addressQueryData = queryClient.getQueryData<Address>(addressResourceKey);
...@@ -75,14 +78,19 @@ const TokenSelect = () => { ...@@ -75,14 +78,19 @@ const TokenSelect = () => {
<TokenSelectDesktop data={ data } isLoading={ balancesIsFetching === 1 }/> <TokenSelectDesktop data={ data } isLoading={ balancesIsFetching === 1 }/>
} }
<Tooltip label="Show all tokens"> <Tooltip label="Show all tokens">
<IconButton <Box>
aria-label="Show all tokens" <NextLink href={ link('address_index', { id: addressHash }, { tab: 'tokens' }) } passHref>
variant="outline" <IconButton
size="sm" aria-label="Show all tokens"
pl="6px" variant="outline"
pr="6px" size="sm"
icon={ <Icon as={ walletIcon } boxSize={ 5 }/> } pl="6px"
/> pr="6px"
icon={ <Icon as={ walletIcon } boxSize={ 5 }/> }
as="a"
/>
</NextLink>
</Box>
</Tooltip> </Tooltip>
</Flex> </Flex>
); );
......
...@@ -30,7 +30,7 @@ const ActionBar = ({ children, className }: Props) => { ...@@ -30,7 +30,7 @@ const ActionBar = ({ children, className }: Props) => {
position="sticky" position="sticky"
top={{ base: scrollDirection === 'down' ? `${ TOP_DOWN }px` : `${ TOP_UP }px`, lg: 0 }} top={{ base: scrollDirection === 'down' ? `${ TOP_DOWN }px` : `${ TOP_UP }px`, lg: 0 }}
transitionProperty="top,box-shadow,background-color,color" transitionProperty="top,box-shadow,background-color,color"
transitionDuration="slow" transitionDuration="normal"
zIndex={{ base: 'sticky2', lg: 'docked' }} zIndex={{ base: 'sticky2', lg: 'docked' }}
boxShadow={{ base: isSticky ? 'md' : 'none', lg: 'none' }} boxShadow={{ base: isSticky ? 'md' : 'none', lg: 'none' }}
ref={ ref } ref={ ref }
......
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