Commit aee48c7c authored by tom's avatar tom

add scroll to tabs

parent 0c8f6120
...@@ -29,9 +29,10 @@ import TokenSelect from './tokenSelect/TokenSelect'; ...@@ -29,9 +29,10 @@ import TokenSelect from './tokenSelect/TokenSelect';
interface Props { interface Props {
addressQuery: UseQueryResult<TAddress>; addressQuery: UseQueryResult<TAddress>;
scrollRef?: React.RefObject<HTMLDivElement>;
} }
const AddressDetails = ({ addressQuery }: Props) => { const AddressDetails = ({ addressQuery, scrollRef }: Props) => {
const router = useRouter(); const router = useRouter();
const isMobile = useIsMobile(); const isMobile = useIsMobile();
...@@ -42,6 +43,13 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -42,6 +43,13 @@ const AddressDetails = ({ addressQuery }: Props) => {
}, },
}); });
const handleCounterItemClick = React.useCallback(() => {
window.setTimeout(() => {
// cannot do scroll instantly, have to wait a little
scrollRef?.current?.scrollIntoView({ behavior: 'smooth' });
}, 500);
}, [ scrollRef ]);
if (addressQuery.isError) { if (addressQuery.isError) {
throw Error('Address fetch error', { cause: addressQuery.error as unknown as Error }); throw Error('Address fetch error', { cause: addressQuery.error as unknown as Error });
} }
...@@ -111,28 +119,28 @@ const AddressDetails = ({ addressQuery }: Props) => { ...@@ -111,28 +119,28 @@ const AddressDetails = ({ addressQuery }: Props) => {
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 } address={ addressQuery.data.hash }/> <AddressCounterItem prop="transactions_count" query={ countersQuery } address={ addressQuery.data.hash } onClick={ handleCounterItemClick }/>
</DetailsInfoItem> </DetailsInfoItem>
{ addressQuery.data.has_token_transfers && ( { addressQuery.data.has_token_transfers && (
<DetailsInfoItem <DetailsInfoItem
title="Transfers" title="Transfers"
hint="Number of transfers to/from this address." hint="Number of transfers to/from this address."
> >
<AddressCounterItem prop="token_transfers_count" query={ countersQuery } address={ addressQuery.data.hash }/> <AddressCounterItem prop="token_transfers_count" query={ countersQuery } address={ addressQuery.data.hash } onClick={ handleCounterItemClick }/>
</DetailsInfoItem> </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 } address={ addressQuery.data.hash }/> <AddressCounterItem prop="gas_usage_count" query={ countersQuery } address={ addressQuery.data.hash } onClick={ handleCounterItemClick }/>
</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 } address={ addressQuery.data.hash }/> <AddressCounterItem prop="validations_count" query={ countersQuery } address={ addressQuery.data.hash } onClick={ handleCounterItemClick }/>
</DetailsInfoItem> </DetailsInfoItem>
) } ) }
{ addressQuery.data.block_number_balance_updated_at && ( { addressQuery.data.block_number_balance_updated_at && (
......
...@@ -12,6 +12,7 @@ interface Props { ...@@ -12,6 +12,7 @@ interface Props {
prop: keyof AddressCounters; prop: keyof AddressCounters;
query: UseQueryResult<AddressCounters>; query: UseQueryResult<AddressCounters>;
address: string; address: string;
onClick: () => void;
} }
const PROP_TO_TAB = { const PROP_TO_TAB = {
...@@ -20,7 +21,7 @@ const PROP_TO_TAB = { ...@@ -20,7 +21,7 @@ const PROP_TO_TAB = {
validations_count: 'blocks_validated', validations_count: 'blocks_validated',
}; };
const AddressCounterItem = ({ prop, query, address }: Props) => { const AddressCounterItem = ({ prop, query, address, onClick }: Props) => {
if (query.isLoading) { if (query.isLoading) {
return <Skeleton h={ 5 } w="80px" borderRadius="full"/>; return <Skeleton h={ 5 } w="80px" borderRadius="full"/>;
} }
...@@ -42,7 +43,7 @@ const AddressCounterItem = ({ prop, query, address }: Props) => { ...@@ -42,7 +43,7 @@ const AddressCounterItem = ({ prop, query, address }: Props) => {
} }
return ( return (
<NextLink href={ link('address_index', { id: address }, { tab: PROP_TO_TAB[prop] }) } passHref> <NextLink href={ link('address_index', { id: address }, { tab: PROP_TO_TAB[prop] }) } passHref>
<Link> <Link onClick={ onClick }>
{ Number(data).toLocaleString() } { Number(data).toLocaleString() }
</Link> </Link>
</NextLink> </NextLink>
......
...@@ -99,7 +99,7 @@ const AddressPageContent = () => { ...@@ -99,7 +99,7 @@ const AddressPageContent = () => {
additionals={ tagsNode } additionals={ tagsNode }
/> />
) } ) }
<AddressDetails addressQuery={ addressQuery }/> <AddressDetails addressQuery={ addressQuery } scrollRef={ tabsScrollRef }/>
{ /* should stay before tabs to scroll up whith pagination */ } { /* should stay before tabs to scroll up whith pagination */ }
<Box ref={ tabsScrollRef }></Box> <Box ref={ tabsScrollRef }></Box>
{ addressQuery.isLoading ? <SkeletonTabs/> : <RoutedTabs tabs={ tabs } tabListProps={{ mt: 8 }}/> } { addressQuery.isLoading ? <SkeletonTabs/> : <RoutedTabs tabs={ tabs } tabListProps={{ mt: 8 }}/> }
......
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