diff --git a/src/pages/Blocks/Blocks.helpers.tsx b/src/pages/Blocks/Blocks.helpers.tsx index a5181132..9b1d931e 100644 --- a/src/pages/Blocks/Blocks.helpers.tsx +++ b/src/pages/Blocks/Blocks.helpers.tsx @@ -1,4 +1,3 @@ -import { differenceInSeconds } from 'date-fns'; import Tooltip from '@mui/material/Tooltip'; import parse from 'html-react-parser'; import TimeAgo from 'react-timeago'; @@ -42,27 +41,21 @@ export const DATA_FETCH_LIMIT = 40; export const DATA_OFFSET = 0; export const DATA_DEFAULT_SORT = 'DESC'; -const getDifferenceInMinutes = (startDate: number, endDate: number, variant = '') => { - const diff = parseFloat((differenceInSeconds(endDate, startDate) / 60).toFixed(1)); - if (variant === 'text') { - return `${diff} ${translate(diff === 1 ? 'pages.blocks.minute' : 'pages.blocks.minutes')}`; - } - - return ( - <> - {diff} {translate(diff === 1 ? 'pages.blocks.minute' : 'pages.blocks.minutes')} - - ); -}; - export const transformTableData = (transactions: Array) => transactions .slice(0, transactions.length - 1) .map( - ( - { id, timestamp, transactionCount, height, ticketsList, size, totalTickets, type }, - index, - ) => { + ({ + id, + timestamp, + transactionCount, + height, + ticketsList, + size, + totalTickets, + type, + timeInMinutesBetweenBlocks, + }) => { const ticketsTypeList = getTicketsTypeList(ticketsList || ''); return { id, @@ -121,11 +114,13 @@ export const transformTableData = (transactions: Array) => ), [TIMESTAMP_BETWEEN_BLOCKS_KEY]: (
- {transactions[index + 1]?.timestamp ? ( + {timeInMinutesBetweenBlocks ? ( <> - {getDifferenceInMinutes( - Number(transactions[index + 1].timestamp) * 1000, - Number(timestamp) * 1000, + {timeInMinutesBetweenBlocks.toFixed(1)}{' '} + {translate( + timeInMinutesBetweenBlocks === 1 + ? 'pages.blocks.minute' + : 'pages.blocks.minutes', )} ) : ( @@ -157,21 +152,28 @@ const getTotalTicket = (height: number, totalTickets: number, ticketsList: strin export const getCsvData = (blocks: Array) => { return blocks .slice(0, blocks.length - 1) - .map(({ id, timestamp, transactionCount, height, ticketsList, size, totalTickets }, index) => ({ - [BLOCK_ID_KEY]: height, - [BLOCK_HASH]: id, - [TRANSACTIONS_QTY_KEY]: transactionCount, - [TOTAL_TICKETS]: getTotalTicket(height, totalTickets, ticketsList), - [BLOCK_SIZE]: formatNumber(size / 1024, { decimalsLength: 2 }), - [TIMESTAMP_BETWEEN_BLOCKS_KEY]: blocks[index + 1]?.timestamp - ? getDifferenceInMinutes( - Number(blocks[index + 1].timestamp) * 1000, - Number(timestamp) * 1000, - 'text', - ) - : `0 ${translate('pages.blocks.minutes')}`, - [TIMESTAMP_BLOCKS_KEY]: formattedDate(timestamp, { dayName: false }), - })); + .map( + ({ + id, + timestamp, + transactionCount, + height, + ticketsList, + size, + totalTickets, + timeInMinutesBetweenBlocks, + }) => ({ + [BLOCK_ID_KEY]: height, + [BLOCK_HASH]: id, + [TRANSACTIONS_QTY_KEY]: transactionCount, + [TOTAL_TICKETS]: getTotalTicket(height, totalTickets, ticketsList), + [BLOCK_SIZE]: formatNumber(size / 1024, { decimalsLength: 2 }), + [TIMESTAMP_BETWEEN_BLOCKS_KEY]: timeInMinutesBetweenBlocks + ? `${timeInMinutesBetweenBlocks.toFixed(1)} ${translate(timeInMinutesBetweenBlocks === 1 ? 'pages.blocks.minute' : 'pages.blocks.minutes')}` + : `0 ${translate('pages.blocks.minutes')}`, + [TIMESTAMP_BLOCKS_KEY]: formattedDate(timestamp, { dayName: false }), + }), + ); }; export const transformMempoolTableData = (transactions: Array) => diff --git a/src/pages/HistoricalStatistics/CirculatingSupply/index.tsx b/src/pages/HistoricalStatistics/CirculatingSupply/index.tsx index 73d76b91..a9fe315c 100644 --- a/src/pages/HistoricalStatistics/CirculatingSupply/index.tsx +++ b/src/pages/HistoricalStatistics/CirculatingSupply/index.tsx @@ -16,20 +16,20 @@ import { EChartsLineChart } from '../Chart/EChartsLineChart'; function CirculatingSupply() { const [chartData, setChartData] = useState(null); const [currentBgColor, handleBgColorChange] = useBackgroundChart(); - const [period, setPeriod] = useState(periods[1][0]); + const [period, setPeriod] = useState(periods[6][0]); const [isLoading, setLoading] = useState(false); const swrData = useCirculatingSupply(period); useEffect(() => { - let currentCache = readCacheValue(cacheList.circulatingSupply) || {}; - if (currentCache[period]) { + let currentCache = readCacheValue(cacheList?.circulatingSupply) || {}; + if (currentCache[period]?.parseData) { setChartData(currentCache[period].parseData as TLineChartData); setLoading(false); } else { setLoading(true); } - if (!swrData.isLoading && swrData.data) { - const parseData = transformStatisticsChart(swrData.data, period, ''); + if (!swrData?.isLoading && swrData?.data) { + const parseData = transformStatisticsChart(swrData?.data, period, ''); setChartData(parseData); currentCache = { ...currentCache, @@ -38,7 +38,7 @@ function CirculatingSupply() { }, }; setCacheValue( - cacheList.circulatingSupply, + cacheList?.circulatingSupply, JSON.stringify({ currentCache, lastDate: Date.now(), @@ -46,7 +46,7 @@ function CirculatingSupply() { ); setLoading(false); } - }, [period, swrData.isLoading, swrData.data]); + }, [period, swrData?.isLoading, swrData?.data]); const handlePeriodFilterChange = (value: PeriodTypes) => { setPeriod(value); diff --git a/src/pages/HistoricalStatistics/TotalSupply/index.tsx b/src/pages/HistoricalStatistics/TotalSupply/index.tsx index 9bea459c..df412db9 100644 --- a/src/pages/HistoricalStatistics/TotalSupply/index.tsx +++ b/src/pages/HistoricalStatistics/TotalSupply/index.tsx @@ -16,7 +16,7 @@ import { EChartsLineChart } from '../Chart/EChartsLineChart'; function TotalSupply() { const [chartData, setChartData] = useState(null); const [currentBgColor, handleBgColorChange] = useBackgroundChart(); - const [period, setPeriod] = useState(periods[1][0]); + const [period, setPeriod] = useState(periods[6][0]); const [isLoading, setLoading] = useState(false); const swrData = useTotalSupply(period); diff --git a/src/pages/Tickets/Tickets.helpers.tsx b/src/pages/Tickets/Tickets.helpers.tsx index 6e1433ce..51adb8ff 100644 --- a/src/pages/Tickets/Tickets.helpers.tsx +++ b/src/pages/Tickets/Tickets.helpers.tsx @@ -990,7 +990,7 @@ export const transformInferenceAPICreditPackData = (data: TicketsList[]) => {parseContractTicket.ticket_input_data_dict .credit_pack_purchase_request_confirmation_dict.requesting_end_user_pastelid ? (