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,7 +35,8 @@ export const baseResponse: AddressCoinBalanceHistoryResponse = { ...@@ -35,7 +35,8 @@ 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', date: '2022-11-02',
value: '128238612887883515', value: '128238612887883515',
...@@ -64,4 +65,6 @@ export const chartResponse: AddressCoinBalanceHistoryChart = [ ...@@ -64,4 +65,6 @@ export const chartResponse: AddressCoinBalanceHistoryChart = [
date: '2022-11-08', date: '2022-11-08',
value: '216488112907005778', 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(() => {
if (!data) {
return undefined;
}
const dataItems = 'items' in data ? data.items : data;
return dataItems.map(({ date, value }) => ({
date: new Date(date), date: new Date(date),
value: BigNumber(value).div(10 ** config.chain.currency.decimals).toNumber(), value: BigNumber(value).div(10 ** config.chain.currency.decimals).toNumber(),
})), [ data ]); }));
}, [ 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