Commit 1130e1c2 authored by Yuri Mikhin's avatar Yuri Mikhin Committed by Yuri Mikhin

Remake counters API integration.

parent 77e0febf
...@@ -22,7 +22,7 @@ import type { InternalTransactionsResponse } from 'types/api/internalTransaction ...@@ -22,7 +22,7 @@ import type { InternalTransactionsResponse } from 'types/api/internalTransaction
import type { LogsResponseTx, LogsResponseAddress } from 'types/api/log'; import type { LogsResponseTx, LogsResponseAddress } from 'types/api/log';
import type { RawTracesResponse } from 'types/api/rawTrace'; import type { RawTracesResponse } from 'types/api/rawTrace';
import type { SearchResult, SearchResultFilters } from 'types/api/search'; import type { SearchResult, SearchResultFilters } from 'types/api/search';
import type { Stats, Charts, HomeStats } from 'types/api/stats'; import type { Counters, Charts, HomeStats } from 'types/api/stats';
import type { TokenCounters, TokenInfo, TokenHolders } from 'types/api/tokenInfo'; import type { TokenCounters, TokenInfo, TokenHolders } from 'types/api/tokenInfo';
import type { TokenTransferResponse, TokenTransferFilters } from 'types/api/tokenTransfer'; import type { TokenTransferResponse, TokenTransferFilters } from 'types/api/tokenTransfer';
import type { TransactionsResponseValidated, TransactionsResponsePending, Transaction } from 'types/api/transaction'; import type { TransactionsResponseValidated, TransactionsResponsePending, Transaction } from 'types/api/transaction';
...@@ -292,7 +292,7 @@ Q extends 'homepage_chart_market' ? ChartMarketResponse : ...@@ -292,7 +292,7 @@ Q extends 'homepage_chart_market' ? ChartMarketResponse :
Q extends 'homepage_blocks' ? Array<Block> : Q extends 'homepage_blocks' ? Array<Block> :
Q extends 'homepage_txs' ? Array<Transaction> : Q extends 'homepage_txs' ? Array<Transaction> :
Q extends 'homepage_indexing_status' ? IndexingStatus : Q extends 'homepage_indexing_status' ? IndexingStatus :
Q extends 'stats_counters' ? Stats : Q extends 'stats_counters' ? Counters :
Q extends 'stats_charts' ? Charts : Q extends 'stats_charts' ? Charts :
Q extends 'blocks' ? BlocksResponse : Q extends 'blocks' ? BlocksResponse :
Q extends 'block' ? Block : Q extends 'block' ? Block :
......
...@@ -19,21 +19,15 @@ export type GasPrices = { ...@@ -19,21 +19,15 @@ export type GasPrices = {
slow: number; slow: number;
} }
export type Stats = { export type Counters = {
counters: { counters: Array<Counter>;
totalBlocks: string; }
averageBlockTime: string;
totalTransactions: string;
completedTransactions: string;
totalAccounts: string;
totalTokens: string;
totalNativeCoinHolders: string; type Counter = {
totalNativeCoinTransfers: string; id: string;
}; value: string;
title: string;
units: string;
} }
export type Charts = { export type Charts = {
......
...@@ -4,7 +4,6 @@ import React from 'react'; ...@@ -4,7 +4,6 @@ import React from 'react';
import useApiQuery from 'lib/api/useApiQuery'; import useApiQuery from 'lib/api/useApiQuery';
import formatNumberToMetricPrefix from 'lib/formatNumberToMetricPrefix'; import formatNumberToMetricPrefix from 'lib/formatNumberToMetricPrefix';
import { numberWidgetsScheme } from './constants/number-widgets-scheme';
import NumberWidget from './NumberWidget'; import NumberWidget from './NumberWidget';
import NumberWidgetSkeleton from './NumberWidgetSkeleton'; import NumberWidgetSkeleton from './NumberWidgetSkeleton';
...@@ -22,20 +21,13 @@ const NumberWidgetsList = () => { ...@@ -22,20 +21,13 @@ const NumberWidgetsList = () => {
gridGap={ 4 } gridGap={ 4 }
> >
{ isLoading ? skeletonElement : { isLoading ? skeletonElement :
numberWidgetsScheme.map(({ id, title, formatFn }) => { data?.counters?.map(({ id, title, value, units }) => {
if (!data?.counters[id]) {
return null;
}
const value = formatNumberToMetricPrefix(Number(data.counters[id]));
return ( return (
<NumberWidget <NumberWidget
key={ id } key={ id }
label={ title } label={ title }
value={ formatFn ? value={ `${ formatNumberToMetricPrefix(Number(value)) } ${ units }` }
formatFn(value) :
value }
/> />
); );
}) } }) }
......
import type { Stats } from 'types/api/stats';
type Key = keyof Stats['counters'];
export const numberWidgetsScheme: Array<{id: Key; title: string; formatFn?: (n: string) => string}> = [
{
id: 'totalBlocks',
title: 'Total blocks',
},
{
id: 'averageBlockTime',
title: 'Average block time',
formatFn: (n) => `${ n } s`,
},
{
id: 'totalTransactions',
title: 'Total transactions',
},
{
id: 'completedTransactions',
title: 'Completed transactions',
},
{
id: 'totalAccounts',
title: 'Total accounts',
},
{
id: 'totalTokens',
title: 'Total tokens',
},
{
id: 'totalNativeCoinHolders',
title: 'Total native coin holders',
},
{
id: 'totalNativeCoinTransfers',
title: 'Total native coin transfers',
},
];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment