Skip to content

Commit f7411fb

Browse files
committed
fix: charts
1 parent 45b80f2 commit f7411fb

File tree

3 files changed

+25
-208
lines changed

3 files changed

+25
-208
lines changed

pages/api/sgho-apy.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,31 @@ type ApiResponse = {
2929

3030
/**
3131
* Transform GraphQL data to the format expected by the frontend
32+
* Aggregates multiple hourly entries per day to a single daily entry
3233
*/
3334
const transformGraphQLData = (graphqlData: SGhoRatesData[]) => {
34-
return graphqlData.map((item) => {
35-
// Convert blockHour (ISO datetime) to date string (YYYY-MM-DD)
36-
const date = new Date(item.blockHour);
37-
const dateString = date.toISOString().split('T')[0];
38-
39-
return {
40-
day: {
41-
value: dateString,
42-
},
43-
merit_apy: item.apr,
44-
};
35+
const dailyData = new Map<string, { timestamp: Date; merit_apy: number }>();
36+
37+
graphqlData.forEach((item) => {
38+
const timestamp = new Date(item.blockHour);
39+
const dateString = timestamp.toISOString().split('T')[0];
40+
41+
// Keep the latest entry for each day (or first if no existing entry)
42+
const existing = dailyData.get(dateString);
43+
if (!existing || timestamp > existing.timestamp) {
44+
dailyData.set(dateString, {
45+
timestamp,
46+
merit_apy: item.apr,
47+
});
48+
}
4549
});
50+
51+
return Array.from(dailyData.entries()).map(([dateString, { merit_apy }]) => ({
52+
day: {
53+
value: dateString,
54+
},
55+
merit_apy,
56+
}));
4657
};
4758

4859
/**
@@ -148,10 +159,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
148159
});
149160
}
150161

151-
// Transform and sort data
152162
const transformedData = transformGraphQLData(result.data.aaveV3RatesSgho);
153163

154-
// Sort by date (oldest first) since we removed ordering from GraphQL query
155164
const sortedData = transformedData.sort((a, b) => {
156165
const dateA = new Date(a.day.value);
157166
const dateB = new Date(b.day.value);

src/modules/sGho/SGhoDepositPanel.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,10 @@ export const SGHODepositPanel: React.FC<SGHODepositPanelProps> = ({
508508
</Typography>
509509
<FormattedNumber
510510
sx={{ mr: 2 }}
511-
value={stakeData.stakeTokenTotalSupply}
511+
value={stakeData.totalSupplyUSDFormatted}
512512
variant="secondary14"
513+
symbol="USD"
514+
visibleDecimals={2}
513515
/>
514516
</Box>
515517

src/services/TokenLogicGraphQLService.ts

Lines changed: 0 additions & 194 deletions
This file was deleted.

0 commit comments

Comments
 (0)