Skip to content

Commit

Permalink
Support new CSV export limit in the UI
Browse files Browse the repository at this point in the history
Fixes #2215
  • Loading branch information
tom2drum committed Sep 13, 2024
1 parent d1632da commit 9aa90a3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/api/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import type {
BlockEpochElectionRewardDetailsResponse,
} from 'types/api/block';
import type { ChartMarketResponse, ChartSecondaryCoinPriceResponse, ChartTransactionResponse } from 'types/api/charts';
import type { BackendVersionConfig } from 'types/api/configs';
import type { BackendVersionConfig, CsvExportConfig } from 'types/api/configs';
import type {
SmartContract,
SmartContractVerificationConfigRaw,
Expand Down Expand Up @@ -917,6 +917,9 @@ export const RESOURCES = {
config_backend_version: {
path: '/api/v2/config/backend-version',
},
config_csv_export: {
path: '/api/v2/config/csv-export',
},

// CSV EXPORT
csv_export_token_holders: {
Expand Down Expand Up @@ -1114,6 +1117,7 @@ never;
/* eslint-disable @typescript-eslint/indent */
export type ResourcePayloadB<Q extends ResourceName> =
Q extends 'config_backend_version' ? BackendVersionConfig :
Q extends 'config_csv_export' ? CsvExportConfig :
Q extends 'address_metadata_info' ? AddressMetadataInfo :
Q extends 'address_metadata_tag_types' ? PublicTagTypesResponse :
Q extends 'blob' ? Blob :
Expand Down
4 changes: 4 additions & 0 deletions types/api/configs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export interface BackendVersionConfig {
backend_version: string;
}

export interface CsvExportConfig {
limit: number;
}
1 change: 1 addition & 0 deletions ui/pages/CsvExport.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test('base view +@mobile +@dark-mode', async({ render, page, mockApiResponse })
},
};
await mockApiResponse('address', addressMock.validator, { pathParams: { hash: addressMock.hash } });
await mockApiResponse('config_csv_export', { limit: 42123 });

const component = await render(<Box sx={{ '.recaptcha': { w: '304px', h: '78px' } }}><CsvExport/></Box>, { hooksConfig });

Expand Down
14 changes: 11 additions & 3 deletions ui/pages/CsvExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ const CsvExport = () => {
},
});

const isLoading = addressQuery.isPending || (exportTypeParam === 'holders' && tokenQuery.isPending);
const configQuery = useApiQuery('config_csv_export', {
queryOptions: {
enabled: Boolean(addressHash),
},
});

const isLoading = addressQuery.isPending || configQuery.isPending || (exportTypeParam === 'holders' && tokenQuery.isPending);

const backLink = React.useMemo(() => {
const hasGoBackLink = appProps.referrer && appProps.referrer.includes('/address');
Expand Down Expand Up @@ -147,6 +153,8 @@ const CsvExport = () => {
return null;
}

const limit = (configQuery.data?.limit || 10_000).toLocaleString(undefined, { maximumFractionDigits: 3, notation: 'compact' });

if (exportTypeParam === 'holders') {
return (
<Flex mb={ 10 } whiteSpace="pre-wrap" flexWrap="wrap">
Expand All @@ -160,7 +168,7 @@ const CsvExport = () => {
noSymbol
/>
<span> to CSV file. </span>
<span>Exports are limited to the top 10K holders by amount held.</span>
<span>Exports are limited to the top { limit } holders by amount held.</span>
</Flex>
);
}
Expand All @@ -176,7 +184,7 @@ const CsvExport = () => {
<span>{ nbsp }</span>
{ filterType && filterValue && <span>with applied filter by { filterType } ({ filterValue }) </span> }
<span>to CSV file. </span>
<span>Exports are limited to the last 10K { exportType.text }.</span>
<span>Exports are limited to the last { limit } { exportType.text }.</span>
</Flex>
);
})();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.