mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* add export for address txs * transfer all export from page to dialog * remove old route and components * improve file name and fix loading state of icon button * basic implementation * refetch item status * status indicator for download items * changes for multichain * handle too many requests for downloads error * update button styles and spacing * fix tests * disable async export for multichain * Fix CSV export cancel flow and stabilize context updates Applied via @cursor push command * test and review fixes * design fixes * refactor file names --------- Co-authored-by: Hanzo Dev <[email protected]>
104 lines
3.2 KiB
TypeScript
104 lines
3.2 KiB
TypeScript
import { useRouter } from 'next/router';
|
|
import React from 'react';
|
|
|
|
import type * as multichain from '@blockscout/multichain-aggregator-types';
|
|
|
|
import CsvExport from 'client/features/csv-export/components/CsvExport';
|
|
import multichainConfig from 'configs/multichain';
|
|
import { MultichainProvider } from 'lib/contexts/multichain';
|
|
import useIsMobile from 'lib/hooks/useIsMobile';
|
|
import getQueryParamString from 'lib/router/getQueryParamString';
|
|
import { LOG } from 'stubs/log';
|
|
import { generateListStub } from 'stubs/utils';
|
|
import ChainSelect from 'ui/multichain/components/ChainSelect';
|
|
import ActionBar from 'ui/shared/ActionBar';
|
|
import DataListDisplay from 'ui/shared/DataListDisplay';
|
|
import LogItem from 'ui/shared/logs/LogItem';
|
|
import Pagination from 'ui/shared/pagination/Pagination';
|
|
import useQueryWithPages from 'ui/shared/pagination/useQueryWithPages';
|
|
|
|
import getAvailableChainIds from './getAvailableChainIds';
|
|
|
|
interface Props {
|
|
addressData: multichain.GetAddressResponse | undefined;
|
|
isLoading: boolean;
|
|
}
|
|
|
|
const MultichainAddressLogs = ({ addressData, isLoading }: Props) => {
|
|
const router = useRouter();
|
|
const chainIds = React.useMemo(() => getAvailableChainIds(addressData), [ addressData ]);
|
|
const isMobile = useIsMobile();
|
|
|
|
const hash = getQueryParamString(router.query.hash);
|
|
const { data, isPlaceholderData, isError, pagination, chainValue, onChainValueChange } = useQueryWithPages({
|
|
resourceName: 'general:address_logs',
|
|
pathParams: { hash },
|
|
options: {
|
|
placeholderData: generateListStub<'general:address_logs'>(LOG, 3, { next_page_params: {
|
|
block_number: 9005750,
|
|
index: 42,
|
|
items_count: 50,
|
|
transaction_index: 23,
|
|
} }),
|
|
enabled: !isLoading,
|
|
},
|
|
isMultichain: true,
|
|
chainIds,
|
|
});
|
|
|
|
const chainData = React.useMemo(() => {
|
|
const config = multichainConfig();
|
|
return config?.chains.find(({ id }) => id === chainValue?.[0]);
|
|
}, [ chainValue ]);
|
|
|
|
const actionBar = (
|
|
<ActionBar mt={ -6 }>
|
|
<ChainSelect
|
|
value={ chainValue }
|
|
onValueChange={ onChainValueChange }
|
|
chainIds={ chainIds }
|
|
loading={ isLoading }
|
|
mode={ isMobile ? 'compact' : 'default' }
|
|
/>
|
|
{ (data?.items.length ?? 0) > 0 && (
|
|
<CsvExport
|
|
type="address_logs"
|
|
resourceName="general:address_csv_export_logs"
|
|
pathParams={{ hash }}
|
|
loadingInitial={ pagination.isLoading }
|
|
chainData={ chainData }
|
|
ml={ 2 }
|
|
/>
|
|
) }
|
|
<Pagination ml="auto" { ...pagination }/>
|
|
</ActionBar>
|
|
);
|
|
|
|
const content = data?.items ? data.items.map((item, index) => (
|
|
<LogItem
|
|
key={ index }
|
|
{ ...item }
|
|
type="address"
|
|
isLoading={ isPlaceholderData }
|
|
chainData={ chainData }
|
|
/>
|
|
)) : null;
|
|
|
|
return (
|
|
<DataListDisplay
|
|
isError={ isError }
|
|
itemsNum={ data?.items?.length }
|
|
emptyText="There are no logs for this address."
|
|
showActionBarIfEmpty
|
|
showActionBarIfError
|
|
actionBar={ actionBar }
|
|
>
|
|
<MultichainProvider chainId={ chainValue?.[0] }>
|
|
{ content }
|
|
</MultichainProvider>
|
|
</DataListDisplay>
|
|
);
|
|
};
|
|
|
|
export default MultichainAddressLogs;
|