diff --git a/lib/api/resources.ts b/lib/api/resources.ts index 5f8453420c..c8db6bc270 100644 --- a/lib/api/resources.ts +++ b/lib/api/resources.ts @@ -739,6 +739,12 @@ export const RESOURCES = { path: '/api/v2/config/backend-version', }, + // CSV EXPORT + csv_export_token_holders: { + path: '/api/v2/tokens/:hash/holders/csv', + pathParams: [ 'hash' as const ], + }, + // OTHER api_v2_key: { path: '/api/v2/key', diff --git a/types/client/address.ts b/types/client/address.ts index 719aa339bf..e7a181ee3b 100644 --- a/types/client/address.ts +++ b/types/client/address.ts @@ -8,4 +8,8 @@ export type CsvExportParams = { type: 'logs'; filterType?: 'topic'; filterValue?: string; +} | { + type: 'holders'; + filterType?: undefined; + filterValue?: undefined; } diff --git a/ui/csvExport/CsvExportForm.tsx b/ui/csvExport/CsvExportForm.tsx index 1105757b2c..917d706e8f 100644 --- a/ui/csvExport/CsvExportForm.tsx +++ b/ui/csvExport/CsvExportForm.tsx @@ -21,9 +21,10 @@ interface Props { filterType?: CsvExportParams['filterType'] | null; filterValue?: CsvExportParams['filterValue'] | null; fileNameTemplate: string; + exportType: CsvExportParams['type'] | undefined; } -const CsvExportForm = ({ hash, resource, filterType, filterValue, fileNameTemplate }: Props) => { +const CsvExportForm = ({ hash, resource, filterType, filterValue, fileNameTemplate, exportType }: Props) => { const formApi = useForm({ mode: 'onBlur', defaultValues: { @@ -36,10 +37,10 @@ const CsvExportForm = ({ hash, resource, filterType, filterValue, fileNameTempla const onFormSubmit: SubmitHandler = React.useCallback(async(data) => { try { - const url = buildUrl(resource, undefined, { + const url = buildUrl(resource, { hash } as never, { address_id: hash, - from_period: data.from, - to_period: data.to, + from_period: exportType !== 'holders' ? data.from : null, + to_period: exportType !== 'holders' ? data.to : null, filter_type: filterType, filter_value: filterValue, recaptcha_response: data.reCaptcha, @@ -56,11 +57,11 @@ const CsvExportForm = ({ hash, resource, filterType, filterValue, fileNameTempla } const blob = await response.blob(); - downloadBlob( - blob, - `${ fileNameTemplate }_${ hash }_${ data.from }_${ data.to } - ${ filterType && filterValue ? '_with_filter_type_' + filterType + '_value_' + filterValue : '' }.csv`, - ); + const fileName = exportType === 'holders' ? + `${ fileNameTemplate }_${ hash }.csv` : + // eslint-disable-next-line max-len + `${ fileNameTemplate }_${ hash }_${ data.from }_${ data.to }${ filterType && filterValue ? '_with_filter_type_' + filterType + '_value_' + filterValue : '' }.csv`; + downloadBlob(blob, fileName); } catch (error) { toast({ @@ -73,7 +74,7 @@ const CsvExportForm = ({ hash, resource, filterType, filterValue, fileNameTempla }); } - }, [ fileNameTemplate, hash, resource, filterType, filterValue, toast ]); + }, [ resource, hash, exportType, filterType, filterValue, fileNameTemplate, toast ]); return ( @@ -82,8 +83,8 @@ const CsvExportForm = ({ hash, resource, filterType, filterValue, fileNameTempla onSubmit={ handleSubmit(onFormSubmit) } > - - + { exportType !== 'holders' && } + { exportType !== 'holders' && }