Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed supply #s #1887

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/app/_components/Stats/StxSupply/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use client';

import { useColorMode } from '@chakra-ui/react';
import { Infinity, Info } from '@phosphor-icons/react';
import * as React from 'react';
import { Info } from '@phosphor-icons/react';

Check warning on line 3 in src/app/_components/Stats/StxSupply/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/app/_components/Stats/StxSupply/index.tsx#L3

Added line #L3 was not covered by tests

import { useGlobalContext } from '../../../../common/context/useGlobalContext';
import { useSuspenseStxSupply } from '../../../../common/queries/useStxSupply';
Expand All @@ -12,20 +10,18 @@
import { GridProps } from '../../../../ui/Grid';
import { Icon } from '../../../../ui/Icon';
import { Tooltip } from '../../../../ui/Tooltip';
import { useStxSupply } from '../../../signers/data/useStxSupply';
import { ExplorerErrorBoundary } from '../../ErrorBoundary';
import { StatSection } from '../StatSection';

function StxSupplyBase(props: GridProps) {
const {
data: { total_stx, unlocked_stx },
data: { total_stx, unlocked_stx, total_stx_year_2050 },
} = useSuspenseStxSupply();
const { circulatingSupply } = useStxSupply();
const circulatingSupplyNumber = circulatingSupply ? Number(circulatingSupply) : 0;
const circulatingSupplyNumber = unlocked_stx ? Number(unlocked_stx) : 0;
const circulatingSupplyFormatted = numberToString(circulatingSupplyNumber);
const totalSupplyNumber = unlocked_stx ? Number(unlocked_stx) : 0;
const totalSupplyNumber = total_stx ? Number(total_stx) : 0;
const totalSupplyFormatted = numberToString(totalSupplyNumber);
const maxSupplyBy2050Number = total_stx ? Number(total_stx) : 0;
const maxSupplyBy2050Number = total_stx_year_2050 ? Number(total_stx_year_2050) : 0;
const maxSupplyBy2050Formatted = numberToString(maxSupplyBy2050Number);
const percentageUnlocked = ((circulatingSupplyNumber / totalSupplyNumber) * 100).toFixed(1);
const isMainnet = useGlobalContext().activeNetwork.mode === 'mainnet';
Expand Down
16 changes: 12 additions & 4 deletions src/common/queries/useStxSupply.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { useSuspenseQuery } from '@tanstack/react-query';

import { useApi } from '../api/useApi';
import { useGlobalContext } from '../context/useGlobalContext';

Check warning on line 3 in src/common/queries/useStxSupply.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useStxSupply.ts#L3

Added line #L3 was not covered by tests

interface StxSupplyResponse {
unlocked_percent: string;
total_stx: string;
total_stx_year_2050: string;
unlocked_stx: string;
block_height: number;
}

export const useSuspenseStxSupply = () => {
const api = useApi();
return useSuspenseQuery({
const { url: activeNetworkUrl } = useGlobalContext().activeNetwork;
return useSuspenseQuery<StxSupplyResponse>({

Check warning on line 15 in src/common/queries/useStxSupply.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useStxSupply.ts#L14-L15

Added lines #L14 - L15 were not covered by tests
queryKey: ['stx-supply'],
queryFn: () => api.infoApi.getStxSupply({}),
queryFn: () => fetch(`${activeNetworkUrl}/extended/v1/stx_supply`).then(res => res.json()),

Check warning on line 17 in src/common/queries/useStxSupply.ts

View check run for this annotation

Codecov / codecov/patch

src/common/queries/useStxSupply.ts#L17

Added line #L17 was not covered by tests
staleTime: 30 * 60 * 1000,
});
};
Loading