mirror of
https://github.com/hanzonet/explore.git
synced 2026-10-30 18:16:57 +00:00
* Unify stats across relevant pages * add op stats to tx page and change stats titles * demo config * aboba or cat fix * chart tooltip fix * tests * revert config
21 lines
682 B
TypeScript
21 lines
682 B
TypeScript
import type { TimeChartItem, TimeChartItemRaw } from 'ui/shared/chart/types';
|
|
|
|
import { sortByDateDesc } from 'ui/shared/chart/utils/sorts';
|
|
|
|
const nonNullTailReducer = (result: Array<TimeChartItemRaw>, item: TimeChartItemRaw) => {
|
|
if (item.value === null && result.length === 0) {
|
|
return result;
|
|
}
|
|
result.unshift(item);
|
|
return result;
|
|
};
|
|
|
|
const mapNullToZero: (item: TimeChartItemRaw) => TimeChartItem = (item) => ({ ...item, value: Number(item.value) });
|
|
|
|
export default function prepareChartItems(items: Array<TimeChartItemRaw>) {
|
|
return items
|
|
.sort(sortByDateDesc)
|
|
.reduceRight(nonNullTailReducer, [] as Array<TimeChartItemRaw>)
|
|
.map(mapNullToZero);
|
|
}
|