mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* add prefix to API resources * fix pw tests * refactor config * remove unnecessary prefixes in resource names * fixes * update screenshots
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import BigNumber from 'bignumber.js';
|
|
import React from 'react';
|
|
|
|
import config from 'configs/app';
|
|
import useApiQuery from 'lib/api/useApiQuery';
|
|
import { currencyUnits } from 'lib/units';
|
|
import ChartWidget from 'ui/shared/chart/ChartWidget';
|
|
|
|
interface Props {
|
|
addressHash: string;
|
|
}
|
|
|
|
const AddressCoinBalanceChart = ({ addressHash }: Props) => {
|
|
const { data, isPending, isError } = useApiQuery('general:address_coin_balance_chart', {
|
|
pathParams: { hash: addressHash },
|
|
});
|
|
|
|
const items = React.useMemo(() => {
|
|
if (!data) {
|
|
return undefined;
|
|
}
|
|
|
|
return data.items.map(({ date, value }) => ({
|
|
date: new Date(date),
|
|
value: BigNumber(value).div(10 ** config.chain.currency.decimals).toNumber(),
|
|
}));
|
|
}, [ data ]);
|
|
|
|
return (
|
|
<ChartWidget
|
|
isError={ isError }
|
|
title="Balances"
|
|
items={ items }
|
|
isLoading={ isPending }
|
|
h="300px"
|
|
units={ currencyUnits.ether }
|
|
emptyText={ data?.days ? `Insufficient data for the past ${ data.days } days` : undefined }
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default React.memo(AddressCoinBalanceChart);
|