diff --git a/src/api/history.js b/src/api/history.js index ce1e5cb..22f9f6f 100644 --- a/src/api/history.js +++ b/src/api/history.js @@ -4,10 +4,15 @@ import { DEFAULT_HISTORY_COUNT } from '@lib/config' import { address, history, lastHistoryItemsCount, historySortKey, historyOrderStatusToShow } from '@lib/stores' import { getLabelForAsset, getChainData } from '@lib/utils' +function getHistoryUrl(params) { + const dataEndpoint = getChainData('dataEndpoint'); + const statusesToShow = get(historyOrderStatusToShow); + + return `${dataEndpoint}/history/${params.address}?chain=arbitrum&limit=${params.first}&skip=${params.skip}&sortBy=${params.sortBy}&sortDirection=${params.sortDirection}&status=${statusesToShow.join(',')}`; +} + export async function getUserHistory(params) { - const dataEndpoint = getChainData('dataEndpoint'); - let _address = get(address); if (!_address) return; @@ -24,15 +29,13 @@ export async function getUserHistory(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'; try { - const response = await fetch(`${dataEndpoint}/history/${_address}?chain=arbitrum&limit=${first}&skip=${skip}&sortBy=${sortBy}&sortDirection=${sortDirection}&status=${statusesToShow.join(',')}`); + const response = await fetch(getHistoryUrl({address: _address, first, skip, sortBy, sortDirection})); const orders = await response.json() || []; lastHistoryItemsCount.set(orders.length); @@ -66,4 +69,43 @@ export async function getUserHistory(params) { } return true; -} \ No newline at end of file +} + +export async function getUserHistoryForExport(params) { + let _address = get(address); + if (!_address) return []; + + if (!params) params = {}; + + const fromTimestamp = params.fromTimestamp || 0; + const toTimestamp = params.toTimestamp || Date.now() / 1000; + const pageSize = 500; + const maxPages = 200; + const sortBy = 'timestamp'; + const sortDirection = 'desc'; + + _address = _address.toLowerCase(); + + let skip = 0; + let rows = []; + + for (let page = 0; page < maxPages; page++) { + const response = await fetch(getHistoryUrl({address: _address, first: pageSize, skip, sortBy, sortDirection})); + const pageRows = await response.json() || []; + + for (const row of pageRows) { + const timestamp = row.timestamp * 1; + if (!timestamp || timestamp > toTimestamp) continue; + if (timestamp >= fromTimestamp) rows.push(row); + } + + if (pageRows.length < pageSize) break; + + const oldestTimestamp = pageRows[pageRows.length - 1]?.timestamp * 1; + if (fromTimestamp && oldestTimestamp && oldestTimestamp < fromTimestamp) break; + + skip += pageSize; + } + + return rows; +} diff --git a/src/components/layout/Modals.svelte b/src/components/layout/Modals.svelte index 03b829d..fce09e6 100644 --- a/src/components/layout/Modals.svelte +++ b/src/components/layout/Modals.svelte @@ -12,6 +12,7 @@ import MarketInfo from '../modals/MarketInfo.svelte' import StakeCAP from '../modals/StakeCAP.svelte' import UnstakeCAP from '../modals/UnstakeCAP.svelte' + import ExportHistory from '../modals/ExportHistory.svelte' import HistoryOrderStatus from '../modals/HistoryOrderStatus.svelte' import Settings from '../modals/Settings.svelte' @@ -65,6 +66,10 @@ {/if} +{#if $activeModal && $activeModal.name == 'ExportHistory'} + +{/if} + {#if $activeModal && $activeModal.name == 'MarketInfo'} -{/if} \ No newline at end of file +{/if} diff --git a/src/components/modals/ExportHistory.svelte b/src/components/modals/ExportHistory.svelte new file mode 100644 index 0000000..b1b96d6 --- /dev/null +++ b/src/components/modals/ExportHistory.svelte @@ -0,0 +1,238 @@ + + + + + +
+
+ Download a CSV report for the currently selected history status filters. +
+ +
+ +
+ + {#if timeframe == 'custom'} +
+
+ + +
+
+ + +
+
+ {/if} + +
+
diff --git a/src/components/trade/account/Account.svelte b/src/components/trade/account/Account.svelte index a589a71..2f13ecf 100644 --- a/src/components/trade/account/Account.svelte +++ b/src/components/trade/account/Account.svelte @@ -139,17 +139,24 @@ margin-right: 10px; } - .tools a { + .tools a, + .tools button { display: flex; align-items: center; color: var(--text1); margin-left: 16px; padding: 4px 0; } - .tools a:hover { + .tools button { + background: none; + font: inherit; + } + .tools a:hover, + .tools button:hover { color: var(--text0); } - .tools a:not(.leaderboard-link) :global(svg) { + .tools a:not(.leaderboard-link) :global(svg), + .tools button :global(svg) { fill: currentColor; height: 16px; } @@ -191,6 +198,7 @@
{#if panel == 'history'} {showModal('HistoryOrderStatus')}} use:tooltip={{content: 'Filter history'}}>{@html FILTER_ICON} + {/if} {showModal('CustomizeColumns', {panel, allColumns: allColumns[panel]})}}>{@html TABLE_ICON} {#if panel == 'orders' && $ordersSorted.length} @@ -205,4 +213,4 @@ {#if panel == 'history'}{/if}
- \ No newline at end of file +