Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chart label formatting and pagination strategy #979

Merged
merged 3 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,28 @@ 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}
}
}`;
const page = await fetchGenericSubgraph<FetchV2StrategyDailySnapshotResponse>(env.subgraph.templeV2, query);
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;
}
}
Expand Down
Loading