From af6603fc8aa347aed2d808421d31b940829ce018 Mon Sep 17 00:00:00 2001 From: pocin <8642344+pocin@users.noreply.github.com> Date: Tue, 2 Apr 2024 10:51:04 +0200 Subject: [PATCH 1/3] fix: consistent chart metric name formatting --- .../Chart/V2StrategyMetricsChart.tsx | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/Chart/V2StrategyMetricsChart.tsx b/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/Chart/V2StrategyMetricsChart.tsx index cfc12b81b..1f47d7b80 100644 --- a/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/Chart/V2StrategyMetricsChart.tsx +++ b/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/Chart/V2StrategyMetricsChart.tsx @@ -72,17 +72,29 @@ const V2StrategyMetricsChart: React.FC<{ selectedInterval: ChartSupportedTimeInterval; }> = ({ dashboardData, selectedMetric, selectedInterval }) => { // uncamel-case the metric names - const formatMetricName = (name: string) => - // format only the selected metric name (the selected metric or all lines in a TRV chart) - name === selectedMetric || isTRVDashboard(dashboardData.key) - ? name + const formatMetricName = (name: string) => { + // format only + // - the selected metric + // - all lines in TRV chart + // - netDebt chart components + // the remaining cases are individual debt tokens (sUSDe, sDAI, rsETH, ...) + // which we keep as is + if ( + name === selectedMetric || + isTRVDashboard(dashboardData.key) || + selectedMetric === 'netDebtUSD' + ) { + return ( + name // // insert a space before all caps .replace(/([A-Z][a-z])/g, ' $1') // // uppercase the first character .replace(/^./, (str) => str.toUpperCase()) .replace(/USD$/, '') - : // Individual debt token tickers remain unchanged - name; + ); + } + return name; + }; const tooltipValuesFormatter = (value: number, name: string) => [ numberFormatter.format(value), formatMetricName(name), From 12b20339b54e409962e6b4a471c164d9520233b6 Mon Sep 17 00:00:00 2001 From: pocin <8642344+pocin@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:05:50 +0200 Subject: [PATCH 2/3] fix: strategyDailySnapshots pagination strategy --- .../hooks/use-dashboardv2-daily-snapshots.ts | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/hooks/use-dashboardv2-daily-snapshots.ts b/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/hooks/use-dashboardv2-daily-snapshots.ts index 59bf4944e..098be216d 100644 --- a/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/hooks/use-dashboardv2-daily-snapshots.ts +++ b/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/hooks/use-dashboardv2-daily-snapshots.ts @@ -82,23 +82,18 @@ async function fetchStrategyHourlySnapshots() { async function fetchStrategyDailySnapshots() { const now = new Date(); // the largest value from the chart time range selector 1W | 1M | 1Y - let since = Math.floor((now.getTime() - ONE_YEAR_MS) / 1000).toString(); + const since = Math.floor((now.getTime() - ONE_YEAR_MS) / 1000).toString(); const result: V2StrategySnapshot[] = []; - const itemsPerPage = 1000; // current max page size + const MAX_PAGE_SIZE = 1000; // current max page size + let skip = 0; while (true) { - // we could be missing data with this pagination strategy if - // the dataset contain snapshots for different strats - // created at the exact same timestamp - // and all such snapshots do not fit in the same page - // imho very unlikely, but possible? - // solution would be to use timestamp_GTE: ${since} - // and deduplicate two consecutive pages const query = ` query { - strategyDailySnapshots(first: ${itemsPerPage}, + strategyDailySnapshots(first: ${MAX_PAGE_SIZE}, orderBy: timestamp, orderDirection: asc, - where: {timestamp_gt: ${since}}) { + where: {timestamp_gt: ${since}} + skip: ${skip}) { ${QUERIED_FIELDS} } }`; @@ -106,11 +101,9 @@ async function fetchStrategyDailySnapshots() { const itemsOnPage = page.data?.strategyDailySnapshots.length ?? 0; if (page.data) { result.push(...page.data.strategyDailySnapshots); - const latestSnapshot = page.data.strategyDailySnapshots.at(-1); - if (!latestSnapshot) break; - since = latestSnapshot.timestamp; + skip += itemsOnPage } - if (itemsOnPage < itemsPerPage) { + if (itemsOnPage < MAX_PAGE_SIZE) { break; } } From 84beb6a5fea14b6b5bfc5865b74b01da96487466 Mon Sep 17 00:00:00 2001 From: pocin <8642344+pocin@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:25:25 +0200 Subject: [PATCH 3/3] style: run prettier --- .../Dashboard/hooks/use-dashboardv2-daily-snapshots.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/hooks/use-dashboardv2-daily-snapshots.ts b/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/hooks/use-dashboardv2-daily-snapshots.ts index 098be216d..a939b1199 100644 --- a/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/hooks/use-dashboardv2-daily-snapshots.ts +++ b/apps/dapp/src/components/Pages/Core/DappPages/Dashboard/hooks/use-dashboardv2-daily-snapshots.ts @@ -82,7 +82,7 @@ async function fetchStrategyHourlySnapshots() { async function fetchStrategyDailySnapshots() { const now = new Date(); // the largest value from the chart time range selector 1W | 1M | 1Y - const since = Math.floor((now.getTime() - ONE_YEAR_MS) / 1000).toString(); + const since = Math.floor((now.getTime() - ONE_YEAR_MS) / 1000).toString(); const result: V2StrategySnapshot[] = []; const MAX_PAGE_SIZE = 1000; // current max page size let skip = 0;