mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import React from 'react';
|
|
|
|
import { route } from 'nextjs-routes';
|
|
|
|
import config from 'configs/app';
|
|
import useApiQuery from 'lib/api/useApiQuery';
|
|
import { AddressHighlightProvider } from 'lib/contexts/addressHighlight';
|
|
import useIsMobile from 'lib/hooks/useIsMobile';
|
|
import { TX } from 'stubs/tx';
|
|
import { Link } from 'toolkit/next/link';
|
|
import SocketNewItemsNotice from 'ui/shared/SocketNewItemsNotice';
|
|
import useNewTxsSocket from 'ui/txs/socket/useTxsSocketTypeAll';
|
|
|
|
import LatestTxsDegraded from './fallbacks/LatestTxsDegraded';
|
|
import LatestTxsItem from './LatestTxsItem';
|
|
import LatestTxsItemMobile from './LatestTxsItemMobile';
|
|
|
|
const zetachainFeature = config.features.zetachain;
|
|
|
|
const LatestTxs = () => {
|
|
const isMobile = useIsMobile();
|
|
const txsCount = isMobile ? 2 : 5;
|
|
const { data, isPlaceholderData, isError } = useApiQuery('general:homepage_txs', {
|
|
queryOptions: {
|
|
placeholderData: Array(txsCount).fill(TX),
|
|
},
|
|
});
|
|
|
|
const { num, showErrorAlert } = useNewTxsSocket({ type: 'txs_home', isLoading: isPlaceholderData });
|
|
|
|
if (isError) {
|
|
return <LatestTxsDegraded maxNum={ txsCount }/>;
|
|
}
|
|
|
|
if (data) {
|
|
const txsUrl = route({ pathname: `/txs`, query: zetachainFeature.isEnabled ? { tab: 'evm' } : undefined });
|
|
return (
|
|
<>
|
|
<SocketNewItemsNotice className="rounded-b-none" url={ txsUrl } num={ num } showErrorAlert={ showErrorAlert } isLoading={ isPlaceholderData }/>
|
|
<div className="mb-3 block lg:hidden text-sm">
|
|
{ data.slice(0, txsCount).map(((tx, index) => (
|
|
<LatestTxsItemMobile
|
|
key={ tx.hash + (isPlaceholderData ? index : '') }
|
|
tx={ tx }
|
|
isLoading={ isPlaceholderData }
|
|
/>
|
|
))) }
|
|
</div>
|
|
<AddressHighlightProvider>
|
|
<div className="mb-3 hidden lg:block text-sm">
|
|
{ data.slice(0, txsCount).map(((tx, index) => (
|
|
<LatestTxsItem
|
|
key={ tx.hash + (isPlaceholderData ? index : '') }
|
|
tx={ tx }
|
|
isLoading={ isPlaceholderData }
|
|
/>
|
|
))) }
|
|
</div>
|
|
</AddressHighlightProvider>
|
|
<div className="flex justify-center">
|
|
<Link className="text-sm" loading={ isPlaceholderData } href={ txsUrl }>View all transactions</Link>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
return <span>No latest transactions found.</span>;
|
|
};
|
|
|
|
export default LatestTxs;
|