Files
explore/ui/home/fallbacks/LatestTxsDegraded.tsx
tom goriunovandGitHub f4cab7f9d7 UI/UX: Graceful service degradation: Home page (#3233)
* fallback components

* home page graphs: fix tab title flickering

* degraded views

* fix tx degraded view when initial query is refetching

* call unwatch when components unmount

* tests

* use context to store rpc data

* stats degraded state

* update tests

* RPC data hint

* fixes

* review fixes

* condition fix

* cover ads in test
2026-02-24 11:15:58 +01:00

79 lines
2.4 KiB
TypeScript

import { Box, Flex } from '@chakra-ui/react';
import { clamp } from 'es-toolkit';
import React from 'react';
import { route } from 'nextjs-routes';
import config from 'configs/app';
import { AddressHighlightProvider } from 'lib/contexts/addressHighlight';
import { publicClient } from 'lib/web3/client';
import { TX } from 'stubs/tx';
import { Link } from 'toolkit/chakra/link';
import LatestTxsItem from '../LatestTxsItem';
import LatestTxsItemMobile from '../LatestTxsItemMobile';
import LatestTxsDegradedNewItems from './LatestTxsDegradedNewItems';
import LatestTxsFallback from './LatestTxsFallback';
import { useHomeRpcDataContext } from './rpcDataContext';
const zetachainFeature = config.features.zetachain;
interface Props {
maxNum: number;
}
const LatestTxsDegraded = ({ maxNum }: Props) => {
const { txs, totalTxs, isError, isLoading, enable } = useHomeRpcDataContext();
React.useEffect(() => {
enable(true, 'latest-txs');
return () => {
enable(false, 'latest-txs');
};
}, [ enable ]);
if (isError || !publicClient) {
return <LatestTxsFallback/>;
}
const items = isLoading ? Array(maxNum).fill(TX) : txs.slice(0, maxNum);
if (items.length === 0) {
return <Box textStyle="sm">No latest transactions found.</Box>;
}
const txsUrl = route({ pathname: `/txs`, query: zetachainFeature.isEnabled ? { tab: 'evm' } : undefined });
const overflow = clamp(totalTxs - maxNum, 0, Infinity);
return (
<>
<LatestTxsDegradedNewItems overflow={ overflow } url={ txsUrl } isLoading={ isLoading }/>
<Box mb={ 3 } display={{ base: 'block', lg: 'none' }} textStyle="sm">
{ items.map(((tx, index) => (
<LatestTxsItemMobile
key={ tx.hash + (isLoading ? index : '') }
tx={ tx }
isLoading={ isLoading }
/>
))) }
</Box>
<AddressHighlightProvider>
<Box mb={ 3 } display={{ base: 'none', lg: 'block' }} textStyle="sm">
{ items.map(((tx, index) => (
<LatestTxsItem
key={ tx.hash + (isLoading ? index : '') }
tx={ tx }
isLoading={ isLoading }
/>
))) }
</Box>
</AddressHighlightProvider>
<Flex justifyContent="center">
<Link textStyle="sm" loading={ isLoading } href={ txsUrl }>View all transactions</Link>
</Flex>
</>
);
};
export default React.memo(LatestTxsDegraded);