Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Time in Minutes Between Blocks #238

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 39 additions & 37 deletions src/pages/Blocks/Blocks.helpers.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<IBlock>) =>
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,
Expand Down Expand Up @@ -121,11 +114,13 @@ export const transformTableData = (transactions: Array<IBlock>) =>
),
[TIMESTAMP_BETWEEN_BLOCKS_KEY]: (
<div className="inline-block">
{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',
)}
</>
) : (
Expand Down Expand Up @@ -157,21 +152,28 @@ const getTotalTicket = (height: number, totalTickets: number, ticketsList: strin
export const getCsvData = (blocks: Array<IBlock>) => {
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<IMempool>) =>
Expand Down
14 changes: 7 additions & 7 deletions src/pages/HistoricalStatistics/CirculatingSupply/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ import { EChartsLineChart } from '../Chart/EChartsLineChart';
function CirculatingSupply() {
const [chartData, setChartData] = useState<TLineChartData | null>(null);
const [currentBgColor, handleBgColorChange] = useBackgroundChart();
const [period, setPeriod] = useState<PeriodTypes>(periods[1][0]);
const [period, setPeriod] = useState<PeriodTypes>(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,
Expand All @@ -38,15 +38,15 @@ function CirculatingSupply() {
},
};
setCacheValue(
cacheList.circulatingSupply,
cacheList?.circulatingSupply,
JSON.stringify({
currentCache,
lastDate: Date.now(),
}),
);
setLoading(false);
}
}, [period, swrData.isLoading, swrData.data]);
}, [period, swrData?.isLoading, swrData?.data]);

const handlePeriodFilterChange = (value: PeriodTypes) => {
setPeriod(value);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/HistoricalStatistics/TotalSupply/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { EChartsLineChart } from '../Chart/EChartsLineChart';
function TotalSupply() {
const [chartData, setChartData] = useState<TLineChartData | null>(null);
const [currentBgColor, handleBgColorChange] = useBackgroundChart();
const [period, setPeriod] = useState<PeriodTypes>(periods[1][0]);
const [period, setPeriod] = useState<PeriodTypes>(periods[6][0]);
const [isLoading, setLoading] = useState(false);
const swrData = useTotalSupply(period);

Expand Down
2 changes: 1 addition & 1 deletion src/pages/Tickets/Tickets.helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ export const transformInferenceAPICreditPackData = (data: TicketsList[]) =>
{parseContractTicket.ticket_input_data_dict
.credit_pack_purchase_request_confirmation_dict.requesting_end_user_pastelid ? (
<RouterLink
route={`${ROUTES.TRANSACTION_DETAILS}/${parseContractTicket.ticket_input_data_dict.credit_pack_purchase_request_confirmation_dict.requesting_end_user_pastelid}`}
route={`${ROUTES.PASTEL_ID_DETAILS}/${parseContractTicket.ticket_input_data_dict.credit_pack_purchase_request_confirmation_dict.requesting_end_user_pastelid}`}
value={formatAddress(
parseContractTicket.ticket_input_data_dict
.credit_pack_purchase_request_confirmation_dict.requesting_end_user_pastelid,
Expand Down
7 changes: 6 additions & 1 deletion src/utils/helpers/statisticsLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,12 @@ export function transformStatisticsChart(
dataY.push(value);
dataX.push(new Date(trans[i].time).toLocaleString());
}
if (period === '24h' && !timestamp && checkValidateData(trans[trans.length - 1]?.time)) {
if (
period === '24h' &&
!timestamp &&
trans.length &&
checkValidateData(trans[trans.length - 1]?.time)
) {
dataX.push(new Date().toLocaleString());
dataY.push(dataY[dataY.length - 1]);
}
Expand Down
1 change: 1 addition & 0 deletions src/utils/types/IBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface IBlock {
senses: TSenseRequests[];
type?: string;
addresses?: ITransactionAddress[];
timeInMinutesBetweenBlocks?: number;
}

export interface IRawBlock {
Expand Down
Loading