Commit 2eb01a01 authored by isstuev's avatar isstuev

coin balance history chart new type and custom empty text

parent c393f753
...@@ -29,6 +29,7 @@ import type { ...@@ -29,6 +29,7 @@ import type {
AddressNFTsResponse, AddressNFTsResponse,
AddressCollectionsResponse, AddressCollectionsResponse,
AddressNFTTokensFilter, AddressNFTTokensFilter,
AddressCoinBalanceHistoryChartOld,
} from 'types/api/address'; } from 'types/api/address';
import type { AddressesResponse } from 'types/api/addresses'; import type { AddressesResponse } from 'types/api/addresses';
import type { TxBlobs, Blob } from 'types/api/blobs'; import type { TxBlobs, Blob } from 'types/api/blobs';
...@@ -859,7 +860,7 @@ Q extends 'address_internal_txs' ? AddressInternalTxsResponse : ...@@ -859,7 +860,7 @@ Q extends 'address_internal_txs' ? AddressInternalTxsResponse :
Q extends 'address_token_transfers' ? AddressTokenTransferResponse : Q extends 'address_token_transfers' ? AddressTokenTransferResponse :
Q extends 'address_blocks_validated' ? AddressBlocksValidatedResponse : Q extends 'address_blocks_validated' ? AddressBlocksValidatedResponse :
Q extends 'address_coin_balance' ? AddressCoinBalanceHistoryResponse : Q extends 'address_coin_balance' ? AddressCoinBalanceHistoryResponse :
Q extends 'address_coin_balance_chart' ? AddressCoinBalanceHistoryChart : Q extends 'address_coin_balance_chart' ? AddressCoinBalanceHistoryChartOld | AddressCoinBalanceHistoryChart :
Q extends 'address_logs' ? LogsResponseAddress : Q extends 'address_logs' ? LogsResponseAddress :
Q extends 'address_tokens' ? AddressTokensResponse : Q extends 'address_tokens' ? AddressTokensResponse :
Q extends 'address_nfts' ? AddressNFTsResponse : Q extends 'address_nfts' ? AddressNFTsResponse :
......
...@@ -35,33 +35,36 @@ export const baseResponse: AddressCoinBalanceHistoryResponse = { ...@@ -35,33 +35,36 @@ export const baseResponse: AddressCoinBalanceHistoryResponse = {
next_page_params: null, next_page_params: null,
}; };
export const chartResponse: AddressCoinBalanceHistoryChart = [ export const chartResponse: AddressCoinBalanceHistoryChart = {
{ items: [
date: '2022-11-02', {
value: '128238612887883515', date: '2022-11-02',
}, value: '128238612887883515',
{ },
date: '2022-11-03', {
value: '199807583157570922', date: '2022-11-03',
}, value: '199807583157570922',
{ },
date: '2022-11-04', {
value: '114487912907005778', date: '2022-11-04',
}, value: '114487912907005778',
{ },
date: '2022-11-05', {
value: '219533112907005778', date: '2022-11-05',
}, value: '219533112907005778',
{ },
date: '2022-11-06', {
value: '116487912907005778', date: '2022-11-06',
}, value: '116487912907005778',
{ },
date: '2022-11-07', {
value: '199807583157570922', date: '2022-11-07',
}, value: '199807583157570922',
{ },
date: '2022-11-08', {
value: '216488112907005778', date: '2022-11-08',
}, value: '216488112907005778',
]; },
],
days: 10,
};
...@@ -148,11 +148,20 @@ export interface AddressCoinBalanceHistoryResponse { ...@@ -148,11 +148,20 @@ export interface AddressCoinBalanceHistoryResponse {
} | null; } | null;
} }
export type AddressCoinBalanceHistoryChart = Array<{ // remove after api release
export type AddressCoinBalanceHistoryChartOld = Array<{
date: string; date: string;
value: string; value: string;
}> }>
export type AddressCoinBalanceHistoryChart = {
items: Array<{
date: string;
value: string;
}>;
days: number;
};
export interface AddressBlocksValidatedResponse { export interface AddressBlocksValidatedResponse {
items: Array<Block>; items: Array<Block>;
next_page_params: { next_page_params: {
......
...@@ -15,10 +15,17 @@ const AddressCoinBalanceChart = ({ addressHash }: Props) => { ...@@ -15,10 +15,17 @@ const AddressCoinBalanceChart = ({ addressHash }: Props) => {
pathParams: { hash: addressHash }, pathParams: { hash: addressHash },
}); });
const items = React.useMemo(() => data?.map(({ date, value }) => ({ const items = React.useMemo(() => {
date: new Date(date), if (!data) {
value: BigNumber(value).div(10 ** config.chain.currency.decimals).toNumber(), return undefined;
})), [ data ]); }
const dataItems = 'items' in data ? data.items : data;
return dataItems.map(({ date, value }) => ({
date: new Date(date),
value: BigNumber(value).div(10 ** config.chain.currency.decimals).toNumber(),
}));
}, [ data ]);
return ( return (
<ChartWidget <ChartWidget
...@@ -28,6 +35,7 @@ const AddressCoinBalanceChart = ({ addressHash }: Props) => { ...@@ -28,6 +35,7 @@ const AddressCoinBalanceChart = ({ addressHash }: Props) => {
isLoading={ isPending } isLoading={ isPending }
h="300px" h="300px"
units={ currencyUnits.ether } units={ currencyUnits.ether }
emptyText={ data && 'days' in data && `Insufficient data for the past ${ data.days } days` }
/> />
); );
}; };
......
...@@ -35,11 +35,12 @@ export type Props = { ...@@ -35,11 +35,12 @@ export type Props = {
isLoading: boolean; isLoading: boolean;
className?: string; className?: string;
isError: boolean; isError: boolean;
emptyText?: string;
} }
const DOWNLOAD_IMAGE_SCALE = 5; const DOWNLOAD_IMAGE_SCALE = 5;
const ChartWidget = ({ items, title, description, isLoading, className, isError, units }: Props) => { const ChartWidget = ({ items, title, description, isLoading, className, isError, units, emptyText }: Props) => {
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
const [ isFullscreen, setIsFullscreen ] = useState(false); const [ isFullscreen, setIsFullscreen ] = useState(false);
const [ isZoomResetInitial, setIsZoomResetInitial ] = React.useState(true); const [ isZoomResetInitial, setIsZoomResetInitial ] = React.useState(true);
...@@ -134,7 +135,7 @@ const ChartWidget = ({ items, title, description, isLoading, className, isError, ...@@ -134,7 +135,7 @@ const ChartWidget = ({ items, title, description, isLoading, className, isError,
if (!hasItems) { if (!hasItems) {
return ( return (
<Center flexGrow={ 1 }> <Center flexGrow={ 1 }>
<Text variant="secondary" fontSize="sm">No data</Text> <Text variant="secondary" fontSize="sm">{ emptyText || 'No data' }</Text>
</Center> </Center>
); );
} }
......
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