Commit aee48c7c authored by tom's avatar tom

add scroll to tabs

parent 0c8f6120
......@@ -29,9 +29,10 @@ import TokenSelect from './tokenSelect/TokenSelect';
interface Props {
addressQuery: UseQueryResult<TAddress>;
scrollRef?: React.RefObject<HTMLDivElement>;
}
const AddressDetails = ({ addressQuery }: Props) => {
const AddressDetails = ({ addressQuery, scrollRef }: Props) => {
const router = useRouter();
const isMobile = useIsMobile();
......@@ -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) {
throw Error('Address fetch error', { cause: addressQuery.error as unknown as Error });
}
......@@ -111,28 +119,28 @@ const AddressDetails = ({ addressQuery }: Props) => {
title="Transactions"
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>
{ 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 }/>
<AddressCounterItem prop="token_transfers_count" query={ countersQuery } address={ addressQuery.data.hash } onClick={ handleCounterItemClick }/>
</DetailsInfoItem>
) }
<DetailsInfoItem
title="Gas used"
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>
{ addressQuery.data.has_validated_blocks && (
<DetailsInfoItem
title="Blocks validated"
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>
) }
{ addressQuery.data.block_number_balance_updated_at && (
......
......@@ -12,6 +12,7 @@ interface Props {
prop: keyof AddressCounters;
query: UseQueryResult<AddressCounters>;
address: string;
onClick: () => void;
}
const PROP_TO_TAB = {
......@@ -20,7 +21,7 @@ const PROP_TO_TAB = {
validations_count: 'blocks_validated',
};
const AddressCounterItem = ({ prop, query, address }: Props) => {
const AddressCounterItem = ({ prop, query, address, onClick }: Props) => {
if (query.isLoading) {
return <Skeleton h={ 5 } w="80px" borderRadius="full"/>;
}
......@@ -42,7 +43,7 @@ const AddressCounterItem = ({ prop, query, address }: Props) => {
}
return (
<NextLink href={ link('address_index', { id: address }, { tab: PROP_TO_TAB[prop] }) } passHref>
<Link>
<Link onClick={ onClick }>
{ Number(data).toLocaleString() }
</Link>
</NextLink>
......
......@@ -99,7 +99,7 @@ const AddressPageContent = () => {
additionals={ tagsNode }
/>
) }
<AddressDetails addressQuery={ addressQuery }/>
<AddressDetails addressQuery={ addressQuery } scrollRef={ tabsScrollRef }/>
{ /* should stay before tabs to scroll up whith pagination */ }
<Box ref={ tabsScrollRef }></Box>
{ 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