Files
tom goriunovandGitHub e6e83ee4e7 Add cross-chain transaction tracking and visualization (#3227)
* envs and feature setup

* home page layout

* cross-chain txs page

* cross-chain transfers page

* cross-chain transfers on tx page

* cross-chain messages on tx page

* cross-chain tx page

* cross-chain tx details token transfers

* stats and counters for lists

* migrate to new API version

* add swagger

* mobile lists

* placeholder views on address page

* tests

* fix adaptive tabs initial state when there is only one tab in the list

* tweaks

* bug fixes

* fix tests

* update screenshots

* migrate to new api version

* add chain label tooltip, copy button to txs in lists and same address highlight

* list views on address page

* fix tests

* fix links to current address in the list views

* update tooltips

* update tables layout

* review fixes

* fix spelling

* update screenshots

* update screenshot
2026-02-19 15:14:32 +01:00

73 lines
2.0 KiB
TypeScript

import { pickBy } from 'es-toolkit';
import { useRouter } from 'next/router';
import React from 'react';
import type { Props as AdaptiveTabsProps } from '../AdaptiveTabs/AdaptiveTabs';
import AdaptiveTabs from '../AdaptiveTabs/AdaptiveTabs';
import { getTabValue } from '../AdaptiveTabs/utils';
import useActiveTabFromQuery from './useActiveTabFromQuery';
export interface RoutedTabsProps extends AdaptiveTabsProps {
preservedParams?: Array<string>;
defaultTabId?: string;
}
const RoutedTabs = (props: RoutedTabsProps) => {
const { tabs, defaultTabId, onValueChange, preservedParams, ...rest } = props;
const router = useRouter();
const activeTab = useActiveTabFromQuery(tabs, defaultTabId);
const tabsRef = React.useRef<HTMLDivElement>(null);
const handleValueChange = React.useCallback(({ value }: { value: string }) => {
const nextTab = tabs.find((tab) => getTabValue(tab) === value);
if (!nextTab) {
return;
}
const queryForPathname = pickBy(router.query, (_, key) => {
if (preservedParams?.includes(String(key))) {
return true;
}
return router.pathname.includes(`[${ key }]`);
});
router.push(
{ pathname: router.pathname, query: { ...queryForPathname, tab: value } },
undefined,
{ shallow: true },
);
onValueChange?.({ value });
}, [ tabs, router, onValueChange, preservedParams ]);
React.useEffect(() => {
if (router.query.scroll_to_tabs) {
tabsRef?.current?.scrollIntoView(true);
delete router.query.scroll_to_tabs;
router.push(
{
pathname: router.pathname,
query: router.query,
},
undefined,
{ shallow: true },
);
}
// replicate componentDidMount
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<AdaptiveTabs
{ ...rest }
tabs={ tabs }
onValueChange={ handleValueChange }
defaultValue={ activeTab ? getTabValue(activeTab) : getTabValue(tabs[ 0 ]) }
/>
);
};
export default React.memo(RoutedTabs);