Skip to content

Commit af785d4

Browse files
committed
refactor discreet function to improve timestamp handling and prevent multiple changes in a single iteration
1 parent 494aef8 commit af785d4

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

utils/convertToChartData.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,13 @@ function discreet(raw: RawResult, config: ChartConfig): ChartData {
432432
apiData,
433433
} = config;
434434

435+
let changeApplied = false;
436+
435437
for (let i = 0; i < steps + 1; i++) {
436-
// checks if the next data point falls between the previous and next plot times
437-
if (
438-
workingTimestamp - RESOLUTION_SECONDS <= raw.timestamp &&
439-
raw.timestamp < workingTimestamp
440-
)
438+
if (!changeApplied && raw.timestamp <= workingTimestamp) {
441439
workingQuantity += raw.change;
440+
changeApplied = true;
441+
}
442442

443443
unlocked.push(workingQuantity);
444444
timestamps.push(workingTimestamp);

0 commit comments

Comments
 (0)