Skip to content

Commit 1c93b17

Browse files
committed
create section unlock percentage
1 parent fcdd9fb commit 1c93b17

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

utils/categoryData.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,33 @@ export function createCategoryData(
7070
final: normalizeAllocations(rawFinalAllocations),
7171
};
7272
}
73+
74+
export function createSectionData(
75+
data: ChartSection[]
76+
): { current: Allocations; final: Allocations } {
77+
if (!data.length) return { current: {}, final: {} };
78+
const rawCurrentAllocations: Allocations = {};
79+
const rawFinalAllocations: Allocations = {};
80+
const timestampNow: number = unixTimestampNow();
81+
82+
data.forEach((section: ChartSection) => {
83+
const s = section;
84+
if (!s) return;
85+
const currentEntryIndex = s.data.timestamps.findIndex(
86+
(t: number) => timestampNow - RESOLUTION_SECONDS < t && t < timestampNow
87+
);
88+
const finalEntryIndex = s.data.unlocked.length - 1;
89+
const current =
90+
s.data.unlocked[
91+
currentEntryIndex == -1 ? finalEntryIndex : currentEntryIndex
92+
];
93+
const final = s.data.unlocked[finalEntryIndex];
94+
rawCurrentAllocations[s.section] = current;
95+
rawFinalAllocations[s.section] = final;
96+
});
97+
98+
return {
99+
current: normalizeAllocations(rawCurrentAllocations),
100+
final: normalizeAllocations(rawFinalAllocations),
101+
};
102+
}

0 commit comments

Comments
 (0)