Skip to content

Commit

Permalink
fix: update logic of getting and display the data in price chart
Browse files Browse the repository at this point in the history
  • Loading branch information
akhlopiachyi committed May 30, 2024
1 parent 093c0a4 commit a1bad7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apps/web-coreum/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web-coreum",
"version": "2.19.3-116",
"version": "2.19.3-117",
"license": "Apache-2.0",
"private": true,
"scripts": {
Expand Down
31 changes: 16 additions & 15 deletions packages/ui/src/screens/home/components/hero/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import chainConfig from '@/chainConfig';
import { useTokenPriceHistoryQuery } from '@/graphql/types/general_types';
import type { HeroState } from '@/screens/home/components/hero/types';

const { primaryTokenUnit, tokenUnits, chainType } = chainConfig();
const { primaryTokenUnit, tokenUnits } = chainConfig();

export const useHero = () => {
const itemsToLoad = 7 * (chainType.toLowerCase() === 'testnet' ? 24 : 96); // Count of ticks for the last 7 days. This value is approximate
const itemsToLoad = 7 * 24 * 4;

const [state, setState] = useState<HeroState>({
loading: true,
Expand Down Expand Up @@ -80,20 +80,21 @@ export const useHero = () => {
}
}, [handleSetState, loadMoreData, state.dataLoading, state.isAllDataLoaded, state.loading]);

const formattedData = useMemo(
() =>
state.tokenPriceHistory
.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
.map((x) => {
const time = new Date(x.timestamp);
const formattedData = useMemo(() => {
const oneWeekAgo = Date.now() - 7 * 24 * 60 * 60 * 1000;

return {
value: x.price as number,
time: Math.floor(time.getTime() / 1000),
};
}),
[state.tokenPriceHistory]
);
return state.tokenPriceHistory
.filter((x) => new Date(x.timestamp).getTime() >= oneWeekAgo)
.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1))
.map((x) => {
const time = new Date(x.timestamp);

return {
value: x.price as number,
time: Math.floor(time.getTime() / 1000),
};
});
}, [state.tokenPriceHistory]);

return {
state,
Expand Down

0 comments on commit a1bad7b

Please sign in to comment.