From eb9e5de45b961be3a66036894ecc1de061672aa6 Mon Sep 17 00:00:00 2001 From: jiangzhewen Date: Tue, 12 May 2026 15:06:30 +0800 Subject: [PATCH] Add history CSV export --- src/api/history.js | 36 ++- src/components/layout/Modals.svelte | 7 +- src/components/modals/ExportHistoryCSV.svelte | 289 ++++++++++++++++++ src/components/trade/account/Account.svelte | 5 +- src/lib/icons.js | 7 +- 5 files changed, 328 insertions(+), 16 deletions(-) create mode 100644 src/components/modals/ExportHistoryCSV.svelte diff --git a/src/api/history.js b/src/api/history.js index ce1e5cb..4e9ebf6 100644 --- a/src/api/history.js +++ b/src/api/history.js @@ -1,39 +1,51 @@ import { get } from 'svelte/store' import { DEFAULT_HISTORY_COUNT } from '@lib/config' -import { address, history, lastHistoryItemsCount, historySortKey, historyOrderStatusToShow } from '@lib/stores' +import { address, history, lastHistoryItemsCount, historyOrderStatusToShow } from '@lib/stores' import { getLabelForAsset, getChainData } from '@lib/utils' -export async function getUserHistory(params) { +export async function fetchUserHistoryPage(params) { const dataEndpoint = getChainData('dataEndpoint'); - let _address = get(address); + if (!params) params = {}; + + let _address = params.address || get(address); if (!_address) return; _address = _address.toLowerCase(); - if (!params) params = {}; - let { first, skip, - diff + statusesToShow } = params; if (!first) first = DEFAULT_HISTORY_COUNT; if (!skip) skip = 0; - const statusesToShow = get(historyOrderStatusToShow); - - const sortKey = get(historySortKey); // [columnName, isDesc] + if (!statusesToShow) statusesToShow = get(historyOrderStatusToShow); let sortBy = 'timestamp'; let sortDirection = 'desc'; + const response = await fetch(`${dataEndpoint}/history/${_address}?chain=arbitrum&limit=${first}&skip=${skip}&sortBy=${sortBy}&sortDirection=${sortDirection}&status=${statusesToShow.join(',')}`); + const orders = await response.json() || []; + + return orders; +} + +export async function getUserHistory(params) { + + if (!params) params = {}; + + let { + skip, + diff + } = params; + try { - const response = await fetch(`${dataEndpoint}/history/${_address}?chain=arbitrum&limit=${first}&skip=${skip}&sortBy=${sortBy}&sortDirection=${sortDirection}&status=${statusesToShow.join(',')}`); - const orders = await response.json() || []; + const orders = await fetchUserHistoryPage(params) || []; lastHistoryItemsCount.set(orders.length); @@ -66,4 +78,4 @@ export async function getUserHistory(params) { } return true; -} \ No newline at end of file +} diff --git a/src/components/layout/Modals.svelte b/src/components/layout/Modals.svelte index 03b829d..5f16556 100644 --- a/src/components/layout/Modals.svelte +++ b/src/components/layout/Modals.svelte @@ -13,6 +13,7 @@ import StakeCAP from '../modals/StakeCAP.svelte' import UnstakeCAP from '../modals/UnstakeCAP.svelte' import HistoryOrderStatus from '../modals/HistoryOrderStatus.svelte' + import ExportHistoryCSV from '../modals/ExportHistoryCSV.svelte' import Settings from '../modals/Settings.svelte' @@ -65,6 +66,10 @@ {/if} +{#if $activeModal && $activeModal.name == 'ExportHistoryCSV'} + +{/if} + {#if $activeModal && $activeModal.name == 'MarketInfo'} -{/if} \ No newline at end of file +{/if} diff --git a/src/components/modals/ExportHistoryCSV.svelte b/src/components/modals/ExportHistoryCSV.svelte new file mode 100644 index 0000000..7ecb2fe --- /dev/null +++ b/src/components/modals/ExportHistoryCSV.svelte @@ -0,0 +1,289 @@ + + + + + +
+
+ Download a CSV report for the selected trading history range. Leave dates empty to export all available history. +
+ +
+ + +
+ + {#if errorMessage} +
{errorMessage}
+ {/if} + + +
+
diff --git a/src/components/trade/account/Account.svelte b/src/components/trade/account/Account.svelte index a589a71..cc451cd 100644 --- a/src/components/trade/account/Account.svelte +++ b/src/components/trade/account/Account.svelte @@ -10,7 +10,7 @@ import tooltip from '@lib/tooltip' import { DEFAULT_CHAIN_ID } from '@lib/config' - import { TABLE_ICON, FILTER_ICON, XMARK_ICON, TROPHY_ICON } from '@lib/icons' + import { TABLE_ICON, FILTER_ICON, XMARK_ICON, TROPHY_ICON, DOWNLOAD_ICON } from '@lib/icons' import { address, chainId, ordersSorted, positionsSorted } from '@lib/stores' import { showModal } from '@lib/ui' @@ -191,6 +191,7 @@ - \ No newline at end of file + diff --git a/src/lib/icons.js b/src/lib/icons.js index 36c12fd..3f94073 100644 --- a/src/lib/icons.js +++ b/src/lib/icons.js @@ -137,6 +137,11 @@ export const TABLE_ICON = ` `; +export const DOWNLOAD_ICON = ` + + +`; + export const FILTER_ICON = ` @@ -191,4 +196,4 @@ export const CHECKMARK_CIRCLE_ICON = ` export const CHECKMARK_CIRCLE_INVERTED_ICON = ` -`; \ No newline at end of file +`;