diff --git a/packages/app-explorer/src/systems/Home/components/DailyTransaction.tsx b/packages/app-explorer/src/systems/Home/components/DailyTransaction.tsx index 11d989c8..87ba7296 100644 --- a/packages/app-explorer/src/systems/Home/components/DailyTransaction.tsx +++ b/packages/app-explorer/src/systems/Home/components/DailyTransaction.tsx @@ -23,10 +23,23 @@ interface DailyTransactionProps { } const DailyTransaction = (blocks: DailyTransactionProps) => { - const chartData = blocks.blocks?.map((block: any) => ({ - time: dayjs(Number(block.time)).format('HH:mm'), - value: block.value, - })); + const chartData = blocks.blocks?.reduce( + (acc: { [key: string]: number }, block: any) => { + const time = dayjs(Number(block.time)).format('HH:mm'); + const value = +block.value / 3600; + + acc[time] = (acc[time] || 0) + value; + return acc; + }, + {}, + ); + + const chartDataArray = chartData + ? Object.entries(chartData).map(([time, value]) => ({ + time, + value, + })) + : []; const cumilativeTsx = blocks.blocks.reduce( (sum: any, block: any) => sum + Number(block.value), 0, @@ -71,7 +84,7 @@ const DailyTransaction = (blocks: DailyTransactionProps) => { { const blocks = props.blocks; - const chartData = blocks?.map((block: any) => ({ - time: dayjs(Number(block.time)).format('HH:mm'), - value: block.value / 3600, - })); + const chartData = blocks.reduce( + (acc: { [key: string]: number }, block: any) => { + const time = dayjs(Number(block.time)).format('HH:mm'); + const value = +block.value / 3600; + acc[time] = (acc[time] || 0) + value; + return acc; + }, + {}, + ); + + const chartDataArray = chartData + ? Object.entries(chartData).map(([time, value]) => ({ + time, + value, + })) + : []; const averageTPS = blocks.reduce((sum: any, block: any) => sum + Number(block.value), 0) / blocks.length; const highestValue = Math.max( - ...chartData.map((data: any) => Number(data.value)), + ...chartDataArray.map((data: any) => Number(data.value)), ); const getTicks = () => { const ticks: string[] = []; - for (let i = 0; i < chartData.length; i += 6) { - ticks.push(chartData[i].time); + for (let i = 0; i < chartDataArray.length; i += 6) { + ticks.push(chartDataArray[i].time); } return ticks; }; @@ -81,7 +93,7 @@ export const TPS = (props: TPSProps) => { { cursor={{ strokeWidth: 0.1, radius: 10 }} /> - {chartData.map((entry, index) => ( + {chartDataArray.map((entry, index) => (