Files
1a57cb25a0 Async CSV export (#3330)
* 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]>
2026-03-02 15:51:50 +02:00

82 lines
2.4 KiB
TypeScript

import { useRouter } from 'next/router';
import React from 'react';
import CsvExport from 'client/features/csv-export/components/CsvExport';
import useIsMounted from 'lib/hooks/useIsMounted';
import getQueryParamString from 'lib/router/getQueryParamString';
import { LOG } from 'stubs/log';
import { generateListStub } from 'stubs/utils';
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 useAddressQuery from './utils/useAddressQuery';
type Props = {
shouldRender?: boolean;
isQueryEnabled?: boolean;
};
const AddressLogs = ({ shouldRender = true, isQueryEnabled = true }: Props) => {
const router = useRouter();
const isMounted = useIsMounted();
const hash = getQueryParamString(router.query.hash);
const { data, isPlaceholderData, isError, pagination } = useQueryWithPages({
resourceName: 'general:address_logs',
pathParams: { hash },
options: {
enabled: isQueryEnabled,
placeholderData: generateListStub<'general:address_logs'>(LOG, 3, { next_page_params: {
block_number: 9005750,
index: 42,
items_count: 50,
transaction_index: 23,
} }),
},
});
const addressQuery = useAddressQuery({ hash });
const actionBar = (
<ActionBar mt={ -6 } showShadow justifyContent={{ base: 'space-between', lg: 'end' }}>
<CsvExport
type="address_logs"
resourceName="general:address_csv_export_logs"
pathParams={{ hash }}
loadingInitial={ pagination.isLoading }
/>
<Pagination ml="auto" { ...pagination }/>
</ActionBar>
);
if (!isMounted || !shouldRender) {
return null;
}
const content = data?.items ? data.items.map((item, index) => (
<LogItem
key={ index }
{ ...item }
type="address"
isLoading={ isPlaceholderData }
defaultDataType={ addressQuery.data?.zilliqa?.is_scilla_contract ? 'UTF-8' : undefined }
/>
)) : null;
return (
<DataListDisplay
isError={ isError }
itemsNum={ data?.items?.length }
emptyText="There are no logs for this address."
actionBar={ actionBar }
>
{ content }
</DataListDisplay>
);
};
export default AddressLogs;