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

48 lines
1.2 KiB
TypeScript

import type { CsvExportType } from '../types/client';
import type config from 'configs/app';
import dayjs from 'lib/date/dayjs';
import getPrefixByFilter from './get-prefix-by-filter';
interface Params {
type: CsvExportType;
params: Record<string, string>;
chainConfig?: typeof config;
}
export default function getFileName({ type, params, chainConfig }: Params): string {
const chainText = chainConfig?.chain.name ? `${ chainConfig.chain.name.replace(' ', '_').toLowerCase() }` : '';
if (type === 'token_holders') {
return [
chainText,
'token_holders',
params.hash,
].filter(Boolean).join('_') + '.csv';
}
if (type.startsWith('address_')) {
const dateText = params.from_period && params.to_period ? `from_${ params.from_period }_to_${ params.to_period }` : '';
const entityPrefix = getPrefixByFilter(params?.filter_type, params?.filter_value);
return [
chainText,
entityPrefix,
type,
params.hash,
dateText,
].filter(Boolean).join('_') + '.csv';
}
if (type === 'advanced_filters') {
return [
chainText,
'filtered_txs',
dayjs().format('YYYY-MM-DD-HH-mm-ss'),
].filter(Boolean).join('_') + '.csv';
}
return 'data.csv';
}