feat: export trading history to CSV#131
Open
subhajitlucky wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a CSV export feature for the Trading History view, including optional date range selection and background CSV generation to keep the UI responsive.
Changes:
- Added an export toolbar (From/To date inputs + export button) above the History table and implemented CSV download flow.
- Added history API helpers to fetch paginated history and aggregate pages for export.
- Introduced a new download SVG icon for the export button.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| src/components/trade/account/History.svelte | Adds date range selectors, export button, worker-based CSV building, and download logic. |
| src/api/history.js | Refactors request URL building, adds a paged fetch helper, and implements multi-page export retrieval. |
| src/lib/icons.js | Adds DOWNLOAD_ICON for the export UI. |
Files not reviewed (1)
- src/lib/icons.js: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+155
to
+158
| function getExportRow(rawItem) { | ||
| const item = formatHistoryItem(rawItem); | ||
| const pnlPercent = item.pnl && item.margin ? 100 * item.pnl / item.margin : ''; | ||
|
|
Comment on lines
+170
to
+175
| item.status, | ||
| item.reason || '', | ||
| item.pnl ? `${formatForDisplay(item.pnl)} ${item.asset}` : '', | ||
| pnlPercent ? `${formatForDisplay(pnlPercent, true)}%` : '', | ||
| item.fee ? `${formatForDisplay(item.fee)} ${item.asset}` : '', | ||
| formatDate(item.expiry) || '', |
| self.onmessage = function(event) { | ||
| const escapeCell = function(value) { | ||
| if (value === undefined || value === null) return ''; | ||
| const text = String(value); |
| <div class='export-toolbar'> | ||
| <label>From <input type='date' bind:value={exportFrom} aria-label='Export history from date'></label> | ||
| <label>To <input type='date' bind:value={exportTo} aria-label='Export history to date'></label> | ||
| <button on:click={exportHistory} disabled={isExporting || isLoading} use:tooltip={{content: 'Export history as CSV'}}> |
| @@ -4,7 +4,7 @@ | |||
| import { address, history, lastHistoryItemsCount, historySortKey, historyOrderStatusToShow } from '@lib/stores' | |||
| import { getLabelForAsset, getChainData } from '@lib/utils' | |||
Comment on lines
18
to
33
| let { | ||
| first, | ||
| skip, | ||
| diff | ||
| } = params; | ||
|
|
||
| if (!first) first = DEFAULT_HISTORY_COUNT; | ||
| if (!skip) skip = 0; | ||
|
|
||
| const statusesToShow = get(historyOrderStatusToShow); | ||
|
|
||
| const sortKey = get(historySortKey); // [columnName, isDesc] | ||
|
|
||
| let sortBy = 'timestamp'; | ||
| let sortDirection = 'desc'; | ||
|
|
| if (!url) return []; | ||
|
|
||
| const response = await fetch(url); | ||
| if (!response.ok) return []; |
c248f2c to
2997c0e
Compare
Author
|
Updated after automated review:
Verification:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14.\n\n## Summary\n- Add optional from/to date selectors above the History table.\n- Fetch all matching history pages using the existing status filter and timestamp range.\n- Generate and download a CSV report with core trading-history fields.\n- Use a browser Worker blob for CSV escaping/joining so large exports do not block the UI formatting step.\n\n## Verification\n- npm run build\n- git diff --check\n\nNote: build passes with the repository's existing Svelte/Rollup warnings.