Skip to content

Commit

Permalink
Merge pull request #5859 from balancer/fix/chart-old-pool
Browse files Browse the repository at this point in the history
fix: old pools charts
  • Loading branch information
alter-eggo committed Jun 21, 2024
2 parents 8c5ddaa + 6a7e5fd commit b9df6da
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 23 deletions.
54 changes: 32 additions & 22 deletions src/components/contextual/pages/pool/PoolChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,19 @@ function getFeesData(
isAllTimeSelected: boolean,
pariodLastSnapshotIdx: number
) {
const feesValues = periodSnapshots.map(
(snapshot, idx): readonly [string, number] => {
const feesValues = periodSnapshots
.map((snapshot, idx) => {
const value = parseFloat(snapshot.swapFees);
let prevValue: number;
// get value of prev snapshot
// if it is last value among all snapshots, then prev value is 0
if (idx === snapshotValues.value.length - 1) {
prevValue = 0;
if (isAllTimeSelected) {
return;
} else {
prevValue = 0;
}
} // if it is last value among certain period snapshots, then we get prev value from all snapshots
else if (idx === pariodLastSnapshotIdx) {
prevValue = parseFloat(snapshotValues.value[idx + 1].swapFees);
Expand All @@ -261,8 +265,8 @@ function getFeesData(
value - prevValue,
]);
return result;
}
);
})
.filter(Boolean) as (readonly [string, number])[];
// add 0 values in order to show chart properly
if (periodSnapshots.length < 30) {
Expand Down Expand Up @@ -296,23 +300,29 @@ function getVolumeData(
isAllTimeSelected: boolean,
pariodLastSnapshotIdx: number
): PoolChartData {
const volumeData = periodSnapshots.map((snapshot, idx) => {
const value = parseFloat(snapshot.swapVolume);
let prevValue: number;
// get value of prev snapshot
if (idx === snapshotValues.value.length - 1) {
prevValue = 0;
} else if (idx === pariodLastSnapshotIdx) {
prevValue = parseFloat(snapshotValues.value[idx + 1].swapVolume);
} else {
prevValue = parseFloat(periodSnapshots[idx + 1].swapVolume);
}
return Object.freeze<[string, number]>([
timestamps.value[idx],
value - prevValue,
]);
});
const volumeData = periodSnapshots
.map((snapshot, idx) => {
const value = parseFloat(snapshot.swapVolume);
let prevValue: number;
// get value of prev snapshot
if (idx === snapshotValues.value.length - 1) {
if (isAllTimeSelected) {
return;
} else {
prevValue = 0;
}
} else if (idx === pariodLastSnapshotIdx) {
prevValue = parseFloat(snapshotValues.value[idx + 1].swapVolume);
} else {
prevValue = parseFloat(periodSnapshots[idx + 1].swapVolume);
}
return Object.freeze<[string, number]>([
timestamps.value[idx],
value - prevValue,
]);
})
.filter(Boolean) as (readonly [string, number])[];
// add 0 values in order to show chart properly
if (periodSnapshots.length < 30) {
Expand Down
13 changes: 12 additions & 1 deletion src/composables/queries/usePoolSnapshotsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PoolSnapshots } from '@/services/pool/types';

import useNetwork from '../useNetwork';
import usePoolQuery from './usePoolQuery';
import { oneDayInMs } from '../useTime';

type QueryOptions = QueryObserverOptions<PoolSnapshots>;

Expand Down Expand Up @@ -47,10 +48,20 @@ export default function usePoolSnapshotsQuery(
if (!pool.value && !storedPool) throw new Error('No pool');

const createTime = storedPool?.createTime || pool.value?.createTime || 0;

const nowTimestap = new Date().getTime();
const thousandDaysInMs = 1000 * oneDayInMs;

let timestamp = Math.floor((nowTimestap - thousandDaysInMs) / 1000);

if (timestamp < createTime) {
timestamp = createTime;
}

return await balancerSubgraphService.poolSnapshots.get({
where: {
pool: id.toLowerCase(),
timestamp_gt: createTime,
timestamp_gt: timestamp,
},
});
};
Expand Down

0 comments on commit b9df6da

Please sign in to comment.