Files
explore/ui/address/AddressEpochRewards.tsx
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

101 lines
3.1 KiB
TypeScript

import { Box } from '@chakra-ui/react';
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 { EPOCH_REWARD_ITEM } from 'stubs/address';
import { generateListStub } from 'stubs/utils';
import AddressEpochRewardsTable from 'ui/address/epochRewards/AddressEpochRewardsTable';
import ActionBar, { ACTION_BAR_HEIGHT_DESKTOP } from 'ui/shared/ActionBar';
import DataListDisplay from 'ui/shared/DataListDisplay';
import Pagination from 'ui/shared/pagination/Pagination';
import useQueryWithPages from 'ui/shared/pagination/useQueryWithPages';
import AddressEpochRewardsListItem from './epochRewards/AddressEpochRewardsListItem';
type Props = {
shouldRender?: boolean;
isQueryEnabled?: boolean;
};
const AddressEpochRewards = ({ shouldRender = true, isQueryEnabled = true }: Props) => {
const router = useRouter();
const isMounted = useIsMounted();
const hash = getQueryParamString(router.query.hash);
const rewardsQuery = useQueryWithPages({
resourceName: 'general:address_epoch_rewards',
pathParams: {
hash,
},
options: {
enabled: isQueryEnabled && Boolean(hash),
placeholderData: generateListStub<'general:address_epoch_rewards'>(EPOCH_REWARD_ITEM, 50, { next_page_params: {
amount: '1',
items_count: 50,
type: 'voter',
associated_account_address_hash: '1',
epoch_number: 10355938,
} }),
},
});
if (!isMounted || !shouldRender) {
return null;
}
const content = rewardsQuery.data?.items ? (
<>
<Box hideBelow="lg">
<AddressEpochRewardsTable
items={ rewardsQuery.data.items }
top={ rewardsQuery.pagination.isVisible ? ACTION_BAR_HEIGHT_DESKTOP : 0 }
isLoading={ rewardsQuery.isPlaceholderData }
/>
</Box>
<Box hideFrom="lg">
{ rewardsQuery.data.items.map((item, index) => (
<AddressEpochRewardsListItem
key={ item.epoch_number + item.type + item.account.hash + item.associated_account.hash + (rewardsQuery.isPlaceholderData ? String(index) : '') }
item={ item }
isLoading={ rewardsQuery.isPlaceholderData }
/>
)) }
</Box>
</>
) : null;
const actionBar = (
<ActionBar mt={ -6 }>
<CsvExport
type="address_epoch_rewards"
resourceName="general:address_csv_export_celo_election_rewards"
pathParams={{ hash }}
loadingInitial={ rewardsQuery.pagination.isLoading }
/>
{ rewardsQuery.pagination.isVisible && (
<Pagination
ml="auto"
{ ...rewardsQuery.pagination }
/>
) }
</ActionBar>
);
return (
<DataListDisplay
isError={ rewardsQuery.isError }
itemsNum={ rewardsQuery.data?.items?.length }
emptyText="There are no epoch rewards for this address."
actionBar={ actionBar }
>
{ content }
</DataListDisplay>
);
};
export default AddressEpochRewards;